michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

package ulem #72

Closed danielezambelli closed 2 years ago

danielezambelli commented 2 years ago

The package ulem does not seem to be supported by make4ht.

In text mode it produces incorrect results.

In math mode it does not recognize macros.

Is it possible to support it or is it better to use another package for underlining?

Miniexamle:

%--8<------------------------------------- \documentclass[10pt,a4paper]{memoir} \usepackage[T1]{fontenc} \usepackage{textcomp}
\usepackage[utf8]{inputenc} \usepackage[italian]{babel}

\RequirePackage{amsmath, amssymb, amsthm}% amsfonts è caricato da amssymb \RequirePackage[e]{esvect} % per i vettori \RequirePackage{physics} % fisica e differenziale (dd) \RequirePackage{cancel} % per le semplificazioni \RequirePackage[normalem]{ulem} % sottolineature \usepackage{lipsum}

\begin{document}

The commands of the package \verb|ulem| are misinterpreted in text mode while are not recognized in math mode.

Text mode: \begin{itemize} \item underline with \verb|\uline|: \uline{under-line} \item duble underline with \verb|\uuline|: \uuline{dubleunder-line} \item dashed underline with \verb|\dashuline|: \dashuline{dashedunder-line} \item doted underline with \verb|\dotuline|: \dotuline{dotedunder-line} \item wavey underline with \verb|\uwave|: \uwave{under-wave} \item cancel with \verb|\sout|: \sout{cancel-line} \item xcancel with \verb|\xout|: \xout{xcancel-line} \end{itemize}

Math mode: [\uline{5a^3}\uuline{-4ab}+1\uwave{+2a^3} \dashuline{+2ab}-a\dotuline{-3a^3}]

The errors occur with both:\ mathml, \ compiled with: \verb|make4ht ulem.tex -l -u -s -d dist "mathml"|\ and mathjax, \ compiled with: \verb|make4ht ulem.tex -c md_make4ht -l -u -s -d dist "mathjax"|. \end{document} %--8<-------------------------------------

Thanks

Daniele

michal-h21 commented 2 years ago

Thanks for the report. I've fixed support for Ulem commands in TeX4ht sources. They work well in the text mode, but math mode is a bit harder due to browser limitations. I will show it later.

For now, try this version of ulem.4ht:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ulem.4ht                            2022-04-26-16:54 %
% Copyright (C) 2001-2009       Eitan M. Gurari         %
% Copyright 2009-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.

\def\:ulemchoose#1#2{\relax\ifmmode\csname a:#1-math\endcsname#2\csname b:#1-math\endcsname\else\csname a:#1\endcsname#2\csname b:#1\endcsname\fi}

\NewConfigure{uline}{2}
\NewConfigure{uline-math}{2}
\def\:tempa#1{\:ulemchoose{uline}{#1}}
\HLet\uline\:tempa

\NewConfigure{uuline}{2}
\NewConfigure{uuline-math}{2}
\def\:tempa#1{\:ulemchoose{uuline}{#1}}
\HLet\uuline\:tempa

\NewConfigure{sout}{2}
\NewConfigure{sout-math}{2}
\def\:tempa#1{\:ulemchoose{sout}{#1}}
\HLet\sout\:tempa

\NewConfigure{xout}{2}
\NewConfigure{xout-math}{2}
\def\:tempa#1{\:ulemchoose{xout}{#1}}
\HLet\xout\:tempa

\NewConfigure{uwave}{2}
\NewConfigure{uwave-math}{2}
\def\:tempa#1{\:ulemchoose{uwave}{#1}}
\HLet\uwave\:tempa

\NewConfigure{dashuline}{2}
\NewConfigure{dashuline-math}{2}
\def\:tempa#1{\:ulemchoose{dashuline}{#1}}
\HLet\dashuline\:tempa

\NewConfigure{dotuline}{2}
\NewConfigure{dotuline-math}{2}
\def\:tempa#1{\:ulemchoose{dotuline}{#1}}
\HLet\dotuline\:tempa

\def\:temp{\z@}
\HLet\ULthickness\:temp

\Hinput{ulem}
\endinput

It works reasonably well with the following config file:

\Preamble{xhtml}
\Configure{uline}
   {\HCode{<span class="uline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{uline-math}
   {\HCode{<span class="uline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{.uline,.uline-math{ text-decoration:underline; }}
\Configure{uuline}
   {\HCode{<span class="uuline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{uuline-math}
   {\HCode{<span class="uuline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{.uuline,.uuline-math{ text-decoration:underline double; }}
\Configure{sout}
   {\HCode{<span class="sout">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{sout-math}
   {\HCode{<span class="sout">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{span.sout, .sout-math {text-decoration: line-through }}
\Configure{xout}
   {\HCode{<span class="xout">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Configure{xout-math}
   {\HCode{<span class="xout-math">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Css{span.xout, .xout-math {text-decoration: line-through underline }}
\Configure{uwave}
   {\HCode{<span class="uwave">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Configure{uwave-math}
   {\HCode{<span class="uwave-math">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Css{span.uwave, .uwave-math {text-decoration:underline wavy; }}
\Configure{dashuline}
   {\HCode{<span class="dashuline">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Configure{dashuline-math}
   {\HCode{<span class="dashuline-math">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Css{span.dashuline, .dashuline-math {text-decoration:underline dashed;}}
\Configure{dotuline}
   {\HCode{<span class="dotuline">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Configure{dotuline-math}
   {\HCode{<span class="dotuline-math">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Css{span.dotuline, .dotuline-math {text-decoration:underline dotted;}}
\begin{document}
\EndPreamble

Now the issue with math. The above config file works well for the default math, meaning pictures for display math, and simple HTML elements for inline math.

I've made a similar configuration for MathML, but it seems that at least in Firefox, the text-decoration CSS property isn't supported. I've only found that I can utilize the <menclose> element for underlines and strike outs, but it doesn't work for dashed or dotted lines, where I need to use <mstyle>. Waved lines are not supported at all. With that, I can somehow achieve the desired functionality, but it doesn't look great. Try this:

\Preamble{xhtml}
\Configure{uline}
   {\HCode{<span class="uline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{.uline,.uline-math{ text-decoration:underline; }}
\Configure{uuline}
   {\HCode{<span class="uuline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{.uuline,.uuline-math{ text-decoration:underline double; }}
\Configure{sout}
   {\HCode{<span class="sout">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{span.sout, .sout-math {text-decoration: line-through }}
\Configure{xout}
   {\HCode{<span class="xout">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Css{span.xout, .xout-math {text-decoration: line-through underline }}
\Configure{uwave}
   {\HCode{<span class="uwave">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Css{span.uwave, .uwave-math {text-decoration:underline wavy; }}
\Configure{dashuline}
   {\HCode{<span class="dashuline">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Css{span.dashuline, .dashuline-math {text-decoration:underline dashed;}}
\Configure{dotuline}
   {\HCode{<span class="dotuline">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
\Css{span.dotuline, .dotuline-math {text-decoration:underline dotted;}}
\Configure{uline-math}
   {\HCode{<menclose class="uline-math" notation="bottom">}\NoFonts} {\EndNoFonts\HCode{</menclose>}}
\Css{.uline-math{border-bottom: 1px solid black;}}
\Configure{uuline-math}
   {\HCode{<menclose class="uuline-math" notation="bottom">}\NoFonts} {\EndNoFonts\HCode{</menclose>}}
\Css{.uuline-math{ border-bottom:3px double black; }}
\Configure{sout-math}
   {\HCode{<menclose class="sout-math" notation="horizontalstrike">}\NoFonts} {\EndNoFonts\HCode{</menclose>}}
\Css{.sout-math {text-decoration: line-through }}
\Configure{xout-math}
   {\HCode{<menclose class="xout-math" notation="horizontalstrike bottom">}\NoFonts} 
   {\EndNoFonts\HCode{</menclose>}}
%\Css{.xout-math {border-bottom: 1px solid black;}}
\Configure{uwave-math}
   {\HCode{<menclose class="uwave-math" notation="bottom">}\NoFonts} 
   {\EndNoFonts\HCode{</menclose>}}
\Css{.uwave-math {border-bottom: 1px solid black;}}
\Configure{dashuline-math}
   {\HCode{<mstyle class="dashuline-math" notation="bottom">}\NoFonts} 
   {\EndNoFonts\HCode{</mstyle>}}
\Css{.dashuline-math {border-bottom: 1px dashed black;}}
\Configure{dotuline-math}
   {\HCode{<mstyle class="dotuline-math" notation="bottom">}\NoFonts} 
   {\EndNoFonts\HCode{</mstyle>}}
\Css{.dotuline-math {border-bottom: 1px dotted black;}}

\begin{document}
\EndPreamble

Regarding MathJax, I've found that you can support underlines and strikeouts thanks to the enclose extension.

\Preamble{xhtml}
\Configure{uline}
   {\HCode{<span class="uline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{uline-math}
   {\HCode{<span class="uline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{.uline,.uline-math{ text-decoration:underline; }}
\Configure{uuline}
   {\HCode{<span class="uuline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{uuline-math}
   {\HCode{<span class="uuline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{.uuline,.uuline-math{ text-decoration:underline double; }}
\Configure{sout}
   {\HCode{<span class="sout">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{sout-math}
   {\HCode{<span class="sout">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{span.sout, .sout-math {text-decoration: line-through }}
\Configure{xout}
   {\HCode{<span class="xout">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Configurations for MathJax %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\catcode`\#=11 
\Configure{MathJaxConfig}{{ 
    tex: { 
      packages: {'[+]': ['html','enclose']},
      \detokenize{% 
      macros: { 
        % our sample macro takes a parameter 
        uline: ["\\enclose{bottom}{#1}",1], 
        uuline: ["\\enclose{bottom}{\\enclose{bottom}{#1}}",1], 
        uwave: ["\\enclose{bottom}{#1}",1], 
        sout: ["\\enclose{horizontalstrike}{#1}",1], 
        xout: ["\\enclose{bottom}{\\enclose{horizontalstrike}{#1}}",1], 
        dashuline: ["\\enclose{bottom}{#1}",1], 
        dotuline: ["\\enclose{bottom}{#1}",1], 
      } 
  } 
} 
}} 
\catcode`\#=6 
\begin{document}
\EndPreamble

You can also use inline CSS to support dashed or dotted lines:

\Preamble{xhtml}
\Configure{uline}
   {\HCode{<span class="uline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{uline-math}
   {\HCode{<span class="uline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{.uline,.uline-math{ text-decoration:underline; }}
\Configure{uuline}
   {\HCode{<span class="uuline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{uuline-math}
   {\HCode{<span class="uuline">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{.uuline,.uuline-math{ text-decoration:underline double; }}
\Configure{sout}
   {\HCode{<span class="sout">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Configure{sout-math}
   {\HCode{<span class="sout">}\NoFonts} {\EndNoFonts\HCode{</span>}}
\Css{span.sout, .sout-math {text-decoration: line-through }}
\Configure{xout}
   {\HCode{<span class="xout">}\NoFonts} 
   {\EndNoFonts\HCode{</span>}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Configurations for MathJax %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\catcode`\#=11 
\Configure{MathJaxConfig}{{ 
    tex: { 
      packages: {'[+]': ['html','enclose']},
      \detokenize{% 
      macros: { 
        % our sample macro takes a parameter 
        uline: ["\\enclose{bottom}{#1}",1], 
        uuline: ["\\enclose{bottom}{\\enclose{bottom}{#1}}",1], 
        uwave: ["\\enclose{bottom}{#1}",1], 
        sout: ["\\enclose{horizontalstrike}{#1}",1], 
        xout: ["\\enclose{bottom}{\\enclose{horizontalstrike}{#1}}",1], 
        dashuline: ["\\style{border-bottom:1px dashed black;}{#1}",1], 
        dotuline: ["\\style{border-bottom:1px dotted black;}{#1}",1], 
      } 
  } 
} 
}} 
\catcode`\#=6 
\begin{document}
\EndPreamble
danielezambelli commented 2 years ago

Thanks for your work.

Is it possible to have a single configuration file that works for both mathjax and mathml with:

make4ht ulem.tex -c m4htulem -l -u -s -d dist "mathml" make4ht ulem.tex -c m4htulem -l -u -s -d dist "mathjax"

I tried the following which works pretty well for mathjax (wave is rendered with a straight line), but gives an error for mathml:

%--8<------------------------------------- make4ht ulem.tex -c m4htulem -l -u -s -d dist "mathml" [STATUS] make4ht: Conversion started [STATUS] make4ht: Input file: ulem.tex [WARNING] tocid: char-def module not found [WARNING] tocid: cannot fix section id's [ERROR] htlatex: Compilation errors in the htlatex run [ERROR] htlatex: Filename Line Message [ERROR] htlatex: ./m4htulem.cf 52 LaTeX Error: Missing \begin{document} in `m4htulem.cfg'. %--8<-------------------------------------

and produces a result where dirty from the configuration file itself.

I tried with the following configuration file:

%--8<------------------------------------- \Preamble{xhtml} \Configure{uline} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{uline-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{.uline,.uline-math{ text-decoration:underline; }} \Configure{uuline} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{uuline-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{.uuline,.uuline-math{ text-decoration:underline double; }} \Configure{sout} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{sout-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.sout, .sout-math {text-decoration: line-through }} \Configure{xout} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{xout-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.xout, .xout-math {text-decoration: line-through underline }} \Configure{uwave} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{uwave-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.uwave, .uwave-math {text-decoration:underline wavy; }} \Configure{dashuline} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{dashuline-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.dashuline, .dashuline-math {text-decoration:underline dashed;}} \Configure{dotuline} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{dotuline-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.dotuline, .dotuline-math {text-decoration:underline dotted;}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Configurations for MathJax % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\catcode\#=11 \Configure{MathJaxConfig}{{ tex: { packages: {'[+]': ['html','enclose']}, \detokenize{% macros: { % our sample macro takes a parameter uline: ["\\enclose{bottom}{#1}",1], uuline: ["\\enclose{bottom}{\\enclose{bottom}{#1}}",1], uwave: ["\\enclose{bottom}{#1}",1], sout: ["\\enclose{horizontalstrike}{#1}",1], xout: ["\\enclose{bottom}{\\enclose{horizontalstrike}{#1}}",1], dashuline: ["\\style{border-bottom:1px dashed black;}{#1}",1], dotuline: ["\\style{border-bottom:1px dotted black;}{#1}",1], } } } }} \catcode#=6 \begin{document} \EndPreamble %--8<-------------------------------------

michal-h21 commented 2 years ago

The \Configure{MathJaxConfig} is defined only in the plain MathJax mode, not with MathML. When it is not defined, you will get an error, because the argument to the configuration will be printed to the document.

You can test for it's existence using:

 \ifcsname a:MathJaxConfig\endcsname
    code for Mathjax
\else
    code for MathML
\fi
danielezambelli commented 2 years ago

The following configuration file seems to work fine to me.

Thanks.

%--8<-------------------------------------

\Preamble{xhtml}

\Configure{uline} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{uline-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{.uline,.uline-math{ text-decoration:underline; }} \Configure{uuline} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{uuline-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{.uuline,.uuline-math{ text-decoration:underline double; }} \Configure{sout} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{sout-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.sout, .sout-math {text-decoration: line-through }} \Configure{xout} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{xout-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.xout, .xout-math {text-decoration: line-through underline }} \Configure{uwave} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{uwave-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.uwave, .uwave-math {text-decoration:underline wavy; }} \Configure{dashuline} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{dashuline-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.dashuline, .dashuline-math {text-decoration:underline dashed;}} \Configure{dotuline} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Configure{dotuline-math} {\HCode{}\NoFonts} {\EndNoFonts\HCode{}} \Css{span.dotuline, .dotuline-math {text-decoration:underline dotted;}}

\ifcsname a:MathJaxConfig\endcsname

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Configurations for MathJax % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\catcode\#=11 \Configure{MathJaxConfig}{{ tex: { packages: {'[+]': ['html','enclose']}, \detokenize{% macros: { % our sample macro takes a parameter uline: ["\\enclose{bottom}{#1}",1], uuline: ["\\enclose{bottom}{\\enclose{bottom}{#1}}",1], % uwave: ["#1",1], % uwave: ["\\enclose{bottom}{#1}",1], uwave: ["\\style{border-bottom:1px underline wavy black;}{#1}",1], sout: ["\\enclose{horizontalstrike}{#1}",1], xout: ["\\enclose{bottom}{\\enclose{horizontalstrike}{#1}}",1], dashuline: ["\\style{border-bottom:1px dashed black;}{#1}",1], dotuline: ["\\style{border-bottom:1px dotted black;}{#1}",1], } } } }} \catcode#=6

\else

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % code for MathML % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\fi

\begin{document} \EndPreamble

%--8<-------------------------------------

michal-h21 commented 2 years ago

I am glad it works for you now. I hope I can close this now.