我尝试在 TeX4ht 中使用可选参数创建配置以下环境
\newenvironment{proof}[1][Proof]{\textit{#1}:\ \ignorespaces}
{}
平均能量损失
\documentclass{book}
\newenvironment{proof}[1][]{\def\arg{#1}\ifx\arg\empty\textit{Proof}\else\textit{#1}\fi:\ \ignorespaces}
{}
\begin{document}
\begin{proof}
Sample text
\end{proof}
\begin{proof}[Proof of Theorem~1]
Sample text
\end{proof}
\end{document}
CFG
\ConfigureEnv{proof}
{\ifvmode \IgnorePar\fi \EndP\HCode{<statement>\Hnewline\Hnewline<label>Proof</label>}\IgnoreIndent \ShowPar\par}
{\ifvmode \IgnorePar\fi \EndP\HCode{</statement>}}
{}{}
我在定义中使用可选参数,如果该参数存在,则应在部分中捕获它<label>xxxxxx</label>
,否则应像捕获一样捕获<label>Proof</label>
我得到了错误的输出
<statement>
<label>Proof</label>
<p class="noindent"><italic>Proof </italic>: Sample text</p>
</statement>
<statement>
<label>Proof</label>
<p class="noindent"><italic>Proof of Theorem 1</italic>: Sample text
</p></statement>
Proof' was repeating due to the hard written in the in the
\ConfigureEnv`,
如何在中添加参数\ConfigureEnv
?
或者如何获得如下所示的预期结果
<statement>
<label>Proof</label>
<p class="noindent">Sample text</p>
</statement>
<statement>
<label>Proof of Theorem 1</label>
<p class="noindent">Sample text</p>
</statement>
答案1
我会将校样标签打印部分从环境中移出到独立命令,然后可以将其配置为打印您想要的<label>
:
包裹myproof.sty
\ProvidesPackage{myproof}
\newcommand\printproof[1]{\def\arg{#1}\ifx\arg\empty\textit{Proof}\else\textit{#1}\fi:}
\newenvironment{proof}[1][]{\printproof{#1}\ \ignorespaces}
{}
\endinput
配置文件myproof.4ht
:
\NewConfigure{printproof}{2}
\pend:defI\printproof{\a:printproof}
\append:defI\printproof{\b:printproof}
\ConfigureEnv{proof}
{\ifvmode \IgnorePar\fi \EndP\HCode{<statement>}\IgnoreIndent \ShowPar\par}
{\ifvmode \IgnorePar\fi \EndP\HCode{</statement>}}
{}{}
\Configure{printproof}{\ifvmode\IgnorePar\fi\EndP\HCode{<label>}\NoFonts}{\EndNoFonts\HCode{</label>}\par}
\endinput
首先,使用 定义两个用于插入标签的钩子,然后使用和命令\NewConfigure
将它们插入到命令的开头和结尾。其余的只是标签的配置。...用于抑制元素中的斜体字体。\printproof
\pend:defI
\append:defI
\NoFonts
\EndNoFonts
<label>
结果:
<statement>
<label>Proof :</label>
<!--l. 6--><p class="indent" > Sample text
</p></statement>
<statement>
<label>Proof of Theorem 1:</label>
<!--l. 9--><p class="indent" > Sample text
</p></statement>