1

In this MWE

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\tiny 
All of this font should be tiny include the math
\begin{align*} 
\sin x &= 1
\end{align*} 

\normalsize
All of this font should be normal include the math
\begin{align*} 
\sin x &= 1
\end{align*} 

\end{document}

Both math and text fonts sizes change when compiled to PDF.

enter image description here

But when compiling to HTML using tex4ht and when using mathjax option, only the text size is changed. Math size remains normal.

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

gives

enter image description here

The raw HTML generated is

<!DOCTYPE html> 
<html xml:lang='en-US' lang='en-US'> 
<head><title></title> 
<meta charset='utf-8' /> 
<meta name='generator' content='TeX4ht (https://tug.org/tex4ht/)' /> 
<meta name='viewport' content='width=device-width,initial-scale=1' /> 
<link href='foo5.css' type='text/css' rel='stylesheet' /> 
<meta name='src' content='foo5.tex' /> 
<script>window.MathJax = { tex: { tags: "ams", inlineMath: [ ["\\\(","\\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], processEscapes: true, processEnvironments: true, packages: ['base', 'color', 'ams'] }, loader: { load: ['[tex]/color', '[tex]/ams'] } }; </script> 
 <script async='async' id='MathJax-script' type='text/javascript' src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js'></script>  
</head><body>
<!-- l. 6 --><p class='noindent'><span class='rm-lmr-5'>All of this font should be tiny include the math </span>\begin {align*} \sin x &amp;= 1 \end {align*}
</p><!-- l. 11 --><p class='indent'>   All of this font should be normal include the math \begin {align*} \sin x &amp;= 1 \end {align*}
</p>   
 
</body> 
</html>

Is this tex4ht issue or mathjax? And how to make both text and math change size at same time as the case is when compiling to PDF?

Using TL 2020 on Linux.

2
  • It should be a tex4ht "issue". If you look at your HTML output, the resized text lives inside a span (<span class='rm-lmr-5'>), but the align that immediately follows sits outside the span. So from MathJax's point of view, while the equation should be scaled with the surrounding text, it should be scaled with the font size in the <p>, not that of the <span>. Mar 30, 2021 at 4:51
  • You can try putting in some braces; but I don't know if it will impact tex4ht at all. Mar 30, 2021 at 4:52

1 Answer 1

3

When you change font using font switches like \tiny, TeX4ht produces extra <span> elements that hold the font information, like in this case:

<span class='rm-lmr-5'>All of this font should be tiny include the math </span>\begin {align*} \sin x &amp;= 1 \end {align*}

This depends on the font information in the DVI file. In this case, problem is that we don't (and cannot) keep this font information in math, so you need to change your code slightly.

I would use a custom environment that changes font size to \tiny. We can configure that environment do produce HTML code that can be styled using CSS. It should then work with MathJax.

Here is the updated TeX file:

\documentclass{article}
\usepackage{amsmath}
\newenvironment{mytiny}{\tiny}{}
\begin{document}

\begin{mytiny}
All of this font should be tiny include the math
\begin{align*} 
\sin x &= 1
\end{align*} 
\end{mytiny}

\normalsize
All of this font should be normal include the math
\begin{align*} 
\sin x &= 1
\end{align*} 
\end{document}

It can be configured using the following .cfg file:

\Preamble{xhtml}
\renewenvironment{mytiny}{}{}
\ConfigureEnv{mytiny}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="tiny">}\par}{\ifvmode\IgnorePar\fi\EndP\HCode{</div}}{}{}

\Css{div.tiny{font-size: 0.8em;}}
\begin{document}
\EndPreamble

It produces the following HTML code:

  <div class='tiny'>
<!-- l. 7 --><p class='indent'>   All of this font should be tiny include the math \begin {align*} \sin x &amp;= 1 \end {align*}
</p>
   </div>

enter image description here

You must log in to answer this question.

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