使用 mathjax 时,tex4ht 不会随文本缩放数学字体

使用 mathjax 时,tex4ht 不会随文本缩放数学字体

在此 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}

编译为 PDF 时,数学和文本字体大小都会发生变化。

在此处输入图片描述

但是当使用 tex4ht 编译为 HTML 并使用 mathjax 选项时,只有文本大小会改变。数学大小保持正常。

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

给出

在此处输入图片描述

生成的原始 HTML 是

<!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>

这是 tex4ht 问题还是 mathjax 问题?如何让文本和数学同时改变大小,就像编译为 PDF 时的情况一样?

在 Linux 上使用 TL 2020。

答案1

当您使用字体开关(例如)更改字体时\tiny,TeX4ht 会生成<span>包含字体信息的额外元素,例如在这种情况下:

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

这取决于 DVI 文件中的字体信息。在这种情况下,问题是我们没有(也不能)在数学中保留此字体信息,因此您需要稍微更改代码。

我将使用将字体大小更改为的自定义环境\tiny。我们可以配置该环境以生成可使用 CSS 进行样式设置的 HTML 代码。然后它应该可以与 MathJax 配合使用。

以下是更新后的 TeX 文件:

\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}

可以使用以下.cfg文件进行配置:

\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

它生成以下 HTML 代码:

  <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>

在此处输入图片描述

相关内容