1

The following is Latex generated by CAS called Fricas.

It compiles OK in lualatex (but get a warning about it using \over) but the end result looks correct.

But when I try to compile the same latex file with tex4ht using mathjax it has trouble with it. Also if I do not use Mathjax, tex4ht still does not compile it OK, it has trouble with \over.

I copied this Latex from fricas output directly from Linux terminal, as is and pasted it into my Latex document. First will show screen shot and then the MWE at the end.

Mathematica graphics

And here it is inside my Latex file

\documentclass[11pt]{article}%
\usepackage{amsmath}
\begin{document}
\[
{{\log \left( {{{\sqrt {{-{{x} \sp {2}}+1}}}+1}} \right)} 
  -{\log \left( {{{\sqrt {{-{{x} \sp {2}}+1}}} -1}} \right)}
  +{{\left( {2 \  {\log \left( {x} \right)}} -4 \right)} \  {\sqrt {{-{{x} \sp {2}}+1}}}}
  +{2 \  x \  {\arcsin \left(   {x} \right)} \  {\log \left( {x} \right)}} 
  -{2 \  x \  {\arcsin \left( {x} \right)}}} \over 2
\]

\end{document}

It compiled OK using Lualatex to

Mathematica graphics

But here is the problem. When compiled to HTML using

  make4ht -ulm default  foo.tex "htm,0,mathjax"

This is the output

Mathematica graphics

I have no idea why mathjax does not like the Latex. Here is the raw HTML

<!DOCTYPE html> 
<html lang="en-US" xml:lang="en-US" > 
<head><title></title> 
<meta  charset="utf-8" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="viewport" content="width=device-width,initial-scale=1" /> 
<link rel="stylesheet" type="text/css" href="foo.css" /> 
<meta name="src" content="foo.tex" /> 
 <script type="text/x-mathjax-config"> MathJax.Hub.Config({ 'fast-preview': {disabled: true}, TeX: { extensions: ["color.js","AMSmath.js"], equationNumbers: { autoNumber: "AMS" } }, extensions: ["tex2jax.js"], tex2jax: {  inlineMath: [ ["\\\(","\\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], processEscapes: true, processEnvironments: true } }); </script> 
 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>  
</head><body 
>
<!--l. 14--><p class="noindent" >\[{{\log \left ({{{\sqrt{{-{{x} \sp{2}}+1}}}+1}} \right )} -{\log \left ({{{\sqrt{{-{{x} \sp{2}}+1}}} -1}} \right )} +{{\left ({2 \{\log \left ({x} \right )}} -4 \right )} \{\sqrt{{-{{x} \sp{2}}+1}}}} +{2 \ x \{\arcsin \left ({x} \right )} \{\log \left ({x} \right )}} -{2 \ x \{\arcsin \left ({x} \right )}}} \over 2 \]
</p>   

</body> 
</html>

When I do not use mathjax mode, tex4ht output is a a little better, but the fractions is all missed up.

 make4ht -ulm default  foo.tex "htm"

Mathematica graphics

My question is: Is the math generated by Fricas above not valid in some way? Other than using \over which is old, is there something else wrong which causes mathjax to fail so bad? I also removed the \over, and the problem remained with tex4ht in mathjax mode. So it seems there is something other than \over which mathjax is not happy with.

I can go complain to Fricas about its Latex, but wanted to first check here.

TL 2019

2
  • 1
    \over is not latex and amsmath actually overwrites the definition to warn you about it. Commented Apr 19, 2020 at 9:57
  • 2
    MathJax handles the \over just fine. It is the \sp and perhaps the \arcsin that are not defined in MathJax. You could \def\sp{^} (and \def\sb{_}) to define those, and similarly for arcsine, if that is undefined. Commented Apr 19, 2020 at 11:17

1 Answer 1

1

You can configure custom command declaration for MathJax in a .cfg file:

\Preamble{xhtml}
\Configure{@HEAD}{\HCode{
<script>
window.MathJax = {
  tex: {
    macros: {
      \unexpanded{
        sp: "^",
        sb: "_",
      }
    }
  }
};
</script>
}}
\begin{document}
\EndPreamble

MathJax still has some issues with your code. I made a simpler example that compiles:

\[
{{\log \left( {{{\sqrt {{-{{x} \sp {2}}+1}}}+1}} \right)}
  -{2\ x\,{\arcsin\left({x}\right)}} 
}\over 2
\]

enter image description here

But as soon as I change the space in

  -{2\ x\,{\arcsin\left({x}\right)}} 

back to your version:

  -{2\ x\ {\arcsin\left({x}\right)}} 

The issue is back:

enter image description here

I would say that it seems like MathJax issue.

2
  • Thanks Michal for fixing the sp and sb. Will add these to my .cfg. But there is still actually a bug in tex4ht. It removes the space after \ and that is why it still does not work. I'll add separate question on this now. This looks like new bug.
    – Nasser
    Commented Apr 20, 2020 at 3:33
  • FYI, I found in V3 mathjax, I had to adjust it a little, like this tex: { macros: { sp: "^", sb: "_", etc... i.e I did not use \unexpanded{ etc...}. When I used \unexpanded as you showed, mathjax did not like it and did not render it. So seems due to changes in how V3 configuration works as it is a little different from V2
    – Nasser
    Commented Apr 20, 2020 at 23:29

You must log in to answer this question.

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