
我正在將大型數學文件從 Latex 轉換為 html + mathml。在某些情況下,我將錯誤的文件形狀作為輸出。示例如下。
主文件測試文件是:
\documentclass{article}
\begin{document}
\[
X \mbox{ is \emph{dense in $Y$}}
\]
\end{document}
簡約的配置myconfig.cfg文件是:
\Preamble{mathml}
\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}}
\begin{document}
\EndPreamble
現在,運行命令htlatex test.tex myconfig.cfg我得到(刪除前導碼並重新組織代碼後):
<body>
<div class="par-math-display"><!--l. 5--><math
xmlns="http://www.w3.org/1998/Math/MathML"
display="block" >
<mrow>
<mi>X</mi>
<mstyle class="mbox">
<!--error--> <mtext> is 
<!--error--> <em>dense in 
<!--error--> </mtext>
<mstyle class="math">
<mi>Y</mi>
</mstyle>
<mtext>
<!--error--> </em>
</mtext></mstyle>
</mrow></math></div>
<!--l. 7--><p class="nopar" >
</body>
在此輸出中,開始和結束標籤多行文字和嗯我強調的是交錯而不是嵌套。
讓我補充一點,修改乳膠程式碼不是一個選項(因為程式碼片段很大)。然而,可能的是重新定義 \emph (但是我嘗試的各種重新定義並沒有改變輸出)。
答案1
編輯:
這是<mtext>
使用格式化指令時實際產生元素的更新配置:
\Preamble{xhtml,mathml,fonts}
\catcode`\:=11
\makeatletter
\newcommand\providemtextclass[1]{%
\Configure{@mtext}{#1}%
\HCode{</mtext>}\ht:special{t4ht@,}\HCode{<mtext \a:@mtext>}\ht:special{t4ht@,&\#x00A0;}%
}
\catcode`\:=12
\makeatother
\begin{document}
\Configure{emph} {\ifmathml\providemtextclass{class="emph" mathvariant="italic" }\else \HCode{<em>}\NoFonts\fi}{\ifmathml\else\EndNoFonts \HCode{</em>}\fi}
\EndPreamble
該\providemtextclass
指令有點複雜。它定義了應在以下<mtext>
元素中使用的屬性。它需要關閉實際打開的<mtext>
.這些\ht:special
命令向 提供特殊指令tex4ht
。用於\ht:special{t4ht@,&\#x00A0;}
將空格替換為牢不可破的空格。這在 MathML 文本中是必要的,否則單字會折疊在一起。但列印標籤時必須停用它,因為它會產生無效的 XML 結構。可以使用 來停用它\ht:special{t4ht@,}
。
渲染結果:
和數學ML:
<math display='block' xmlns='http://www.w3.org/1998/Math/MathML'><mrow>
<mi>X</mi><mstyle class='mbox'><mtext> is </mtext><mtext class='emph' mathvariant='italic'>dense in </mtext><mstyle class='math'><mi>Y</mi> </mstyle><mtext class='emph' mathvariant='italic'></mtext></mstyle>
</mrow></math>
原答案:
命令的配置\emph
需要考慮到在數學中使用時的情況,MathML
否則會無效。
以下是 中提供的配置的修改版本mathml.4ht
:
\Preamble{xhtml,mathml,fonts}
\Configure{emph}
{\ifmathml \Configure{@mtext}{ class="emph"
mathvariant="italic" }%
\else \HCode{<em>}\NoFonts\fi}
{\ifmathml\else\EndNoFonts \HCode{</em>}\fi}
\begin{document}
\EndPreamble
基本文字指令<mtext>
在 MathML 中產生元素,可以使用\Configure{@mtext}
.由於 swich,此配置在數學環境中使用\ifmathml
。在普通文本中,<em>
使用。
這會產生以下結果:
<div class='par-math-display'><!-- l. 4 --><math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><mrow>
<mi>X</mi><mstyle class='mbox'><mtext> is dense in </mtext><mstyle class='math'><mi>Y</mi> </mstyle><mtext class='emph' mathvariant='italic'></mtext></mstyle>
</mrow></math></div>
你可以看到有一個虛假的<mtext class='emph' mathvariant='italic'></mtext>
。這是由包含$Y$
在\emph
命令中引起的。這個版本效果更好:
X \mbox{ is \emph{dense in }$Y$}
關於你的最後一個問題。我們有一個錯誤追蹤器和原始碼儲存庫,位於普什恰。錯誤直接在原始碼中修復,更新直接發送到 TeX 發行版。
TeX.sx 上的大部分問題實際上不是錯誤,而是更多有關根據特定用戶需求修改輸出的問題,因此將它們作為包提供確實沒有意義。如果我們提供一些常見問題和配置的列表,那就太好了,事實上我們還需要更新文件。我開始在...上下功夫,但進展緩慢。對我來說,寫程式比寫散文容易得多,特別是因為我的母語不是英語。我還忙於新的 make4ht 和 tex4ebooks 版本,所以我真的找不到時間來閱讀文件。