2

I need a customized mathml coding. mml: text should be added globally all mathml coding

Current Coding:

 <math display="block" class="equation"><mi>a</mi> <mo class="MathClass-bin">+</mo> <msubsup><mrow><mi>b</mi></mrow><mrow><mn>2</mn></mrow><mrow><mn>3</mn></mrow></msubsup></math>

The Current coding should be changed to

<mml:math display="block" class="equation"><mml:mi>a</mml:mi> <mml:mo class="MathClass-bin">+</mml:mo> <mml:msubsup><mml:mrow><mml:mi>b</mml:mi></mml:mrow><mml:mrow><mml:mn>2</mml:mn></mml:mrow><mml:mrow><mml:mn>3</mml:mn></mml:mrow></mml:msubsup></mml:math>

MWE:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation} 
a+b_{2}^{3}
\end{equation} 

\end{document}

My CFG:

\Preamble{xhtml,mathml,NLM,charset=UTF-8,-xtpipes,NoFonts,no-DOCTYPE,refcaption}

\Configure{section} 
            {\HCode{<section>}}    {\HCode{</section>}} 
            {\HCode{<title>}}      {\HCode{</title>}} 
\Configure{subsection} 
            {\HCode{<subsection>}}    {\HCode{</subsection>}} 
            {\HCode{<title>}}      {\HCode{</title>}} 
\Configure{subsubsection} 
            {\HCode{<subsubsection>}}    {\HCode{</subsubsection>}} 
            {\HCode{<title>}}      {\HCode{</title>}} 

\Configure{textit}{\HCode{<italic>}\NoFonts}{\HCode{</italic>}\EndNoFonts}
\Configure{textbf}{\HCode{<bold>}\NoFonts}{\HCode{</bold>}\EndNoFonts}
\Css{.textsuperscript{font-size:.7rem;}}
\Css{.textsubscript{font-size:.7rem;}}
\Configure{HtmlPar}
{\EndP\Tg<p>}
{\EndP\Tg<p>}
{\HCode{</p>\Hnewline}}
{\HCode{</p>\Hnewline}}
\begin{document}
\EndPreamble

How to get the customized mathml output. How to configure the cfg to get this output. Kindly advice.

1 Answer 1

2

You can set xml prefix for mathml elements with \Configure{mathml}{prefix}. You also need to register the prefix in the root element with xmlns attribute. Full config file:

\Configure{ext}{xhtml}
\Preamble{xhtml,mathml,NLM,charset=UTF-8,-xtpipes,NoFonts,refcaption,ext=.xhtml}

\Configure{mathml}{mml:}
\Configure{HTML}{\HCode{<html xmlns="http://www.w3.org/1999/xhtml"\Hnewline  xmlns:mml="http://www.w3.org/1998/Math/MathML">}}
{\HCode{</html>}}
\Configure{MathClass}{0}{*}{<mml:mi\Hnewline>}{</mml:mi>}{}
\Configure{MathClass}{1}{*}{<mml:mo\Hnewline
             mmlclass="MathClass-op">}{</mml:mo>}{}
\Configure{MathClass}{2}{*}{<mml:mo\Hnewline
             mmlclass="MathClass-bin">}{</mml:mo>}{}
\Configure{MathClass}{3}{*}{<mml:mo\Hnewline
             mmlclass="MathClass-rel">}{</mml:mo>}{}
   \Configure{MathClass}{4}{*}{<mml:mrow
                                     ><mml:mo\Hnewline
             mmlclass="MathClass-open">}
                           {</mml:mo><mml:mrow>}{}
   \Configure{MathClass}{5}{*}{</mml:mrow><mml:mo\Hnewline
             mmlclass="MathClass-close">}
                           {</mml:mo></mml:mrow>}{}
\Configure{MathClass}{6}{*}{<mml:mo\Hnewline
             mmlclass="MathClass-punc">}{</mml:mo>}{}
\Configure{MathClass}{7}{*}{<mml:mn>}{</mml:mn>}
                           {0123456789}     
% \Configure{MathClass}{2}{*}{<mml:mo\Hnewline>}{</mml:mo>}{}
% \Configure{MathClass}{3}{*}{<mml:mn\Hnewline>}{</mml:mn>}{}


\Configure{section} 
            {\HCode{<section>}}    {\HCode{</section>}} 
            {\HCode{<title>}}      {\HCode{</title>}} 
\Configure{subsection} 
            {\HCode{<subsection>}}    {\HCode{</subsection>}} 
            {\HCode{<title>}}      {\HCode{</title>}} 
\Configure{subsubsection} 
            {\HCode{<subsubsection>}}    {\HCode{</subsubsection>}} 
            {\HCode{<title>}}      {\HCode{</title>}} 

\Configure{textit}{\HCode{<italic>}\NoFonts}{\HCode{</italic>}\EndNoFonts}
\Configure{textbf}{\HCode{<bold>}\NoFonts}{\HCode{</bold>}\EndNoFonts}
\Css{.textsuperscript{font-size:.7rem;}}
\Css{.textsubscript{font-size:.7rem;}}
\Configure{HtmlPar}
{\EndP\Tg<p>}
{\EndP\Tg<p>}
{\HCode{</p>\Hnewline}}
{\HCode{</p>\Hnewline}}
\begin{document}
\EndPreamble

the important lines are

\Configure{mathml}{mml:}
\Configure{HTML}{\HCode{<html xmlns="http://www.w3.org/1999/xhtml"\Hnewline  xmlns:mml="http://www.w3.org/1998/Math/MathML">}}
{\HCode{</html>}}

for some reason, Firefox doesn't want to display the file correctly with .html extension, but it works with .xhtml. We can change that with

\Configure{ext}{xhtml}

which must happen before the \Preamble command.

The result:

<?xml version="1.0" encoding="utf-8" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" 
"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" > 
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:mml="http://www.w3.org/1998/Math/MathML"><head> <title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<!-- charset=utf-8,html,xhtml,mathml,NLM,charset=UTF-8,-xtpipes,NoFonts,refcaption,ext=.xhtml --> 
<meta name="src" content="sample.tex" /> 
<meta name="date" content="2015-09-29 19:47:00" /> 
<link rel="stylesheet" type="text/css" href="sample.css" /> 
</head><body 
>
   <table class="equation"><tr><td> <a 
 id="x1-2r1"></a>
<!--l. 6--><mml:math 
 xmlns="http://www.w3.org/1998/Math/MathML"  
display="block" mml:class="equation">
                              <mml:mi 
>a</mml:mi> <mml:mo 
mmlclass="MathClass-bin">+</mml:mo> <mml:msubsup><mml:mrow 
><mml:mi 
>b</mml:mi></mml:mrow><mml:mrow 
><mml:mn>2</mml:mn></mml:mrow><mml:mrow 
><mml:mn>3</mml:mn></mml:mrow></mml:msubsup 
>
</mml:math></td><td class="eq-no">(1)</td></tr></table>

</body></html>

and rendering in Firefox:

enter image description here

1
  • Your solution is really impressive. I got the solution
    – CS Kumar
    Commented Sep 30, 2015 at 6:27

You must log in to answer this question.

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