michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

tcolorbox references and aspect #75

Closed danielezambelli closed 2 years ago

danielezambelli commented 2 years ago

Hi Michal,

There are some errors in the references with tcolorboxes.

And also the boxes are not drawn in the same way, but this is a secondary problem.

In the working file, mk4ht reports me errors related to the .aux file errors that are not raised in the minimal example.

I send you a minimal example:

%--8<------------------------------------------------------- \documentclass[10pt,a4paper]{memoir} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[italian]{babel} \usepackage{amsmath, amssymb, amsthm} \usepackage{ulem} \RequirePackage[colorlinks, hyperindex, pagebackref, linkcolor=blue, filecolor=blue, citecolor = black, urlcolor=blue]{hyperref}

\usepackage{tcolorbox} \tcbuselibrary{most} \usepackage{lipsum}

\theoremstyle{plain}

\newcommand{\coloross}{violet}

\tcbset{ ossstyle/.style={fonttitle=\bfseries\upshape, fontupper=\slshape, arc=0mm, colback=\coloross!5!white, colframe=\coloross!50!black, theorem style=plain, coltitle=\coloross!30!black} }

\newtcbtheorem[number within=chapter]{osservazione}{Osservazione} {ossstyle}{oss}

\begin{document}

\chapter{Problem with tcolorbox references}

\paragraph{Osservazioni} Due ambienti per le osservazioni.

\begin{osservazione}{Osservazione interessante}{osser} Questo è il contenuto di una osservazione interessante. \end{osservazione}

There may be a reference to the observation in the text: \ observation number: \ref{oss:osser};\ title of the observation: \nameref{oss:osser};\ observation page: \pageref{oss:osser}.

\lipsum[1-3]

\begin{osservazione}{Osservazione molto interessante}{primaoss} Questo è il contenuto di una osservazione. \end{osservazione}

There may be a reference to the observation in the text: \ observation number: \ref{oss:primaoss};\ title of the observation: \nameref{oss:primaoss};\ observation page: \pageref{oss:primaoss}.

\end{document} %--8<-------------------------------------------------------

Thank you for your attention.

Daniele

michal-h21 commented 2 years ago

You can try this version of tcolorbox.4ht:


% tcolorbox.4ht (2022-05-04-14:11), generated from tex4ht-4ht.tex
% Copyright 2020-2022 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2022-05-04-14:11}

% use custom counter that increments for every \tcolorbox
\newcounter{:tcbcolcount}

\def\:tempa{%
  \stepcounter{:tcbcolcount}%
  % save text and background colors for use in CSS
  \get:xcolorcss{tcbcolbacktitle}\:tcbcolbacktitle%
  \get:xcolorcss{tcbcoltitle}\:tcbcoltitle%
  \get:xcolorcss{tcbcolback}\:tcbcolback%
  \get:xcolorcss{tcbcolframe}\:tcbcolframe%
  \get:xcolorcss{tcbcolupper}\:tcbcolupper%
  % make unique ID for this box
  \def\:tcbcolid{tcolobox-\arabic{:tcbcolcount}}
  % Open box
  \a:tcolorbox%
  % set label if it exists
  \ifdefined\tcolorbox:label:key%
    \let\@currentlabel\tcolorbox:currentlabel% at this moment, \@currentlabel has wrong value
    \o:tcb@set@label:{\tcolorbox:label:key}%
    \AnchorLabel% save cross-ref destination
    \global\let\tcolorbox:label:key\undefined%
  \fi%
  % open title
  \b:tcolorbox%
  \kvtcb@before@title\kvtcb@title\kvtcb@after@title%
  % close title and open main box
  \c:tcolorbox%
  \box\tcb@upperbox%
  % deal with lower box, if it is set
  \iftcb@hasLower%
    \a:tcolorlowerbox%
    \box\tcb@lowerbox%
    \b:tcolorlowerbox%
  \fi%
  % We need to close box in \tcb@endboxanddraw
}

\HLet\tcb@drawcolorbox\:tempa
% overwrite other versions of box drawing macros
\HLet\tcb@drawcolorbox@standalone\:tempa

% we need to close tcolorbox environment here,
% in the box. otherwise, last paragraph end
% would be ignored and we would get invalid XML
\def\:tempb{\d:tcolorbox\o:tcb@endboxanddraw:}
\HLet\tcb@endboxanddraw\:tempb

% this code prevents emptying of the box title when
% some Tcolorbox options are used
\def\:tempb{}
\HLet\tcb@detach@title@code\:tempb

% require end of paragraph before Tcolorbox
\long\def\:tempb[#1]{\EndP\o:tcb@@icolorbox:[#1]}
\HLet\tcb@@icolorbox\:tempb

\NewConfigure{tcolorbox}{4}
\NewConfigure{tcolorlowerbox}{2}

% we need to save current label for a later use
\def\:tempa#1{%
  \xdef\tcolorbox:label:key{#1}%
  \global\let\tcolorbox:currentlabel\@currentlabel%
}
\HLet\tcb@set@label\:tempa

\pend:def\tcb@minipage{\SaveEndP}
\pend:def\tcb@minipage@top{\SaveEndP}
\pend:def\tcb@minipage@bottom{\SaveEndP}
\pend:def\tcb@minipage@center{\SaveEndP}

\Hinput{tcolorbox}
\endinput

Note that there is still a problem, as the title shouldn't be colored. I cannot find source of this issue.

danielezambelli commented 2 years ago

Dear Michal,

With this new version of the driver, the reference to the number works, but not the reference to the name (the page reference, of course, is not meaningful).

Complicating the example a bit (see below) I get strange errors:

[ERROR] htlatex: Compilation errors in the htlatex run [ERROR] htlatex: Filename Line Message [ERROR] htlatex: ./tcolorboxref.tex 50 Undefined control sequence. [ERROR] htlatex: ./tcolorboxref.tex 51 Package inputenc Error: inputenc is not designed for xetex or luatex.

Strange because

New example:

%--8<------------------------------------------------------- \documentclass[ 10pt,a4paper]{memoir} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[italian]{babel} \usepackage{amsmath, amssymb, amsthm} \usepackage{ulem} \RequirePackage[colorlinks, hyperindex, pagebackref, linkcolor=blue, filecolor=blue, citecolor = black, urlcolor=blue]{hyperref}

\usepackage{tcolorbox} \tcbuselibrary{most} \usepackage{lipsum}

\theoremstyle{plain}

\newcommand{\coloross}{violet} \newcommand{\colortcblist}{green}

\DeclareTCBListing{latexlistingbox}{ s O{} m }{% colback = \colortcblist!5!white, colframe = \colortcblist!75!black, fonttitle = \bfseries, IfBooleanTF = {#1}{}{listing side text}, title={#3},#2}

\tcbset{ ossstyle/.style={fonttitle=\bfseries\upshape, fontupper=\slshape, arc=0mm, colback=\coloross!5!white, colframe=\coloross!50!black, theorem style=plain, coltitle=\coloross!30!black} }

\newtcbtheorem[number within=chapter]{osservazione}{Osservazione} {ossstyle}{oss}

\begin{document}

\chapter{Problem with tcolorbox references}

\paragraph{Osservazioni} Due ambienti per le osservazioni.

\begin{osservazione}{Osservazione interessante}{primaoss} Questo è il contenuto di una osservazione interessante. \end{osservazione}

There may be a reference to the observation in the text: \ observation number: \ref{oss:primaoss};\ title of the observation: \nameref{oss:primaoss};\ observation page: \pageref{oss:primaoss}.

\lipsum[1-3]

\begin{osservazione}{Osservazione molto interessante}{secondaoss} Questo è il contenuto di una osservazione. \end{osservazione}

There may be a reference to the observation in the text: \ observation number: \ref{oss:secondaoss};\ title of the observation: \nameref{oss:secondaoss};\ observation page: \pageref{oss:secondaoss}.

\lipsum[4-5]

\begin{latexlistingbox}*{Osservazione} \begin{osservazione}{Osservazione molto molto interessante}{terzaoss} Questo è il contenuto di una osservazione. \end{osservazione}

There may be a reference to the observation in the text: \ observation number: \ref{oss:terzaoss};\ title of the observation: \nameref{oss:terzaoss};\ observation page: \pageref{oss:terzaoss}. \end{latexlistingbox}

\end{document} %--8<-------------------------------------------------------

michal-h21 commented 2 years ago

Regarding \nameref support, this version of tcolorbox.4ht should fix it:

% tcolorbox.4ht (2022-05-05-15:22), generated from tex4ht-4ht.tex
% Copyright 2020-2022 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2022-05-05-15:22}

% use custom counter that increments for every \tcolorbox
\newcounter{:tcbcolcount}

\def\:tempa{%
  \stepcounter{:tcbcolcount}%
  % save text and background colors for use in CSS
  \get:xcolorcss{tcbcolbacktitle}\:tcbcolbacktitle%
  \get:xcolorcss{tcbcoltitle}\:tcbcoltitle%
  \get:xcolorcss{tcbcolback}\:tcbcolback%
  \get:xcolorcss{tcbcolframe}\:tcbcolframe%
  \get:xcolorcss{tcbcolupper}\:tcbcolupper%
  % make unique ID for this box
  \def\:tcbcolid{tcolobox-\arabic{:tcbcolcount}}
  % Open box
  \a:tcolorbox%
  % set label if it exists
  \ifdefined\tcolorbox:label:key%
    \let\@currentlabel\tcolorbox:currentlabel% at this moment, \@currentlabel has wrong value
    \o:tcb@set@label:{\tcolorbox:label:key}%
    \AnchorLabel% save cross-ref destination
    \global\let\tcolorbox:label:key\undefined%
  \fi%
  % open title
  \b:tcolorbox%
  \kvtcb@before@title\kvtcb@title\kvtcb@after@title%
  % close title and open main box
  \c:tcolorbox%
  \box\tcb@upperbox%
  % deal with lower box, if it is set
  \iftcb@hasLower%
    \a:tcolorlowerbox%
    \box\tcb@lowerbox%
    \b:tcolorlowerbox%
  \fi%
  % We need to close box in \tcb@endboxanddraw
}

\HLet\tcb@drawcolorbox\:tempa
% overwrite other versions of box drawing macros
\HLet\tcb@drawcolorbox@standalone\:tempa

% we need to close tcolorbox environment here,
% in the box. otherwise, last paragraph end
% would be ignored and we would get invalid XML
\def\:tempb{\d:tcolorbox\o:tcb@endboxanddraw:}
\HLet\tcb@endboxanddraw\:tempb

% this code prevents emptying of the box title when
% some Tcolorbox options are used
\def\:tempb{}
\HLet\tcb@detach@title@code\:tempb

% require end of paragraph before Tcolorbox
\long\def\:tempb[#1]{\EndP\o:tcb@@icolorbox:[#1]}
\HLet\tcb@@icolorbox\:tempb

\NewConfigure{tcolorbox}{4}
\NewConfigure{tcolorlowerbox}{2}

% we need to save current label for a later use
\def\:tempa#1{%
  \xdef\tcolorbox:label:key{#1}%
  \global\let\tcolorbox:currentlabel\@currentlabel%
}
\HLet\tcb@set@label\:tempa

\pend:def\tcb@minipage{\SaveEndP}
\pend:def\tcb@minipage@top{\SaveEndP}
\pend:def\tcb@minipage@bottom{\SaveEndP}
\pend:def\tcb@minipage@center{\SaveEndP}

\AfterEndPreamble{%
  % fix \nameref support
  \def\:tempa#1{%
    \gdef\NR:Title{\a:newlabel{#1}}%
    \o:tcb@gettitle:{#1}%
  }%
  \HLet\tcb@gettitle\:tempa
}

\Hinput{tcolorbox}
\endinput

The compilation error seems to be caused by the fact that you use the inputenc package, but compile your document with -l or -x option. Try to compile it without these options, or remove inputenc.

michal-h21 commented 2 years ago

I've found that you get the same error even when you compile your file using lualatex, so it seems more like a bug in Listings, which expects \inputencodingname to exists.

danielezambelli commented 2 years ago

Yes, if I compile without "-l", make4ht works fine.

I try to investigate the source of the error with LuaLaTeX.

Thank you.

danielezambelli commented 2 years ago

Changing the first few lines of the source like this:

%--8<------------------------------------------------------- % !TEX encoding = UTF-8 Unicode \documentclass[10pt,a4paper]{memoir} \usepackage[T1]{fontenc} % \usepackage[utf8]{inputenc} It doesn't work with LuaLaTeX !!! %--8<-------------------------------------------------------

the LuaLaTeX error is avoided and the compilation works fine.

Thanks!

michal-h21 commented 2 years ago

I am glad it works now. I think that the Inputenc package shouldn't be necessary in recent LaTeX, as it expects UTF8 encoding even with PDFLaTeX.