在 tex4ht 中定制 thebibliography 环境

在 tex4ht 中定制 thebibliography 环境

我正在尝试通过 tex4ht 创建以下 xml 结构

<ref-list>
<title>Bibliography</title>
 <ref id="bib_ch0_001" bibid="aa"><label>[1]</label><mixed-citation publication-type="">Sample Bib text</mixed-citation></ref>
 <ref id="bib_ch0_002" bibid="ab"><label>[2]</label><mixed-citation publication-type="">Sample Bib text</mixed-citation></ref>
 <ref id="bib_ch0_003" bibid="cb"><label>[3]</label><mixed-citation publication-type="">Sample Bib text</mixed-citation></ref>
</reflist>

平均能量损失

\documentclass{book}
\usepackage{Macros}
\begin{document}

\cite{aa}

\begin{thebibliography}{99}
\bibitem{aa}Sample Bib text

\bibitem{ab}Sample Bib text

\bibitem{ac}Sample Bib text
\end{thebibliography}

我已经创建了具有以下结构的 macros.4ht

\newcount\bibcountid
\newcount\bibitemno
\ConfigureList{thebibliography}%
   {\Configure{likechapter}{}{}{}{}%
   \HCode{<ref-list>\Hnewline<title>Bibliography</title>}
   \let\en:bib=\empty}
   {\en:bib
    \Close:UntilEnd
    \HCode{</reflist>}
   }
   {\advance\bibcountid1\en:bib
    \def\en:bib{\HCode{\Hnewline</mixed-citation>\Hnewline</ref>}\let\en:bib=\empty}%
     \HCode{\Hnewline<ref id="bib_ch\thechapter_00\the\bibcountid" bibid="">}%
     \HCode{<label>}%
   }%
   {\HCode{</label><mixed-citation publication-type="">}}
  1. 我同时得到了输出,头部重复如下

<h2 class="likechapterHead">Bibliography</h2>

<ref-list>

<title>Bibliography</title>

  1. 我还需要保留\bibitem{labelid}xmltag 中 的原始标签 id<ref id="bib_ch0_001" bibid="aa">

为此,我刚从 latex.4ht 复制并添加了\def\bibargforht{#2}' in the\@lbibitem`

\def\@lbibitem[#1]#2{{\:SUBOff\:SUPOff\edef\:tempb{{#2}}%
   \pend:def\:tempb{\o:@lbibitem:[#1]}%
   \global\let\:temp\:tempb}%
   \def\bibargforht{#2}\setb:anc{#2}\:temp\bib:anc \let\AnchorLabel\sv:anc\ignorespaces}

当我使用 natbib.sty 时出现编译错误!

如何在书目环境中正确配置这2点?

答案1

您可以尝试以下操作Macros.4ht

\newcount\bibcountid
\newcount\bibitemno
\def\eattwo#1#2{}

\LinkCommand\BibItemLink{ref,href,bibid}

\def\saved:label{\the\value{\@listctr}}

\ConfigureEnv{thebibliography}{
\ifvmode\IgnorePar\fi\EndP%
   \HCode{<reflist>}%
\bgroup%
% Local redefinition for \chapter* configuration
\Configure{likechapter}{}{}{\ifvmode\IgnorePar\fi\EndP\HCode{<title>}}{\HCode{</title>}}%
\Configure{toTocLink}{\eattwo}{}% to remove <a id=""> tag
\let\en:bib=\empty%
}
   {\ifvmode\IgnorePar\fi\EndP%
    \HCode{</reflist>}\egroup%
   }%
{}{}

\ConfigureList{thebibliography}{}{\en:bib\Close:UntilEnd}
   {\advance\bibcountid1\en:bib%
    \def\en:bib{\HCode{\Hnewline</mixed-citation>\Hnewline}\EndBibItemLink\let\en:bib=\empty}%
\DeleteMark}%
   {}

\Configure{bibitem}{\BibItemLink[ id="bib_ch\thechapter_00\the\bibcountid"]}{\HCode{<label>[\saved:label]</label><mixed-citation publication-type="">}}

有几个变化:

  • 为了仅获取一次书目标题,configuration for\chapter*命令在本地重新定义为<title>在 configuration for thebibliographyelement 中打印元素。它也用于插入<reflist>元素。

tex4ht使用链接机制插入<ref>元素:

\LinkCommand\BibItemLink{ref,href,bibid}
 ...
 \ConfigureList{thebibliography}{}{\en:bib\Close:UntilEnd}
   {\advance\bibcountid1\en:bib%
    \def\en:bib{\HCode{\Hnewline</mixed-citation>\Hnewline}\EndBibItemLink \let\en:bib=\empty}%
\DeleteMark}%
   {}
  ...
 \Configure{bibitem}{\BibItemLink[ id="bib_ch\thechapter_00 \the\bibcountid"]}{\HCode{<label>[\saved:label]</label><mixed-citation publication-type="">}}

定义\LinkCommand了两个新命令\BibItemLink\EndBibItemLink。它插入<ref>标签,bibid参数为。我们在需要链接命令的地方id插入。\BibItemLink\Configure{bibitem}

\BibItemLink[ id="bib_ch\thechapter_00\the\bibcountid"]}

这将创建以下<ref>元素:

 <ref 
  bibid="Xaa" id="bib_ch0_001"  >

配置的第二部分bibitem用于插入<label><mixed-citation>

{\HCode{<label>[\saved:label]</label><mixed-citation publication-type="">}}

使用 从列表配置中删除 bibitem 标签\DeleteMark,因为它会破坏我们的xml结构,因此必须在此处手动插入。

我们必须关闭<mixed-citation><ref>在配置中thebibliography

 \ConfigureList{thebibliography}{}{\en:bib\Close:UntilEnd}
   {\advance\bibcountid1\en:bib%
    \def\en:bib{\HCode{\Hnewline</mixed-citation>\Hnewline}\EndBibItemLink \let\en:bib=\empty}%
\DeleteMark}%

我意识到这不是一个真正简单的配置,但如果我们需要遵循严格的XML与 LaTeX 输入结构不同的严格要求,有时我们必须使用一些肮脏的技巧。

结果如下xml

 <reflist>


   <title><a 
 id="x1-1000"></a>Bibliography</title>
    <ref 
  bibid="Xaa" id="bib_ch0_001"  ><label>[1]</label><mixed-citation publication-type="">Sample Bib text

</mixed-citation> 
</ref>
    <ref 
  bibid="Xab" id="bib_ch0_002"  ><label>[2]</label><mixed-citation publication-type="">Sample Bib text

</mixed-citation> 
</ref>
    <ref 
  bibid="Xac" id="bib_ch0_003"  ><label>[3]</label><mixed-citation publication-type="">Sample Bib text 
</mixed-citation> 
</ref>
</reflist>

相关内容