michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

'mathml'-option does not process \bf #98

Closed yalguzaq closed 1 year ago

yalguzaq commented 1 year ago

LaTeX: $$\left({\bf E}|X|^p\right)^{\frac{q}{p}} \leq {\bf E} |X|^q$$

Compilation command: make4ht markup.tex 'mathml,mathjax'

Erroneous output: image

Correct output: image

The problem summary: E is not shown in bold when given inside {\bf ...} environment. This is a widespread command among TeX users.

michal-h21 commented 1 year ago

Try this configuration file:

\Preamble{xhtml}
\catcode`\:=11
\makeatletter
\def\:closemi{\HCode{</\a:mathml mi>}\EndPauseMathClass}
\def\bf{\ifmmode\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi{\PauseMathClass\HCode{<\a:mathml mi mathvariant="bold">}\aftergroup\:closemi}{\bfseries}}
\makeatother
\catcode`\:=12
\begin{document}
\EndPreamble

In general, font switch commands are quite hard to support.

yalguzaq commented 1 year ago

Will this be included in the next make4ht version or should I keep this in my cfg file indefinitely?

michal-h21 commented 1 year ago

I can add it to the mathml output in TeX4ht. Does it work well in your files?

I am busy this week, but I can add it next week, if it works correct.y

yalguzaq commented 1 year ago

Yes, I confirm that this is a solution to my issue. Thanks a lot.

yalguzaq commented 1 year ago

Will this also be included as the default behaviour for mathjax?

michal-h21 commented 1 year ago

I think this example works in MathJax? But in general, you can pass a definition for unknown commands to MathJax, see this example.