michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

make4ht not expand function on math mode #50

Closed danielezambelli closed 2 years ago

danielezambelli commented 2 years ago

make4ht don't compile correctly this .tex file (make4ht testmathbb.tex -l -u -s -d dist "mathjax"):

\documentclass[a4paper,10pt]{memoir} \usepackage[utf8]{inputenc} \usepackage{amsfonts, amssymb}

%--------------------------------- % Functions definition \newcommand{\N}{\ensuremath{\mathbb{N}}} \newcommand{\Z}{\mathbb{Z}} \newcommand{\round}[1]{\left( #1 \right)} \newcommand{\square}[1]{\left[ #1 \right]} \newcommand{\intervac}[2]{\left]#1;~#2\right]}

\begin{document}

\section{Without functions} Numerics sets:

(\mathbb{N}); (\mathbb{Z}); \dots

Expressions: [4x^2 +3x +2 = \left[\left(4x+3\right) \cdot x +2 \right]] Subset: [2 < x \leqslant 5 \Rightarrow \left]2;~5\right]]

\section{With functions} Numerics sets:

(\N); (\Z); \dots

Expressions: [4x^2 +3x +2 = \square{\round{4x+3} \cdot x +2}] Subsets: [2 < x \leqslant 5 \Rightarrow \intervac{2}{5}]

\end{document}

michal-h21 commented 2 years ago

I ran into an error, because your code was missing all math environments. This version compiles:

% https://github.com/michal-h21/make4ht/issues/50
\documentclass[a4paper,10pt]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts, amssymb}

%---------------------------------
% Functions definition
\newcommand{\N}{\ensuremath{\mathbb{N}}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\round}[1]{\left( #1 \right)}
\renewcommand{\square}[1]{\left[ #1 \right]}
\newcommand{\intervac}[2]{\left]#1;~#2\right]}

\begin{document}

\section{Without functions}
Numerics sets:

\(\mathbb{N}\); \(\mathbb{Z}\); \dots

Expressions:
\[4x^2 +3x +2 = \left[\left(4x+3\right) \cdot x +2 \right]\]
Subset:
\[2 < x \leqslant 5 \Rightarrow \left]2;~5\right]\]

\section{With functions}
Numerics sets:

\(\N\); \(\Z\); \dots

Expressions:
\[4x^2 +3x +2 = \square{\round{4x+3} \cdot x +2}\]
Subsets:
\[2 < x \leqslant 5 \Rightarrow \intervac{2}{5}\]

\end{document}

Custom macros don't work out of the box, you must pass their definition to MathJax. You can use the MathJaxConfig configuration for that. The following configuration file works:

\Preamble{xhtml} 
\catcode`\#=11 
\Configure{MathJaxConfig}{{ 
    tex: { 
      tags: "ams", 
      \detokenize{% 
      macros: { 
        N: "\\mathbb{N}", 
        Z: "\\mathbb{Z}", 
        round: ["\\left(#1\\right)", 1],
        square: ["\\left[#1\\right]", 1],
        intervac: ["\\left]#1;~#2\\right]", 2],
      } 
  } 
} 
}} 
\catcode`\#=6 
\begin{document} 
\EndPreamble
danielezambelli commented 2 years ago

Thanks, it works well for me.

I'm having difficulty finding documentation on the format and commands available for the configuration file, where could I find it?

Daniele.

michal-h21 commented 2 years ago

The documentation is unfortunately still quite sparse and spread over several places. I add the new information to the page I linked in my previous post. Much more information is still in the original documentation (note that you can click on the numbers on the left side and it will show an example of use), and also here.