I've had a varying level of success converting LaTeX documents into HTML, but one of the major problems I've encountered is converting expressions which contain commands defined through the xparse package. For example,

\DeclareDocumentCommand\derivative{ s o m g d() }
{ % Total derivative
    % s: star for \flatfrac flat derivative
    % o: optional n for nth derivative
    % m: mandatory (x in df/dx)
    % g: optional (f in df/dx)
    % d: long-form d/dx(...)
        {\fractype{\diffd \IfNoValueTF{#2}{}{\sp{#2}}}{\diffd #3\IfNoValueTF{#2}{}{\sp{#2}}}}
        {\fractype{\diffd \IfNoValueTF{#2}{}{\sp{#2}}}{\diffd #3\IfNoValueTF{#2}{}{\sp{#2}}} \argopen(#5\argclose)}
    {\fractype{\diffd \IfNoValueTF{#2}{}{\sp{#2}} #3}{\diffd #4\IfNoValueTF{#2}{}{\sp{#2}}}}
\DeclareDocumentCommand\dv{}{\derivative} % Shorthand for \derivative

is a command to typeset a derivative, so $\dv{x}{t}$ will produce a nicely formatted dx/dt notation. This example is taken from the physics package from CTAN, but I use a number of similar macros in day-to-day work. Is there a way to either convert these macros into standard tex markup before passing the file to e.g. pandoc, or is there a way to convert them as part of the html conversion process, so that they can be rendered in MathML or by MathJax?

  • latexml (and also tex4ht) should in some sense be able to follow the macro definitions but you don't really want to expand/translate all of xparse every time, most systems, certainly tex4ht and mathjax allow you to specify custom conversions, so in mathjax's case you just need to define \derivative in javascript and add that javascript code as an extension in the mathjax customisation object. – David Carlisle Apr 30 '15 at 17:29

If you want to convert math to mathml with tex4ht, you only need to provide mathml option:

htlatex filename "xhtml,mathml" 

for your example, the result is following:

enter image description here

display="inline" ><mfrac><mrow 
><mi mathvariant="normal">d</mi><mi 
><mi mathvariant="normal">d</mi><mi 
>t</mi></mrow></mfrac> </math>
  • I feel rather daft now; that seems to work where my previous attempt with mathjax fails... Thanks! – lpmn Apr 30 '15 at 19:26
  • 1
    @lpmn mathjax just supports TeX-like syntax, it really doesn't support custom macros without configuration. you can combine mathjax with mathml in order to support browsers without mathml support. see tex.stackexchange.com/a/239944/2891 for example – michal.h21 Apr 30 '15 at 19:34

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.