我尝试重新配置 \Link、\ref、\cite 以获得以下输出
链接 --><target targetid="x1-10001"></target>
參考 --><xref ref-type="Sec" rid="x1-10001">1</xref>
引用 --><xref ref-type="bibr" rid="Xbib1">1</xref>
我配置如下.cfg
\Configure{Link}{xref}{LinkID=}{targetid=}{\empty}
\Configure{ref}
{\Configure{Link}{xref}{ref-type="\RefArg" rid=}{}{}\Link}
{\ifx \RefArg\:UnDef\else\fi\EndLink%
\Configure{Link}{xref}{LinkID=}{Targetid=}{\empty}}
{}
\Configure{cite}{}{}
{\Configure{Link}{xref}{ref-type="bibr" rid=}{id=}{\empty}%
\Link}
{\EndLink}
我得到如下输出
<sec sec-type="section" id="sample_s_001">
<label>1</label>
<title><target targetid="x1-10001"></target>
Sample Section head</title>
对于 \ref 我得到的输出
<p class="noindent">Macro <xref ref-type="Sec1" rid="x1-10001">1</xref>
language has evolved gradually: as the need arose for actions beyond
对于 \cite 我得到了错误的输出
[<target LinkID="Xbib1">1</target>]
如何配置这些以实现预期的输出?
梅威瑟:
\documentclass{article}
\usepackage{times}
\usepackage{graphicx}
\usepackage[numbers]{natbib}
\title{TeX4HT Try}
\begin{document}
\maketitle
\section{Sample Section head}\label{Sec1}
Macro~\ref{Sec1} language has evolved gradually: as the need arose for actions beyond a predefined set of commands. As a consequence, it is a pretty non-standard language that implements loops and conditional statements with macro functions rather than keywords.
Sophisticated macro scripts involving loops and conditional statements are, admittedly, hard to write and read, and it may take some time to become familiar with it \cite{bib1}.
\begin{thebibliography}{}
\bibitem{bib1} text
\bibitem{bib2} text
\end{thebibliography}
答案1
似乎 Natbib 包的配置没有考虑到该\Configure{cite}
命令。我刚刚添加了对该命令的支持。您可以使用以下修补natbib.4ht
文件,直到将支持添加到 TL:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% natbib.4ht 2019-07-26-22:42 %
% Copyright (C) 1999-2009 Eitan M. Gurari %
% Copyright 2009-2019 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\HRestore\@lbibitem
\HRestore\@bibitem
\ifNAT@super
\def\citet{\@ifstar{\NAT@longnamestrue\ht@citet}%
{\NAT@longnamesfalse\ht@citet}}
\def\setb:anc#1{\let\sv:anc\AnchorLabel
\def\bib:anc{\Link{}{bibitem\the
\c@NAT@ctr}\EndLink \gdef\bib:anc{}}%
\def\AnchorLabel{\bib:anc}}
\def\nb:link#1{\Protect\Link{bibitem#1}{}#1\Protect\EndLink}
\def\nb@link#1{\Protect\Link{bibitem#1}{}#1\Protect\EndLink}
\let\nat:lbibitem\@lbibitem
\def\@lbibitem{%
\ifx\hyper@natanchorstart\@gobble
\def\hyper@natanchorstart##1{\Link{}{bibitem\the
\c@NAT@ctr}\EndLink}\fi
\nat:lbibitem
}
\catcode`\:12
\def\ht@citet#1{\def\NAT@num{-1}\let\NAT@last@yr\relax\let\NAT@nm\@empty
\let\@citea\@empty
\@for\@citeb:=#1\do{%
\@ifundefined{b@\@citeb\@extra@b@citeb}%
{{\reset@font\bfseries?}\NAT@citeundefined\PackageWarning{natbib}%
{Citation `\@citeb' on page \thepage \space undefined}%
}%
{\@citea\let\NAT@last@num\NAT@num\let\NAT@last@nm\NAT@nm
\NAT@parse{\@citeb}%
\ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
\let\NAT@name=\NAT@all@names
\global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
\fi
\ifNAT@full\let\NAT@nm\NAT@all@names\else
\let\NAT@nm\NAT@name
\fi
\NAT@nm}\Tg<sup>\nb@link{\NAT@num}\Tg</sup>
\def\@citea{\unskip\NAT@sep\penalty\@m\space}%
}%
}
\def\NAT@citexnum[#1][#2]#3{%
\NAT@sort@cites{#3}%
\let\@citea\@empty
\@cite{\def\NAT@num{-1}\let\NAT@last@yr\relax\let\NAT@nm\@empty
\@for\@citeb:=\NAT@cite@list\do
{\edef\@citeb{\expandafter\@firstofone\@citeb}%
\if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
\@ifundefined{b@\@citeb\@extra@b@citeb}{%
{\reset@font\bfseries?}
\NAT@citeundefined\PackageWarning{natbib}%
{Citation `\@citeb' on page \thepage \space undefined}}%
{\let\NAT@last@num\NAT@num\let\NAT@last@nm\NAT@nm
\NAT@parse{\@citeb}%
\ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
\let\NAT@name=\NAT@all@names
\global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
\fi
\ifNAT@full\let\NAT@nm\NAT@all@names\else
\let\NAT@nm\NAT@name\fi
\ifNAT@swa
\ifnum\NAT@ctype=2\relax\@citea
\hyper@natlinkstart{\@citeb\@extra@b@citeb}%
\NAT@test{2}\hyper@natlinkend\else
\ifnum\NAT@sort>1
\begingroup\catcode`\_8
\ifcat _\ifnum\z@<0\NAT@num _\else A\fi
\global\let\NAT@nm=\NAT@num \else \gdef\NAT@nm{-2}\fi
\ifcat _\ifnum\z@<0\NAT@last@num _\else A\fi
\global\@tempcnta\NAT@last@num
\global\advance\@tempcnta \@ne
\else \global\@tempcnta\m@ne\fi
\endgroup
\ifnum\NAT@nm=\@tempcnta
\ifx\NAT@last@yr\relax
\edef\NAT@last@yr{\@citea
\csname o:mbox:\endcsname{\csname nb:link\endcsname
\NAT@num}}%
\else
\edef\NAT@last@yr{--\penalty
\@m\csname o:mbox:\endcsname{\csname nb:link\endcsname
\NAT@num}}%
\fi
\else
\NAT@last@yr \@citea \csname o:mbox:\endcsname{\csname nb:link\endcsname
\NAT@num}%
\let\NAT@last@yr\relax
\fi
\else
\@citea \csname o:mbox:\endcsname
{\ifx\hyper@natanchorstart\@gobble
\Link{bibitem\NAT@num}{}\NAT@num
\EndLink
\else
\hyper@natlinkstart{\@citeb\@extra@b@citeb}\NAT@num
\hyper@natlinkend
\fi
}%
\fi
\fi
\def\@citea{\NAT@sep\penalty\@m\NAT@space}%
\else
\ifcase\NAT@ctype\relax
\ifx\NAT@last@nm\NAT@nm \NAT@yrsep\penalty\@m\NAT@space\else
\@citea \NAT@test{1}\ \NAT@@open
\if\relax#1\relax\else#1\ \fi\fi \NAT@mbox{%
\hyper@natlinkstart{\@citeb\@extra@b@citeb}%
\NAT@num\hyper@natlinkend}%
\def\@citea{\NAT@@close\NAT@sep\penalty\@m\ }%
\or\@citea
\hyper@natlinkstart{\@citeb\@extra@b@citeb}%
\NAT@test{1}\hyper@natlinkend
\def\@citea{\NAT@sep\penalty\@m\ }%
\or\@citea
\hyper@natlinkstart{\@citeb\@extra@b@citeb}\NAT@test{2}%
\hyper@natlinkend
\def\@citea{\NAT@sep\penalty\@m\ }%
\fi
\fi
}}%
\ifnum\NAT@sort>1\NAT@last@yr\fi
\ifNAT@swa\else\ifnum\NAT@ctype=0\if\relax#2\relax\else
\NAT@cmt\ #2\fi \NAT@@close\fi\fi}{#1}{#2}}
\let\@citex\NAT@citexnum
\catcode`\:11
\else
\def\hyper@natlinkstart#1{%
\let\rel:hyper\def \hyper@linkstart{cite}{X#1}%
\def\hyper@nat@current{#1}%
}
\def\hyper@natlinkbreak#1#2{%
\hyper@linkend#1\let\rel:hyper\def \hyper@linkstart{cite}{X#2}%
}
\def\hyper@natlinkend{\hyper@linkend}
\expandafter\ifx \csname hyper@linkstart\endcsname\relax
\def\hyper@linkstart#1#2{%
\a:cite%
\def\:temp{#1}%
\ifx\:temp\@urltype
\cIteLink[#2]{}{}%
\else
\ifx\rel:hyper\def\cIteLink{#2}{}\else\cIteLink[\##2]{}{}\fi
\fi \global\let\rel:hyper=\:UnDef
}
\def\hyper@linkend{\EndcIteLink\b:cite}
\fi
\long\def\:temp#1{}\ifx \:temp\hyper@natanchorstart
\def\hyper@natanchorstart#1{\Link{}{X#1}\EndLink}
\fi
\pend:defIII\NAT@cite{\let\mbox\o:mbox:}
\pend:defIII\NAT@citenum{\let\mbox\o:mbox:}
\fi
\Hinput{natbib}
\endinput
重要的变化是这样的:
\def\hyper@linkstart#1#2{%
\a:cite%
\def\:temp{#1}%
\ifx\:temp\@urltype
\cIteLink[#2]{}{}%
\else
\ifx\rel:hyper\def\cIteLink{#2}{}\else\cIteLink[\##2]{}{}\fi
\fi \global\let\rel:hyper=\:UnDef
}
\def\hyper@linkend{\EndcIteLink\b:cite}
和\a:cite
命令\b:cite
在各个引用周围添加标签,\cIteLink
是一个自定义链接命令,需要正确配置:
\LinkCommand\Xreflink{xref,id,rid,ref-type="bibr"}
\Configure{cite}{}{}
{\Xreflink}{\EndXreflink}
第四个参数中使用的链接命令\Configure{cite}
必须使用命令定义\LinkCommand
。它采用以逗号分隔的参数:
\LinkCommand...................1 <= i <= 6
Creates a \Link-like command
#1 tag name
#2 href-like attribute
#3 name-like attribute
#4 insertion
#5 /, if empty element
#6 replacement for # (ignored if absent)
Example:
\LinkCommand\JSLink{a,\noexpand\jsref,name}
\def\jsref="#1"{href="javascript:window.open('#1')"}
\JSLink{a}{}xx\EndJSLink
\Link{}{a}\EndLink % or \JSLink{}{a}\EndJSLink
结果如下:
<p class="indent" > Sophisticated macro scripts involving loops and conditional statements are,
admittedly, hard to write and read, and it may take some time to become familiar with it
[<xref
id="Xbib1" ref-type="bibr" >1</xref>].
</p>