2

Maple has a new Latex conversion software now.

This converts Maple expressions (and whole documents) to Latex.

Maple comes with its own style files which are now needed since the Latex generated uses macros and commands defined in this style file. There is currently no way to avoid this as far as I know.

There is no problem using the style file(s) when compiling using lualatex to pdf. All works OK.

The problem is that I am not able to make it work with tex4ht when in mathjax mode. Some commands and macros being used in the Latex generated are not known by mathjax.

I tried to add these to my .cfg file, but it is not working. I do not know if I am doing something wrong or if there is more things to do to make it work with mathjax. So now all my compilation to HTML show up with these commands as unknown which makes the math not readable. Here is a link to an actual page build last night.

Here is a MWE, using small Latex, generated by Maple which I copied to my Latex document

\documentclass[11pt]{article}
\usepackage{amsmath} 
\usepackage{maplestd2e}%this style file comes with Maple

\begin{document}
\[%example code copied from Maple conversion to Latex
u(x,y ,t) = \Mapleoverset{\infty}{\Mapleunderset{\mathit{m} =1}{\sum }}
\Mapleoverset{\infty}{\Mapleunderset{n =1}{\sum}}
\sin(n \pi  x) \sin(\mathit{m} \pi  y)
\]
\end{document}

The maplestd2e.sty is available on the internet if one googles the name. But I also put a copy here maplestd2e.sty if anyone likes to try the above.

Doing lualatex foo5.tex, there is no problem, and it gives the correct output

enter image description here

But when compiling to HTML using

make4ht -ulm default -a debug foo5.tex "mathjax,htm"

it gives

enter image description here

When this happens, normally it means I need to define this command in my .cfg to teach mathjax about this command. But I tried to do this and it is not working. This is what I tried. Looked at Maple's style file to see what the command does. These are near the end of the above linked to file

\newcommand{\Mapleoverset}[2]%
  {\mathop{\kern\z@#2}\limits^{#1}}
\newcommand{\Mapleunderset}[2]%
  {\mathop{\kern\z@#2}\limits_{#1}}

So I edited my .cfg file and added, in the macro section of MathJaxConfig the following

Mapleoverset: ["\\mathop{\#2}\\limits^{\#1}",2],
Mapleunderset: ["\\mathop{\#2}\\limits_{\#1}",2]

Then compiled using

 make4ht -ulm default -a debug -c ./nma_mathjax.cfg foo5.tex "mathjax,htm"

Here is a link to my nma_mathjax.cfg file used. The output of the above is

enter image description here

May be I did not do it right.

As the new Maple Latex software is used more and people try to convert it to HTML using tex4ht, I am sure others will run into the same problems I am having now at one point.

The questions I have: Why does not tex4ht support this style file out of the box as is like with pdf? What does one need to do exactly to tell Mathjax to use these commands from this style file? If I figure how to do it for one of these commands, I can do it for the other commands in this style file.

TL 2020

6
  • You have told tex4ht not to process the math at all but just pass it to mathjax, so it is up to you to define it to mathjax, tex4ht is more or less not involved. I couldn't tell from your description if you are making those definitions available in the web page using those macros Dec 28, 2020 at 0:48
  • @DavidCarlisle I couldn't tell from your description if you are making those definitions available in the web page using those macros Yes. This is done via the .cfg file. It defines the macros/command which go into the web page header (inserted there by tex4ht) and then used by mathjax when the page is loaded. I do not know to how to define these commands there seems to be the problem. The option -c ./nma_mathjax.cfg loads these macros into the web page.
    – Nasser
    Dec 28, 2020 at 0:53
  • too late to try now but \#1 looks wrong shouldn't that be #1 ? Dec 28, 2020 at 0:59
  • @DavidCarlisle No. These # has to be escaped since in a string. If I do not escape them, tex4ht gives error ! Illegal parameter number in definition of \a:MathJaxConfig. <to be read again> I've used these before in .cfg, and those were escaped also and work.
    – Nasser
    Dec 28, 2020 at 1:00
  • odd it shouldn't have a \ in the final javascript config see docs.mathjax.org/en/v2.7-latest/tex.html#defining-tex-macros # isn't a special character in javascript strings Dec 28, 2020 at 1:01

1 Answer 1

3

You cannot put blank lines in the MathJax configuration. It results in JavaScript parsing error, so your definitions aren't used at all. Here is a corrected version:

\Preamble{xhtml,p-width}

%This below does not work. see https://tex.stackexchange.com/questions/543919/what-are-the-limitations-of-using-tikz-with-tex4ht
%\tikzset{every node/.style={/pgf/tex4ht node/escape=true}}

%this disables make4ht loading mathjax
\Configure{MathjaxSource}{}


%\Configure{@HEAD}{\HCode{ <script type="text/javascript" src="/scripts/MathJax-2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML"></script> \Hnewline}}        

%this loads mathjax  

\Configure{MathjaxSource}{https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js}

%V3.0
\Configure{MathJaxConfig}{{  
  tex: {
    maxBuffer: 40*1024,
    packages: {'[+]': ['textmacros']},
    \unexpanded{%
    macros: {      
        sp: "^",
        sb: "_",      
      noalign: ["\#1", 1],
      myadjustbox: ["\#1", 1],      
      medskip: "",
      sc: "\\small\\rm",
      sl: "\\it",
      symbfit: "\\boldsymbol",
      LommelS: ["\\operatorname{LommelS\#1}",1],
      sinc: ["\\operatorname{sinc}"],
      dag: ["\\dagger"],
      ddag: ["\\ddagger"],
      tauL: "\\tau L",
      relax: "{}",
      setlength: ["{}", 2],
      allowbreak: "{}",
      sech: ["\\operatorname{sech}"],
      csch: ["\\operatorname{csch}"],
      arcsec: ["\\operatorname{arcsec}"],
      arccot: ["\\operatorname{arccot}"],
      arccsc: ["\\operatorname{arccsc}"],
      arccosh: ["\\operatorname{arccosh}"],
      arcsinh: ["\\operatorname{arcsinh}"],
      arctanh: ["\\operatorname{arctanh}"],
      arcsech: ["\\operatorname{arcsech}"],
      arccsch: ["\\operatorname{arccsch}"],
      arccoth: ["\\operatorname{arccoth}"],
      erf: ["\\operatorname{erf}"],
      erfi: ["\\operatorname{erfi}"],      
      AiryAi: ["\\operatorname{AiryAi}"],
      AiryBi: ["\\operatorname{AiryBi}"],
      BesselJ: ["\\operatorname{BesselJ}"],
      BesselY: ["\\operatorname{BesselY}"],
      BesselK: ["\\operatorname{BesselK}"],
      BesselI: ["\\operatorname{BesselI}"],
      WhittakerM: ["\\operatorname{WhittakerM}"],
      WhittakerW: ["\\operatorname{WhittakerW}"],
      LambertW: ["\\operatorname{LambertW}"],
      RootOf: ["\\operatorname{RootOf}"],
      Ei: ["\\operatorname{Ei}"],
      Si: ["\\operatorname{Si}"],
      Ci: ["\\operatorname{Ci}"],
      Ssi: ["\\operatorname{Ssi}"],
      Shi: ["\\operatorname{Shi}"],
      Chi: ["\\operatorname{Chi}"],
      Li: ["\\operatorname{Li}"],
      HeunC: ["\\operatorname{HeunC}"],
      HeunCPrime: ["\\operatorname{HeunCPrime}"],
      FresnelC: ["\\operatorname{FresnelC}"],
      EllipticE: ["\\operatorname{EllipticE}"],
      EllipticCE: ["\\operatorname{EllipticCE}"],
      EllipticF: ["\\operatorname{EllipticF}"],
      EllipticK: ["\\operatorname{EllipticK}"],
      EllipticCK: ["\\operatorname{EllipticCK}"],
      EllipticPi: ["\\operatorname{EllipticPi}"],
      EllipticCPi: ["\\operatorname{EllipticCPi}"],
      LegendreP: ["\\operatorname{LegendreP}"],
      LegendreQ: ["\\operatorname{LegendreQ}"],
      dilog: ["\\operatorname{dilog}"],
      polylog: ["\\operatorname{polylog}"],
      StruveH: ["\\operatorname{StruveH}"],
      StruveL: ["\\operatorname{StruveL}"],
      ParabolicCylinderD: ["\\operatorname{ParabolicCylinderD}"],
      hypergeom: ["\\operatorname{hypergeom}"],
      WeierstrassP: ["\\operatorname{WeierstrassP}"],
      MathieuS: ["\\operatorname{MathieuS}"],
      MathieuC: ["\\operatorname{MathieuC}"],
      MathieuSPrime: ["\\operatorname{MathieuSPrime}"],
      MathieuCPrime: ["\\operatorname{MathieuCPrime}"],
      logintegral: ["\\operatorname{log\\_integral}"],
      Mapleoverset: ["\\mathop{\#2}\\limits^{\#1}",2],
      Mapleunderset: ["\\mathop{\#2}\\limits_{\#1}",2]
    }},
    autoload: {
      color: [],
      colorV2: ['color']
    },
    packages: {'[+]': ['noerrors','textmacros']}
  },
  options: {
    ignoreHtmlClass: 'tex2jax_ignore',
    processHtmlClass: 'tex2jax_process'
  },
  loader: {
    load: ['[tex]/noerrors','[tex]/textmacros']
  }
};
}




%added oct 4,2019
%\Configure{@HEAD}{\HCode{
%<script async src="https://www.googletagmanager.com/gtag/js?id=UA-149430386-1"></script>
%<script>
%  window.dataLayer = window.dataLayer || [];
%  function gtag(){dataLayer.push(arguments);}
%  gtag('js', new Date());
%  gtag('config', 'UA-149430386-1');
%</script>}}

         
\Configure{@HEAD}{\HCode{<SCRIPT TYPE="text/javascript">
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == "string")
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, "width=600,height=200,scrollbars=yes");
return false;
}
</SCRIPT>\Hnewline}}

\Configure{@HEAD}{\HCode{
<link rel="shortcut icon" href="\#" />\Hnewline
}}

\Configure{@HEAD}{\HCode{
    <script type="text/javascript" src="/scripts/gifffer-master/lib/gifffer.js"></script>\Hnewline 
<script>
   window.onload = function() {
   Gifffer();
   }
</script>\Hnewline  
}}

%added March 1, 2020
\Configure{@HEAD}{\HCode{
    <script type="text/javascript" src="/scripts/libgif-js-master/libgif.js"></script>\Hnewline
    <script type="text/javascript" src="/scripts/libgif-js-master/rubbable.js"></script>\Hnewline
}
}

\Configure{@HEAD}{\HCode{
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shCore.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushMatlab.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushPlain.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushPython.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushRuby.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushPerl.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushCpp.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushBash.js"></script>\Hnewline
<script type="text/javascript" src="/styles/syntaxhighlighter/scripts/shBrushXml.js"></script>\Hnewline
<script type="text/javascript">SyntaxHighlighter.all()</script>\Hnewline
<link href="/styles/syntaxhighlighter/styles/shCore.css" rel="stylesheet" type="text/css" />\Hnewline
<link href="/styles/syntaxhighlighter/styles/shThemeDefault.css" rel="stylesheet" type="text/css"/>\Hnewline
}}

         
\makeatletter
\@ifpackageloaded{graphicx}{%
  \DeclareGraphicsExtensions{.svg,.png}

  %this below to make it resize the SVG image, if it is there, to
  %what is in the includegraphics.
  %thanks to @Michal.h21 for this trick
  \newcommand\emwidth{10}
  \newcommand\CalcRem[1]{\strip@pt\dimexpr(#1)/\emwidth}
  \Configure{graphics*}
           {svg}
            {\Picture[pict]{\csname Gin@base\endcsname.svg \space style="width:\CalcRem{\Gin@req@width}em;"}%
            \special{t4ht+@File: \csname Gin@base\endcsname.svg}
            }
            
  %make sure this below is here, this will make it resize the png image
  %to what is in the includegraphics command
   \Configure{graphics*}
        {png}
        {%the special command below so it will copy the png over  
           \special{t4ht+@File: \csname Gin@base\endcsname.png}
           \Picture[pict]{\csname Gin@base\endcsname .png
              \space width="\expandafter\the\csname Gin@req@width\endcsname"
            }%  
        }%
            
}{}
\makeatother
  
%see https://tex.stackexchange.com/questions/490873/problem-with-vertical-alignment-of-text-and-images-in-long-table-when-using-tex4
\makeatletter
\@ifpackageloaded{adjustbox}{%
\Configure{halignTR}{}
\Configure{AdjustboxValignTop}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:top;}}}
\Configure{AdjustboxValignMiddle}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:middle;}}}
\Configure{AdjustboxValignCenter}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:middle;}}}
\Configure{AdjustboxValignBottom}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:bottom;}}}
}{}
\makeatother

  
%see   https://tex.stackexchange.com/questions/249179/tex4ht-how-to-create-fixed-width-table-columns
\catcode`\:=11
\Configure{halignTD} {}{}
   {<}{\HCode{ style="white-space:nowrap; text-align:left;"}}
   {-}{\HCode{ style="white-space:nowrap; text-align:center;"}}
   {>}{\HCode{ style="white-space:nowrap; text-align:right;"}}
   {^}{\HCode{ style="vertical-align:top; white-space:nowrap;"}}
   {=}{\HCode{ style="vertical-align:baseline; white-space:nowrap;"}}
   {||}{\HCode{ style="vertical-align:middle; white-space:nowrap;"}}
   {_}{\HCode{ style="vertical-align:bottom; white-space:nowrap;"}}
   {p}{\HCode{ style="white-space:wrap; text-align:left;"}\Protect\a:HColWidth}
   {m}{\HCode{ style="white-space:wrap; text-align:left; vertical-align:middle;"}\Protect\a:HColWidth}
   {b}{\HCode{ style="white-space:wrap; text-align:left; vertical-align:baseline;"}}
   {}
\catcode`\:=12

%see https://tex.stackexchange.com/questions/370308/why-tex4ht-adds-an-extra-newline-when-using-begindescription-after-item
\Css{dl:after {content:"";display:table;clear:both;}}
\Css{dt{float:left;min-width:1em;clear:left;}}
\Css{dd{float:left;}}

  
\begin{document}

%-------------------------------
%this remove lines above graphics and below them in HTML
\ConfigureEnv{figure} 
    {\HCode{}}{\HCode{}}{}{}    

% This one removes the rulers. Taking a look at html4.4ht should make 
% clear what has been changed.
\Configure{float}
   {\ifOption{refcaption}{}{\csname par\endcsname\ShowPar \leavevmode}}
   {\HCode{}}
{\ifvmode \IgnorePar \fi\EndP \HCode{}\csname par\endcsname\ShowPar}

%----------------------------------




\Css{html{
    font-size: 100.0\%;    
}} 

\Css{body{margin-top: 1em; 
          margin-bottom: 1em; 
          width: 92\%;
          max-width: 65em;
          margin-left: auto; 
          margin-right: auto; 
          padding: 0em;
          color: \#444; 
          font-family: arial, sans-serif;
          %line-height: 16px;
          font-style: normal;
          font-size: 1.0em;           
          %border: 1px solid \#F0F0F0 ;
          text-align:left;
          background: \#FFFFFF;}}
          
\Css{li img{vertical-align:middle;}}
\Css{div.caption{text-align:center;}}
\Configure{float}{\csname par\endcsname\ShowPar}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="float">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar}

\Css{table.longtable{margin-left: auto;margin-right:auto;}}

%added august 22, 2020 to force table to have fixed width columns. 
%see https://stackoverflow.com/questions/4185814/fixed-table-cell-width
%does not work
%\Css{table.longtable{width:65em; word-break:break-all;}}

%added feb 10, 2019 to center graphics
%see https://tex.stackexchange.com/questions/474282/tex4ht-css-code-works-using-standard-book-class-but-has-no-effect-using-koma-sc

\Css{div.fbox {display:table;margin-left:auto; margin-right: auto;}}

\Css{div.caption{text-align:center;}}
\Css{div.figure img{text-align:center;display:block;margin-left:auto; margin-right: auto;}}
\Css{div.float img{text-align:center;display:block;margin-left:auto; margin-right: auto;}}
\Css{div.fbox img{text-align:center;display:block;margin-left:auto; margin-right: auto;}}
\Css{div.caption table{margin: auto;}}

%added april 7, 2019 to make underline works with mathjax for math. Thanks
%to Michal Hoftich and Bill Hammond
\Css{span.underline {border-bottom: 0.15ex solid black;text-decoration:none;}}
          
\Css{tr {vertical-align:top;}}

\Css{div.titlepage{text-align:center;}}

%\Css{ td { padding: 10px; }} %bug in texh4t

\EndPreamble

The resulting HTML:

enter image description here

2
  • 1
    You cannot put blank lines in the MathJax configuration OMG ! I had no idea. I was adding empty lines in between different parts to make it more clear. Thanks. It works now.
    – Nasser
    Dec 28, 2020 at 10:20
  • 1
    @Nasser me neither, I just found this issue using error console in Firefox :)
    – michal.h21
    Dec 28, 2020 at 10:25

You must log in to answer this question.

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