TransWikia.com

tex4ht does not scale math font along with text when using mathjax

TeX - LaTeX Asked on April 8, 2021

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.

One Answer

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}{ifvmodeIgnoreParfiEndPHCode{<div class="tiny">}par}{ifvmodeIgnoreParfiEndPHCode{</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

Correct answer by michal.h21 on April 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP