textit 在 mathjax 模式下與 tex4ht 一起使用

textit 在 mathjax 模式下與 tex4ht 一起使用

我正在嘗試編譯由 Maple 產生的 La​​tex 程式碼。產生的 La​​tex 包含類似\textit{\_C1}在 pdf 中正常運作的內容,但是當使用 tex4ht 在 mathjax 模式下編譯為 HTML 時,它不起作用,因為 mathjax 不支援在此巨集內嵌套(參考

MathJax 不處理文字模式下的宏,因為它只處理數學模式宏。因此,在數學模式中嵌入的 \text{} 或 \hbox{} 或其他文字模式材料中,不會執行任何巨集。這是一個功能而不是一個錯誤。 :-)

我嘗試使用\renewcommand重新定義在 HTML/mathjax 中\textit{\_C1}工作{\it \_C1},但無法做到這一點。該命令在 HTML 中沒有改變,它仍然顯示為\textit{\_C1}

這裡是MWE

\documentclass[12pt]{article}
\usepackage{amsmath}

\ifdefined\HCode 
\renewcommand{\textit}[1]{{\it#1}}
\fi 

\begin{document}

\[
y(t) = \textit{\_C1}
\]

  
\[
y (t) = {\it \_C1}
\]
\end{document}

使用 lualatex 編譯為 pdf,兩者給出相同的輸出

在此輸入影像描述

但是編譯成html

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

在此輸入影像描述

產生的 HTML 是

<!DOCTYPE html> 
<html lang="en-US" xml: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 rel="stylesheet" type="text/css" href="foo3.css" /> 
<meta name="src" content="foo3.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 type="text/javascript" async="async" id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js"></script>  
</head><body 
>
<!--l. 12--><p class="noindent" >\[ y(t) = \textit{\_C1} \]
</p><!--l. 17--><p class="indent" >   \[ y (t) ={\it \_C1} \] </p> 
</body> 
</html>

如何糾正我的錯誤\renewcommand,使其\textit{#}更改為{\it #}自動以使 mathjax 滿意? (我無法更改 Maple Latex 程式碼產生程式碼)或者除了使用之外還有更好的方法來解決這個問題嗎\renewcommand?可能需要在 tex4ht 中為 mathjax 的巨集新增配置?

使用 TL 2020

答案1

您的 LaTeX 生成器是否\textit以數學模式產生?我想說這是一個錯誤。應該用它\mathit來代替。\it根本不應該使用,它是一個已棄用的命令。無論如何,由於您的文件是由 MathJax 呈現的,並且它明確表示它不支援內部的數學內容\textit,因此我們無能為力。

這在 MathJaxpdflatex和 MathJax 中都有效:

\documentclass[12pt]{article}
\usepackage{amsmath}

\begin{document}


\[
y(t) = \mathit{\_C1}
\]

  
\[
y (t) = {\it \_C1}
\]
\end{document}

在此輸入影像描述

相關內容