1

I'm trying to change the MathJax font used by Tex4ht to AMS Euler, which can be done by including the following code on a webpage

<script type="text/x-mathjax-config">
var font = "Neo-Euler";
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [['$','$']],
        displayMath: [['\\[','\\]']],
        processEscapes: true,
    },
    "SVG":{ 
        font:font
    },
    "HTML-CSS": {
        webFont: font,
        imageFont: font,
        preferredFont: font,
        availableFonts: [],
        scale: 85,
        mtextFontInherit: true
    }
});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

However, if I try to insert this within an \HCode instruction, I get these errors

\Configure{@HEAD}{\endparagraph\HCode{
  <script type="text/x-mathjax-config">
  var font = "Neo-Euler";
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [['$','$']],
      displayMath: [['\\[','\\]']],
      processEscapes: true,
    },
    "SVG":{
      font:font
    },
    "HTML-CSS": {
      webFont: font,
      imageFont: font,
      preferredFont: font,
      availableFonts: [],
      scale: 85,
      mtextFontInherit: true
    }
  }); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
}}
[ERROR]   htlatex: ./config/html.cfg    149      Argument of \reserved@a has an extra }.
[ERROR]   htlatex: ./config/html.cfg    149      Paragraph ended before \reserved@a was complete.
[ERROR]   htlatex: ?    60       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@item doesn't match its definition.
[ERROR]   htlatex: ?    68       Argument of \g:Advance has an extra }.
[ERROR]   htlatex: ?    68       Paragraph ended before \g:Advance was complete.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@item doesn't match its definition.
[ERROR]   htlatex: ?    68       Argument of \g:Advance has an extra }.
[ERROR]   htlatex: ?    68       Paragraph ended before \g:Advance was complete.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@item doesn't match its definition.
[ERROR]   htlatex: ?    68       Argument of \g:Advance has an extra }.
[ERROR]   htlatex: ?    68       Paragraph ended before \g:Advance was complete.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@item doesn't match its definition.
[ERROR]   htlatex: ?    68       Argument of \g:Advance has an extra }.
[ERROR]   htlatex: ?    68       Paragraph ended before \g:Advance was complete.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@item doesn't match its definition.
[ERROR]   htlatex: ?    68       Argument of \g:Advance has an extra }.
[ERROR]   htlatex: ?    68       Paragraph ended before \g:Advance was complete.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@item doesn't match its definition.
[ERROR]   htlatex: ?    68       Argument of \g:Advance has an extra }.
[ERROR]   htlatex: ?    68       Paragraph ended before \g:Advance was complete.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@item doesn't match its definition.
[ERROR]   htlatex: ?    68       Argument of \g:Advance has an extra }.
[ERROR]   htlatex: ?    68       Paragraph ended before \g:Advance was complete.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Undefined control sequence.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[ERROR]   htlatex: ?    68       Use of \@chapter doesn't match its definition.
[FATAL]   make4ht-lib: Fatal error. Command htlatex returned exit code 1

I figured embedding the code inside a \verb|| might help, but that caused a different issue.

[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename     Line    Message
[ERROR]   htlatex: ?    150      TeX capacity exceeded, sorry [input stack size=5000].
[FATAL]   make4ht-lib: Fatal error. Command htlatex returned exit code 1

My full config file is

\Preamble{xhtml}

% add tufte.css to your document
\Configure{AddCss}{/tufte.css}

\Configure{MathjaxSource}
{}

\Configure{@HEAD}{\endparagraph\HCode{
  <script type="text/x-mathjax-config">
  var font = "Neo-Euler";
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [['$','$']],
      displayMath: [['\\[','\\]']],
      processEscapes: true,
    },
    "SVG":{
      font:font
    },
    "HTML-CSS": {
      webFont: font,
      imageFont: font,
      preferredFont: font,
      availableFonts: [],
      scale: 85,
      mtextFontInherit: true
    }
  }); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
}}

% helper macro to close the current paragraph
\def\endparagraph{\ifvmode\IgnorePar\fi\EndP}

% insert <article> element to the document body
\Configure{@BODY}{\endparagraph\HCode{<article>}}
\Configure{@/BODY}{\endparagraph\HCode{</article>}}

% Tufte LaTeX makes \section and \subsection to behave like \section* and \subsection*
% so we need to configure like<section level>
% These configurations insert <section> elements and print titles in apropriate header elements
\Configure{likesection}
{\endparagraph\HCode{<section>}}{\endparagraph\HCode{</section>}}
{\HCode{<h2>}}{\HCode{</h2>}\par\ShowPar}

\Configure{likesubsection}
{\endparagraph\HCode{<section>}}{\endparagraph\HCode{</section>}}
{\HCode{<h3>}}{\HCode{</h3>}\par\ShowPar}

% we must redefine TOC to print starred sectioning commands
% \TableOfContents is provided by TeX4ht
\renewcommand\tableofcontents{\endparagraph\HCode{<h2>Contents</h2>\Hnewline}\TableOfContents[likesection,likesubsection]}

% custom \maketitle
\makeatletter
\renewcommand{\maketitle}{%
  \begingroup%
    \endparagraph\HCode{<h1>}\@title\HCode{</h1>}%
    \HCode{<p class="subtitle">}\@author\HCode{</p>}%
    \HCode{<p class="subtitle">}\@date\HCode{</p>}%
  \endgroup
}

% make images resize automatically
\Configure{Gin-dim}{}
\Css{img {
    max-width: 100\%;
    height: auto;
}}

% fix for commands redefined by soul
\@ifpackageloaded{soul}{%
\renewcommand{\allcaps}[1]{\MakeTextUppercase{#1}}%
\renewcommand{\smallcaps}[1]{{\scshape\MakeTextLowercase{#1}}}%
\renewcommand{\textsc}[1]{\textcaps{#1}}%
}{}

% footnotes and sidenotes

\long\def\@tufte@sidenote[#1][#2]#3{%
  \stepcounter\@mpfn%
\bgroup% make font changes local
  \HCode{<label for="sitenote-\thempfn" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sidenote-\thempfn" class="margin-toggle" />}%
  \HCode{<span class="sidenote">}#3\HCode{</span>}%
\egroup%
}
\renewcommand\marginnote[2][0pt]{%
  \stepcounter\@mpfn%
\bgroup% make font changes local
  \HCode{<label for="sitenote-\thempfn" class="margin-toggle"></label><input type="checkbox" id="sidenote-\thempfn" class="margin-toggle" />}%
  \HCode{<span class="marginnote">}#2\HCode{</span>}%
\egroup%
}

% environments

\ConfigureEnv{verbatim}{\endparagraph\HCode{<pre><code>}\NoFonts}{\EndNoFonts\endparagraph\HCode{</code></pre>}}{}{}
\ConfigureEnv{fullwidth}{\endparagraph\HCode{<div class="fullwidth">}%
\ConfigureList{list}{}{}{}{}% fullwidth uses list environment internally, we don't need this
\par\ShowPar\indent% require insertion of paragraph
}
{\endparagraph\HCode{</div>}}{}{}

% floats

\NewConfigure{marginfloat}{2}

% redefine internal margin float environment in order to prevent use of minipage and other undersirable environments
\renewenvironment{@tufte@margin@float}[2][-1.2ex]%
{\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
\begingroup%
\let\textwidth\marginparwidth% \includegraphics[width=\textwidth]{...} should work
\def\@captype{#2}%
\par%
% redefine paragraph
\Configure{HtmlPar}{\EndP\csname a:marginfloat\endcsname}{\EndP\csname a:marginfloat\endcsname}{\csname b:marginfloat\endcsname}{\csname b:marginfloat\endcsname}%
}
{\endgroup}

\Configure{marginfloat}{\HCode{<p><span class="marginnote">}
% we must handle \caption inside marginnote
\Configure{caption}{\HCode{<span class="figure">}}{:\space}{}{\HCode{</span>}}
}{\HCode{</span></p>}}{}{}

% display marginnote caption on a separate line
\Css{.marginnote .figure{display:block;}}

\renewenvironment{@tufte@float}[3][htbp]%
{\@float{#2}[#1]}{\end@float}

% caption should produce margin note by default
\Configure{caption}{\HCode{<span class="marginnote">}}{:\space}{}{\HCode{</span>}}

% figure* should produce full width image
% we need to make few adjustments
\ConfigureEnv{figure*}{
\Configure{float}{}{\endparagraph\HCode{<figure class="fullwidth">}}{\endparagraph\HCode{</figure>}\csname par\endcsname\ShowPar}
\Configure{caption}{\endparagraph\HCode{<span class="figure">}}{:\space}{}{\HCode{</span>}}
}{}{}{}

\ConfigureEnv{margintable}{\endparagraph\HCode{<div class="margintable">}\Configure{caption}{}{:\space}{}{}}{\endparagraph\HCode{</div>}}{}{}

% fix for display math length
\Css{div.math-display, div.par-math-display {width: 55\%}}

\makeatother

\begin{document}
\EndPreamble

The $\LaTeX$ file in question can be found here.

2
  • Could you also add an example of your TeX file? I
    – michal.h21
    May 1 at 19:44
  • I've added a link at the bottom of the post. May 1 at 20:13

1 Answer 1

1

It seems like an issue with unwanted expansion in your MathJax config. You can use \detokenize to prevent that:

\Configure{MathjaxSource}
{}

\Configure{@HEAD}{\endparagraph\HCode{
\detokenize{%
  <script type="text/x-mathjax-config">
  var font = "Neo-Euler";
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [['$','$']],
      displayMath: [['\\[','\\]']],
      processEscapes: true,
    },
    "SVG":{
      font:font
    },
    "HTML-CSS": {
      webFont: font,
      imageFont: font,
      preferredFont: font,
      availableFonts: [],
      scale: 85,
      mtextFontInherit: true
    }
  }); </script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js"></script>
}}}

% helper macro to close the current paragraph
\def\endparagraph{\ifvmode\IgnorePar\fi\EndP}

Note that I had to use a different address for MathJax, as the one you used no longer works. Also note that if you use up-to date TeX4ht, you can use \Configure{MathJaxConfig}:

\Configure{MathJaxConfig}{{ 
\detokenize{
    tex2jax: {
      inlineMath: [['$','$']],
      displayMath: [['\\[','\\]']],
      processEscapes: true,
    },
    "SVG":{
      font:"Neo-Euler"
    },
    "HTML-CSS": {
      webFont: "Neo-Euler",
      imageFont: "Neo-Euler",
      preferredFont: "Neo-Euler",
      availableFonts: [],
      scale: 85,
      mtextFontInherit: true
    }
  } 
}} 

It is available when you use make4ht filename.tex "mathjax" option.

In any case, it seems that the Euler font is not used anyway:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.