\AtBeginDocument 内容似乎被 htlatex 忽略

\AtBeginDocument 内容似乎被 htlatex 忽略

似乎通过 插入的内容\AtBeginDocument被 忽略了htlatex。除了不使用 之外,还有其他解决方法吗\AtBeginDocument

要重现,请保存下面的 MWE 并运行

htlatex <filename>

两者之间的唯一区别是一个使用\AtBeginDocument{\Dedication}而另一个\Dedication在文档主体中。

\Dedication在主体中使用产生

<!--l. 9--><p class="indent" >   This is dedicated to me as I wrote it!! :-)

   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;1</span><br /><a 
 id="x1-10001"></a>First Chapter</h2> Text for first chapter.  
</body></html> 

而使用\AtBeginDocument{\Dedication}产生

<!--l. 11--><p class="indent" >

   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;1</span><br /><a 
 id="x1-10001"></a>First Chapter</h2> Text for first chapter.  
</body></html> 

请注意,题词文本缺失。

参考


代码:Dedication

\documentclass{book}

\newcommand*{\Dedication}{%
    \clearpage
    This is dedicated to me as I wrote it!! :-)
}

\begin{document}
\Dedication
\chapter{First Chapter}
Text for first chapter.
\end{document}

代码:\AtBeginDocument{\Dedication}

\documentclass{book}

\newcommand*{\Dedication}{%
    \clearpage
    This is dedicated to me as I wrote it!! :-)
}

\AtBeginDocument{\Dedication}%

\begin{document}
\chapter{First Chapter}
Text for first chapter.
\end{document}

答案1

问题是,在 中的文档开头发生了很多事情。这是从文件加载tex4ht补丁并打印标题的时刻。因此,在您的示例中,您的奉献文字会打印在任何 html 标记之前。可能最简单的解决方案是使用命令,它会在所有命令完成后打印内容:.4hthtmletoolbox\AfterEndPreamble\AtBeginDocument

\documentclass{book}

\newcommand*{\Dedication}{%
    \clearpage
    This is dedicated to me as I wrote it!! :-)
}

\usepackage{etoolbox}
%\AtBeginDocument{\Dedication}%
\AfterEndPreamble{\Dedication}
\begin{document}
\chapter{First Chapter}
Text for first chapter.
\end{document}

结果:

<!--l. 11--><p class="indent" >   This is dedicated to me as I wrote it!! :-)

</p>
   <h2 class="chapterHead"><span class="titlemark">Chapter&#x00A0;1</span><br /><a 
 id="x1-10001"></a>First Chapter</h2> Text for first chapter.  
</body></html>

相关内容