MathML is very verbose and is a pain to write manually, which is no problem if your code is automatically generated. For programs it is easy to parse, since it is XML.
TeX math code was designed to be written by humans and results in much shorter code. I cannot answer your question if one format will replace the other. As I mentioned they serve different purposes.
Is there any attempt to automatically transform one into the other that anyone is aware of?
I cannot speak for LaTeX, but in ConTeXt you can input MathML directly. Information about MathML in ConTeXt and the Wiki - MathML. Here is an example (credits to Hans Hagen) taken from one of the ConTeXt manuals:
\usemodule[mathml]
\starttext
\xmlprocessdata{}{
<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3c.org/mathml" version="2.0">
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci> x </ci>
</bvar>
<apply>
<root/>
<ci> u </ci>
</apply>
</apply>
<apply>
<times/>
<apply>
<divide/>
<cn> 1 </cn>
<apply>
<times/>
<cn> 2 </cn>
<apply>
<root/>
<ci> u </ci>
</apply>
</apply>
</apply>
<apply>
<diff/>
<bvar>
<ci> x </ci>
</bvar>
<ci> u </ci>
</apply>
</apply>
</apply>
</math>
}{}
\stoptext
The output:
For a TeX to MathML conversion, you can use the XML export, see ConTeXt wiki - epub and my answer to the question Converting ConTeXt document to HTML.
The main problem is that the elife
class loads Unicode-math package, which is not supported by TeX4ht. It even causes fatal error. To fix that, we need to create a special file that will prevent Unicode-math from loading, and define dummy version of \setmathfont
.
Here is the file, unicode-math-hooks.4ht
:
\:dontusepackage{unicode-math}
\RequirePackage{fontspec}
\NewDocumentCommand \setmathfont { O{} m O{} }{}
\endinput
We need to register this file in TeX4ht, using usepackage.4ht
:
% usepackage.4ht (2021-12-14-13:43), generated from tex4ht-4ht.tex
% Copyright 2003-2009 Eitan M. Gurari
% Copyright 2009-2021 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2021-12-14-13:43}
\def\:temp{tex4ht}\ifx \:temp\@currname
\:warning{\string\usepackage{tex4ht} again?}
\def\:temp#1htex4ht.def,tex4ht.sty#2!*?: {\def\:temp{#2}}
\expandafter\:temp \@filelist htex4ht.def,tex4ht.sty!*?: %
\ifx \:temp\empty \else
\:warning{if
\string\RequirePackage[tex4ht]{hyperref} or
\string\usepackage[tex4ht]{hyperref} was
used try instead, repectively,
\string\RequirePackage{hyperref} or
\string\usepackage{hyperref}}
\fi
\fi
\gdef\a:usepackage{\use:package ,!*?: }
\gdef\use:package#1,{%
\if :#1:\def\:temp##1!*?: {}\else
\def\:temp{#1}\ifx \@currname\:temp
\def\:temp##1!*?: {\input usepackage.4ht }%
\else \let\:temp=\use:package \fi
\fi \:temp}
\Configure{PackageHooks}{biblatex-chicago.sty}{biblatex-chicago-hooks.4ht}
\Configure{PackageHooks}{cleveref.sty}{cleveref-hooks.4ht}
\Configure{PackageHooks}{xr.sty}{xr-hooks.4ht}
\Configure{PackageHooks}{xr-hyper.sty}{xrhyper-hooks.4ht}
\Configure{PackageHooks}{eso-pic.sty}{esopic-hooks.4ht}
\Configure{PackageHooks}{showframe.sty}{showframe-hooks.4ht}
\Configure{PackageHooks}{expl3.sty}{expl3-hooks.4ht}
\Configure{PackageHooks}{savetrees.sty}{savetrees-hooks.4ht}
\Configure{PackageHooks}{newcomputermodern.sty}{newcomputermodern-hooks.4ht}
\Configure{PackageHooks}{newcomputermodern.sty}{newcomputermodern-hooks.4ht}
\Configure{PackageHooks}{fontawesome5-utex-helper.sty}%
{fontawesome5-utex-helper-hooks.4ht}
\Configure{PackageHooks}{fontawesome5.sty}{fontawesome5-hooks.4ht}
\Configure{PackageHooks}{biblatex.sty}{biblatex-hooks.4ht}
\Configure{PackageHooks}{xeCJK.sty}{xecjk-hooks.4ht}
\Configure{PackageHooks}{ctex.sty}{ctex-hooks.4ht}
\Configure{PackageHooks}{polyglossia.sty}{polyglossia-hooks.4ht}
\Configure{PackageHooks}{fontspec.sty}{fontspec-hooks.4ht}
\Configure{PackageHooks}{tikz.sty}{tikz-hooks.4ht}
\Configure{PackageHooks}{pdfbase.sty}{pdfbase-hooks.4ht}
\Configure{PackageHooks}{hyperref.sty}{hyperref-hooks.4ht}
\Configure{PackageHooks}{caption.sty}{caption-hooks.4ht}
\Configure{PackageHooks}{minted.sty}{minted-sty-hooks.4ht}
\Configure{PackageHooks}{graphics.sty}{graphics-hooks.4ht}
\Configure{PackageHooks}{graphbox.sty}{graphbox-hooks.4ht}
\Configure{PackageHooks}{xcolor.sty}{xcolor-hooks.4ht}
\Configure{PackageHooks}{imakeidx.sty}{imakeidx-hooks.4ht}
\Configure{PackageHooks}{fancyhdr.sty}{fancyhdr-hooks.4ht}
\Configure{PackageHooks}{exerquiz.sty}{exerquiz-hooks.4ht}
\Configure{PackageHooks}{hyperxmp.sty}{hyperxmp-hooks.4ht}
\Configure{PackageHooks}{datetime2.sty}{datetime2-hooks.4ht}
\Configure{PackageHooks}{unicode-math.sty}{unicode-math-hooks.4ht}
\endinput
With this fix, you will not get a fatal error, but you will still get a compilation error caused by elife
's additions to \maketitle
. We can fix this issue with elife.4ht
file:
\def\:tempa{%
\a:themetadata%
\textbf{*For correspondence:} \@correspondence\par
\ifx\empty\@contribution\else
\c:themetadata\bigskip\@contribution\d:themetadata\fi
\ifx\empty\@presentaddress\else
\e:themetadata\textbf{Present address: }\@presentaddress\f:themetadata\fi
\bigskip
\ifx\empty\@deceased\else\g:themetadata\@deceased\h:themetadata\fi
\b:themetadata%
}
\HLet\themetadata\:tempa
% redefine \@author to include affiliations and other information
\def\:tempa{\a:authlist\ifx\AB@affillist\AB@empty\AB@author\else
\ifnum\value{affil}>\value{Maxaffil}\def\rlap##1{##1}%
\c:authlist\AB@authlist\d:authlist\themetadata\e:authlist\AB@affillist\f:authlist
\else \AB@authors\fi\fi\b:authlist}
\HLet\@author\:tempa
\NewConfigure{themetadata}{8}
\NewConfigure{authlist}{6}
\renewenvironment{abstract}{%
\textcolor{eLifeLightBlue}{\large\bfseries\abstractname\space}
}{%
}
\Hinput{elife}
\endinput
It inserts some configurable hooks that can be used to insert HTML code. Yu can configure these hooks in a .cfg
file:
\Preamble{xhtml}
% configure environments in \maketitle
\Configure{authlist}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="authlist">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
{\HCode{<div>}}{\HCode{</div><div>}}{\HCode{</div><div>}}{\HCode{</div>}}
\Configure{themetadata}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="themetadata">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
{\HCode{<div>}}{\HCode{</div><div>}}{\HCode{</div><div>}}
{\HCode{</div><div>}}{\HCode{</div><div>}}{\HCode{</div>}}
\Css{.themetadata{font-size:0.8rem;}}
\def\IgnoreRule{\special{t4ht@\string_}}
\def\EndIgnoreRule{\special{t4ht@\string_\string_}}
\ConfigureEnv{abstract}
{\ifvmode\IgnorePar\fi\EndP\HCode{<section role="doc-abstract" class="abstract">\Hnewline}\IgnoreRule}
{\ifvmode\IgnorePar\fi\EndP\HCode{</section>\Hnewline}\EndIgnoreRule}{}{}
\Css{.authlist span{font-size:0.8rem;}}
\begin{document}
\EndPreamble
It should compile correctly now:
Best Answer
It is possible to do that, but it is not that easy. Here is a MWE:
As you can see, I introduced the
\eqannotate
command, which is used in theequation
environment. I am afraid that it is not easily possible to catch contents of environments, so they need to be marked by hand (or using pre-processing script).Here is a configuration file:
MathML has the
<annotation>
element, it can be used to insert raw LaTeX code to the HTML as an annotation.\Configure{$}
and\Configure{[]}
configure what HTML code will be inserted for$ ... $
and\[ ... \]
. It also calls command that saves the original LaTeX code in a token list, typesets MathML and then prints the saved tokens inside<annotation>
. Most of this code is copied frommathml.4ht
, it is only a bit simplified.Regarding wrong formatting of
$\mathbf{V_{Obs}}$
, this can be fixed using the following DOM filter:Compile using:
This is the resulting HTML:
And rendered page: