配置 htlatex 以获取 html 中的部分名称

配置 htlatex 以获取 html 中的部分名称

如果使用

htlatex 文件名 "xhtml,svg"

html 文件中的部分名称以

<h3 class="sectionHead">

html 文件中的子部分名称也以以下形式开头

<h4 class="subsectionHead">

是否可以配置 htlatex,以便将以下 html 代码添加到 h3 或 h4 标签之前的节或子节名称的开头?

<div class="content" id="content-x" data-id='x'>

以及章节或小节的末尾

</div>

被添加。这里 x 表示计数器。例如,如果有 8 个部分和 3 个子部分……那么 x 将取 1 到 11 之间的值。计数器不区分部分和子部分。因此,问题在于在生成的 html 文件中为部分/子部分添加编号分区。

答案1

尝试这个配置文件:

\Preamble{xhtml}
\newcounter{sectid}
\def\myendp{\ifvmode\IgnorePar\fi\EndP}
\Configure{section}{\stepcounter{sectid}\myendp\HCode{<div class="content" id="content-\arabic{sectid}" data-id="\arabic{sectid}">}}{\myendp\HCode{</div>}}
   {\myendp\IgnorePar
    \HCode{<h3 class="sectionHead">}\TitleMark\space\HtmlParOff}
   {\HCode{</h3>}\HtmlParOn\ShowPar \IgnoreIndent \par}
\Configure{subsection}{\stepcounter{sectid}\myendp\HCode{<div class="content" id="content-\arabic{sectid}" data-id="\arabic{sectid}">}}{\myendp\HCode{</div>}}
   { \myendp\IgnorePar\HCode{<h3 class="subsectionHead">}\TitleMark\space\HtmlParOff}
   {\HCode{</h3>}\HtmlParOn \IgnoreIndent \ShowPar \par}
\begin{document}
\EndPreamble

部分配置\Configure{sectiontype}需要四个参数,前两个是插入到部分开头和结尾的代码,因此可用于插入元素<div>。下一个参数是插入标题元素以及编号(使用\TitleMark。在最后一个参数中,标题已关闭。有很多宏处理段落\myendpHtmlParOn

自定义计数器用于插入 ID 号,它在每个部分开始时更新:

 \stepcounter{sectid}\myendp\HCode{<div class="content" id="content-\arabic{sectid}" data-id="\arabic{sectid}">}

这是一个示例结果:

 <div class="content" id="content-1" data-id="1"><h3 class="sectionHead"><span class="titlemark">1   </span> <a 
 id="x1-10001"></a>hello</h3>
<!--l. 8--><p class="noindent" >
</p>
   <div class="content" id="content-2" data-id="2"> <h3 class="subsectionHead"><span class="titlemark">1.1   </span> <a 
 id="x1-20001.1"></a>first</h3>
<!--l. 9--><p class="noindent" >Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum
ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem.
Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet
tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra
ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus.
Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur
auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,
accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim
rutrum.
</p><!--l. 10--><p class="noindent" >
</p>
   </div><div class="content" id="content-3" data-id="3"> <h3 class="subsectionHead"><span class="titlemark">1.2   </span> <a 
 id="x1-30001.2"></a>second</h3>
<!--l. 11--><p class="noindent" >Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor
lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et,
tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet
magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis.
Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam
tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus
mauris.
</p><!--l. 12--><p class="noindent" >
</p>
   </div></div><div class="content" id="content-4" data-id="4"><h3 class="sectionHead"><span class="titlemark">2   </span> <a 
 id="x1-40002"></a>world</h3>
<!--l. 13--><p class="noindent" >
</p>

   <div class="content" id="content-5" data-id="5"> <h3 class="subsectionHead"><span class="titlemark">2.1   </span> <a 
 id="x1-50002.1"></a>third</h3>
<!--l. 14--><p class="noindent" >Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt
tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante.
Phasellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis,
molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum
ligula, eleifend at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula
feugiat magna. Nunc eleifend consequat lorem. Sed lacinia nulla vitae enim.
Pellentesque tincidunt purus vel magna. Integer non enim. Praesent euismod nunc
eu purus. Donec bibendum quam in tellus. Nullam cursus pulvinar lectus.
Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis eu
massa.
</p>
   </div></div> 

相关内容