I am trying to render a latex file to mathml for viewing in firefox. However, when trying to render the following example:


to mathml, neither pandoc nor ht4tex render the i correctly, under the sigma sign. I have tried the following commands:

pandoc text.tex --mathml


htlatex test.tex "html,mathml"

but neither produce the desired output.

Note that when I compile to a pdf file using pdflatex or when using pandoc with the --mathjax option the file renders correctly, but I'm trying to get a solution that produces only mathml.

  • you could raise that with the tex4ht developers, but why would you need such a construct rather than simply \[\sum_i\] you should almost never need \displaystyle or \limits within a document, just in defining commands. – David Carlisle Jun 7 '19 at 6:57

In general, it is hard to support switching commands such as \itshape, \large or \displaystyle in tex4ht. tex4ht just cannot know where it should close the affected content in a reliable way. The font switches are supported using the font information in the DVI file, but there is no such information for \displaystyle.

It is much better to use commands that clearly mark the affected text, like \textit for example. For your use, you need to define a custom command that can be then patched by tex4ht to insert correct MathML elements.

I would redefine your TeX file in the following way, introducing the \displaycontent command:

% https://tex.stackexchange.com/q/494579/2891

The configuration for tex4ht, myconfig.cfg may look as follows:

\renewcommand\displaycontent[1]{\HCode{<mstyle displaystyle="true">}#1\HCode{</mstyle>}}

It just redefines the \displaycontent to include <mstyle displaystyle="true"> before and </mstyle> after the enclosed content.

The file can be compiled using

make4ht -c myconfig.cfg test.tex

This is the resulting MathML:

<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><mrow><mstyle displaystyle='true'><munder class='msub'><mrow><mo class='MathClass-op'>∑</mo>

And it is how it is rendered by Firefox:

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.