如何防止 make4ht 在摘要中创建不必要的跨度兄弟标签?

如何防止 make4ht 在摘要中创建不必要的跨度兄弟标签?

make4ht正在抽象中创建不必要的 span 同级标签。以下示例显示了此行为:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\begin{document}
\begin{abstract}
\lipsum[1-1]
\end{abstract}
\lipsum[1-1]
\end{document}

生成的 HTML 内容如下:

<!DOCTYPE html> 
<html xml:lang='en-US' lang='en-US'> 
<head> <title></title> 
<meta charset='utf-8' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' /> 
<meta content='width=device-width,initial-scale=1' name='viewport' /> 
<link type='text/css' rel='stylesheet' href='test.css' /> 
<meta content='test.tex' name='src' /> 
</head><body>
   <section role='doc-abstract' class='abstract'> 

<div class='center'>
<!-- l. 10 --><p class='noindent'>
</p><!-- l. 10 --><p class='noindent'><span class='rm-lmbx-9'>Abstract</span></p></div>
     <!-- l. 13 --><p class='indent'>    <span class='rm-lmr-9'>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
     </span><span class='rm-lmr-9'>elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum
     </span><span class='rm-lmr-9'>gravida  mauris.  Nam  arcu  libero,  nonummy  eget,  consectetuer  id,
     </span><span class='rm-lmr-9'>vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant
     </span><span class='rm-lmr-9'>morbi tristique senectus et netus et malesuada fames ac turpis egestas.
     </span><span class='rm-lmr-9'>Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum
     </span><span class='rm-lmr-9'>urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat.
     </span><span class='rm-lmr-9'>Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent
     </span><span class='rm-lmr-9'>eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla,
     </span><span class='rm-lmr-9'>malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla.
     </span><span class='rm-lmr-9'>Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend,
     </span><span class='rm-lmr-9'>sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.</span>
</p>
</section>
<!-- l. 17 --><p class='indent'>   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> 
</body> 
</html>

有没有什么办法可以防止这种行为?遗憾的是,HTMLTidy没有同级标签的合并选项。

答案1

这是因为我们在摘要中保留了原始字体。由于 LaTeX 使用较小的字体,因此 TeX4ht 会添加<span>带有大小信息的元素。为了防止这种情况,我们需要请求正常大小的字体。我们可以在摘要标题后插入此指令:

\Preamble{xhtml}
\ConfigureEnv{abstract}
{\ifvmode\IgnorePar\fi\EndP\HCode{<section role="doc-abstract" class="abstract">\Hnewline}
\ConfigureEnv{center}{\ifvmode\IgnorePar\fi\EndP\HCode{<h3 class="abstracttitle">}\HtmlParOff}{\HCode{</h3>}\HtmlParOn\par\normalsize\normalfont}{\empty}{\empty}
} 
{\ifvmode\IgnorePar\fi\EndP\HCode{</section>}}{}{}
\Css{.abstract{font-size:0.9rem;margin-bottom:1em;}}
\Css{.abstracttitle{text-align:center;}}

\begin{document}
\EndPreamble

\ConfigureEnv{center}之所以使用是因为 abstractcenter在内部使用环境来打印摘要标题。我们使用它来插入元素<h3>并使用 来要求正常大小的字体\normalsize

结果如下:

 <section class='abstract' role='doc-abstract'> 
<h3 class='abstracttitle'>
<span class='cmbx-9'>Abstract</span>
</h3>
     <!-- l. 7 --><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>
</section>

原始答案:

\Preamble{xhtml}
\Configure{abstracttitle}{\ifvmode\IgnorePar\fi\EndP\HCode{<h3 class="abstracttitle">}\HtmlParOff}
   {\HCode{</h3>}\HtmlParOn\normalsize}
\Css{.abstract{font-size:0.9rem;}}

\begin{document}
\EndPreamble

\Configure{abstracttitle}是从 TeX4ht 源改编的。我刚刚添加了\normalsize命令。\Css用于获取较小的文本。

相关内容