michal-h21 / make4ht

Build system for tex4ht
131 stars 15 forks source link

'mathml,mathjax' causing problems with `'` as `\prime` #130

Closed yalguzaq closed 10 months ago

yalguzaq commented 11 months ago

Is there a way to address the issue that make4ht produces errors when faced with expressions of the type $f''$ instead of $f^{\prime\prime}$? I would have simply replaced all repeating occurrences of '...' with ^{\prime...\prime}, but there are text-mode primes that need to be taken into consideration.

make4ht

make4ht --config make4ht.cfg file.tex 'mathjax'
make4ht file.tex 'mathjax'

config.cfg

\Preamble{xhtml,mathml,mathjax}

\begin{document}

\EndPreamble

file.tex

\documentclass{article}
\usepackage{amsmath,amssymb,amsthm}
\begin{document}
$$f''$$
\end{document}

image

michal-h21 commented 11 months ago

Thanks for the report. Try this configuration file, it seems to fix the issue:


\Preamble{xhtml,mathml,mathjax}

\catcode`\:=11
\Configure{'}
   {\let\:primes=\empty}
   {\relax \csname SUB:prime\endcsname\sp{%
      \global\let\SUB:prime=\:UnDef
      \def\:tempa{\prime\prime}\ifx \:tempa\:primes
              \mathop{\HCode{<\a:mathml mi>\string&\#x2033;</\a:mathml mi>}}\else
      \def\:tempa{\prime\prime\prime}\ifx \:tempa\:primes
              \mathop{\HCode{<\a:mathml mi>\string&\#x2034;</\a:mathml mi>}}\else
              \:primes \fi\fi}%
   }
   {\let\prime=\relax \xdef\:primes{\:primes\prime}}
\catcode`\:=12
\begin{document}
\EndPreamble

If it works, I will add it to TeX4ht sources.

yalguzaq commented 10 months ago

Yes, this solved the problem. Thanks a lot.