4

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(...)
    \IfBooleanTF{#1}
    {\let\fractype\flatfrac}
    {\let\fractype\frac}
    \IfNoValueTF{#4}
    {
        \IfNoValueTF{#5}
        {\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?

1
  • 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. Commented Apr 30, 2015 at 17:29

1 Answer 1

4

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

<math 
 xmlns="http://www.w3.org/1998/Math/MathML"  
display="inline" ><mfrac><mrow 
><mi mathvariant="normal">d</mi><mi 
>x</mi></mrow>
<mrow 
><mi mathvariant="normal">d</mi><mi 
>t</mi></mrow></mfrac> </math>
2
  • I feel rather daft now; that seems to work where my previous attempt with mathjax fails... Thanks!
    – lpmn
    Commented Apr 30, 2015 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
    Commented Apr 30, 2015 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .