michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

Macro for systems: {\left\{\begin{array}{lcl}#1\end{array}\right.} #73

Closed danielezambelli closed 2 years ago

danielezambelli commented 2 years ago

Hi!

I use some macros to make systems of equations:

% 8<----------------------------------------------- \newcommand{\sistema}[1]{\left{\begin{array}{lcl}#1\end{array}\right.}

\newcommand{\fatratti}[1]{\left{\begin{array}{rclcl}#1\end{array}\right.} % 8<-----------------------------------------------

The corresponding code, in the configuration file is:

% 8<----------------------------------------------- sistema: ["\left\{\begin{array}{lcl}#1\end{array}\right\.", 1],

fatratti: ["\left\{\begin{array}{rclcl}#1\end{array}\right\.", 1], % 8<-----------------------------------------------

But when I compile I get the error that might depend on the parser of the configuration file:

% 8<----------------------------------------------- [ERROR] htlatex: Compilation errors in the htlatex run [ERROR] htlatex: Filename Line Message [ERROR] htlatex: ./sistemi.tex 14 File ended while scanning use of \c:MathJaxConfig:. [ERROR] htlatex: ./sistemi.tex 16 LaTeX Error: Missing \begin{document}. % 8<-----------------------------------------------

I report below an example file. If you comment out the calls to "system" or "fatratti" the compilation works fine.

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

\RequirePackage{amsmath, amssymb, amsthm}% amsfonts è caricato da amssymb

\newcommand{\sistema}[1]{\left{\begin{array}{lcl}#1\end{array}\right.}

\newcommand{\fatratti}[1]{\left{\begin{array}{rclcl}#1\end{array}\right.}

\begin{document}

This .tex run correctly if compiled with dflatex or make4ht with ``mathml'' with:

\verb|make4ht sistemi.tex -l -u -s -d dist "mathml"|

[\sistema{A=0 \B=0}]

[f(x)=\fatratti{+1 & \text{ se } & x < 0\ 0 & \text{ se } & x = 0\ -1 & \text{ se } & x > 0\}]

If I compile with:\ \verb|make4ht sistemi.tex -c md_make4ht -l -u -s -d dist "mathjax"|\ I obtain this error:

\begin{verbatim} [ERROR] htlatex: Compilation errors in the htlatex run [ERROR] htlatex: Filename Line Message [ERROR] htlatex: ./sistemi.tex 14 File ended while scanning use of \c:MathJaxConfig:. [ERROR] htlatex: ./sistemi.tex 16 LaTeX Error: Missing \begin{document}. \end{verbatim}

In the config file I have the following line:

\begin{verbatim} sistema: ["\left\{\begin{array}{lcl}#1\end{array}\right\.", 1], \end{verbatim}

Bat also with this line:

\begin{verbatim} sistema: ["\left\{#1\right\.", 1], \end{verbatim}

I get the same error

make4ht works correctly if I replace the macros with their content:

[ \left{\begin{array}{lcl}A=0 \B=0\end{array}\right. ]

[ f(x)=\left{\begin{array}{rclcl} +1 & \text{ se } & x < 0\ 0 & \text{ se } & x = 0\ -1 & \text{ se } & x > 0\ \end{array}\right. ]

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

Thanks for your attention.

michal-h21 commented 2 years ago

This one is a bit harder. What I found is that the left braces opened by \\left\\{ need to be matched by closing bracket in the config file. The issue is that the closing bracket will be included in the JS code, which will force MathJax to fail to interpret it. So I found another trick, to use JavaScript comments to comment these extra brackets. As you have two opening brackets, you need to include two closing brackets:

\Preamble{xhtml} 
\catcode`\#=11 
\Configure{MathJaxConfig}{{
    tex: { 
      tags: "ams", 
      macros: { 
        uline: ["\\underline{#1}",1],
        uuline: ["\\underline{\\underline{#1}}",1],
        uwave: ["\\mathit{#1}",1],
        dashuline: ["\\mathit{#1}",1],
        dotuline: ["\\mathit{#1}",1],
        sistema: ["\\left\\{\\begin{array}{lcl}#1\\end{array}\\right.", 1],
        fatratti: ["\\left\\{\\begin{array}{rclcl}#1\\end{array}\\right.", 1],
      } 
  } 
} 
//}}}
\catcode`\#=6 
\begin{document}
\EndPreamble

See the line before \catcode. It uses //}}} - the third bracket closes the configuration and it will be not included in the HTML code.

danielezambelli commented 2 years ago

It works fine, thank you!

What does the "//" mean? Is it a comment?

Thanks!

michal-h21 commented 2 years ago

That's good to hear! // is a comment in JavaScript. It hides the closing brackets for the browser, but LaTeX still sees them, so it can correctly close the configuration.