这是另一个问题。 这选定答案建议使用zref-xr
,它对于 PDF 输出来说效果很好,但在使用 TeX4ht 时有其局限性:via 的配置\Configure{xr}
显然被忽略了,所以我无法强制使用自定义链接命令来处理外部文档(它使用 JavaScript 来检索正确的文件)。链接文本是正确的,并且不会因使用siunitx
单元命令而出现错误,但如果没有自定义链接命令,超链接将无法按我的预期工作。
有没有办法调整xr-hyper
为不扩展标签内容(如前所述zref-xr
)或保留TeX4htzref-xr
选项\Configure{xr}
?我实际上更喜欢前者,因为更改为zref
可能会在以后产生其他后果...
编辑:这是根据上一个问题中的示例所请求的 MWE:
doc1.tex
\documentclass{book}
\usepackage{lipsum, siunitx}
\iffalse
\usepackage{xr-hyper, hyperref}
\externaldocument[extern__]{doc2}
\else
\usepackage{hyperref, nameref, zref-xr}
\zxrsetup{toltxlabel}
\zexternaldocument*[extern__]{doc2}
\fi
\begin{document}
\chapter{Test \SI{1}{\GeV}}
\label{target}
\lipsum[1]
\nameref{target}
\nameref{extern__target}
\end{document}
doc2.tex
\documentclass{book}
\usepackage{lipsum, siunitx}
\iffalse
\usepackage{xr-hyper, hyperref}
\externaldocument[extern__]{doc1}
\else
\usepackage{hyperref, nameref, zref-xr}
\zxrsetup{toltxlabel}
\zexternaldocument*[extern__]{doc1}
\fi
\begin{document}
\chapter{Test \SI{2}{\GeV}}
\label{target}
\lipsum[1]
\nameref{target}
\nameref{extern__target}
\end{document}
配置文件
\Preamble{html}
% adapted from http://cvr.cc/?p=362
\LinkCommand\ExternalDocumentLink{a,\noexpand\ExternalDocumentJS,name}
\def\ExternalDocumentJS="#1"{href="javascript:window.alert('#1')"}
\Configure{xr}{\ExternalDocumentLink}{\EndExternalDocumentLink}
\begin{document}
\EndPreamble
xr-hyper
使用时\iftrue
,链接本身可以工作,但链接文本是错误的,并且会出现错误。zref-xr
使用\iffalse
时,链接文本是正确的。\Configure{xr}
未被识别为xr-hyper.4ht
未加载 -- 当我将其复制到 时zref-xr.4ht
,错误消失,但结果是一样的:外部文档的文件名未解析,因此链接指向同一文件中的目标。
答案1
似乎对该xr-hyper
软件包的支持已中断。处理外部文档加载的宏会获取错误参数,从而导致编译错误。由于此命令是在文档前言中执行的,因此修补不会在 中发生xr-hyper.4ht
,而是在 中usepackage.4ht
发生。以下是更新后的版本:
% usepackage.4ht (2019-10-09-15:45), generated from tex4ht-4ht.tex
% Copyright 2003-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.
\immediate\write-1{version 2019-10-09-15:45}
\def\:temp{tex4ht}\ifx \:temp\@currname
\:warning{\string\usepackage{tex4ht} again?}
\def\:temp#1htex4ht.def,tex4ht.sty#2!*?: {\def\:temp{#2}}
\expandafter\:temp \@filelist htex4ht.def,tex4ht.sty!*?: %
\ifx \:temp\empty \else
\:warning{if
\string\RequirePackage[tex4ht]{hyperref} or
\string\usepackage[tex4ht]{hyperref} was
used try instead, repectively,
\string\RequirePackage{hyperref} or
\string\usepackage{hyperref}}
\fi
\fi
\gdef\a:usepackage{\use:package xr,xr-hyper,eso-pic,expl3,savetrees,biblatex,xeCJK,polyglossia,fontspec,tikz,pdfbase,graphics,xcolor,imakeidx,minted,fancyhdr,,!*?: }
\gdef\use:package#1,{%
\if :#1:\def\:temp##1!*?: {}\else
\def\:temp{#1}\ifx \@currname\:temp
\def\:temp##1!*?: {\input usepackage.4ht }%
\else \let\:temp=\use:package \fi
\fi \:temp}
\def\:temp{xr}\ifx \@currname\:temp
\AtEndOfPackage{\let\XR:\XR@
\def\XR@[#1]#2{%
\Configure{AtBeginDocument}{\XR:[#1]{#2}}{}}%
}
\fi
\def\:temp{xr-hyper}\ifx \@currname\:temp
\def\eat:optional[#1]{}
\AtEndOfPackage{\let\XR:\XR@
\def\XR@[#1][#2]#3{%
\AtBeginDocument{\XR:[#1][#2]{#3}}
}%
}
\fi
\def\:temp{eso-pic}\ifx \@currname\:temp
\:dontusepackage{eso-pic}
\newcommand\AddToShipoutPicture{\@ifstar{}{}}
\let\AddToShipoutPictureBG\AddToShipoutPicture
\let\AddToShipoutPictureFG\AddToShipoutPicture
\fi
\def\:temp{expl3}\ifx \@currname\:temp
\ifdefined\XeTeXversion%
\xenunidelblock{Latin-expl3}%
\AtEndOfPackage{\xeuniuseblock{Latin-expl3}}
\fi
\fi
\def\:temp{savetrees}\ifx \@currname\:temp
\:dontusepackage{savetrees}
\fi
\def\:temp{biblatex}\ifx \@currname\:temp
\AtEndOfPackage{%
\def\blx@mknoautolang{%
\blx@lbxinput{\blx@languagename}%
{}{}%
}%
\def\blx@lbxinput@iii#1#2{%
\global\csundef{blx@lng@#2}%
\:IfFileExists{#1.lbx}
{\blx@lbxinput@iv{#2}{#1}{language '#2' -> '#1'}}
{\ifcsdef{blx@suffmaptried@#2}
{}
{\blx@warning@noline{%
File '#1.lbx' not found!\MessageBreak
Ignoring mapping '#2' -> '#1'}%
\global\cslet{blx@suffmaptried@#2}\@empty}%
\blx@lbxinput@iv{#2}{#2}{language '#2'}}}
}
\fi
\def\:temp{xeCJK}\ifx \@currname\:temp
\:dontusepackage{xeCJK}
\AtEndOfPackage{%
\RequirePackage{fontspec}
}
\DeclareDocumentCommand\setCJKmainfont{o m o}{}
\let\setCJKsansfont\setCJKmainfont
\let\setCJKmonofont\setCJKmainfont
\DeclareDocumentCommand\setCJKfamilyfont {m o m }{}
\DeclareDocumentCommand\newCJKfontfamily {o m o m}{\expandafter\gdef\csname #2\endcsname{\relax}}
\DeclareDocumentCommand\xeCJKsetup{m}{}
% }
\AtBeginDocument{%
\xeuniuseblock{CJK}
}
\fi
\AtEndOfPackage{
\let\orig@xpg@define@keys\xpg@define@keys
\def\xpg@define@keys#1{%
\orig@xpg@define@keys{#1}%
\define@choicekey+[xpg@setup]{#1}{direction}[\val\nr]{LR,RL}[LR]%
{
\togglefalse{#1@RL}%
\ifcase\nr\relax%
\csgappto{init@extras@#1}{%
a:PolyglossiaRtl%
}
\or
\csgappto{init@extras@#1}{%
\b:PolyglossiaRtl%
}
\fi
}%
{\xpg@warning{#1: Invalid value \val\space for key "direction"}}%
}}
\def\:temp{fontspec}\ifx \@currname\:temp
\ifdefined\fontspec
\:dontusepackage{fontspec}
\else
\input usepackage-fontspec.4ht
\fi
\fi
\def\:temp{tikz}\ifx \@currname\:temp
\AtEndOfPackage{%
\let\use:tikzlibrary\usetikzlibrary
\def\find:externalize#1external#2\@nil{%
\if\relax#2\relax\else
\let\tikz:externalize\tikzexternalize
\renewcommand\tikzexternalize[1][]{\tikz:externalize[##1,mode=only graphics]}
\tikzset{%
tex4ht inc/.style={%
/pgf/images/include external/.code={%
\includegraphics[]{####1.pdf}%
}%
}
}
\tikzset{tex4ht inc}
\fi
}
\renewcommand\usetikzlibrary[1]{%
\use:tikzlibrary{#1}%
\find:externalize#1external\@nil%
}
}
\fi
\def\:temp{pdfbase}\ifx\@currname\:temp
\AtEndOfPackage{%
\let\old:outputpage\@outputpage
\def\@outputpage{\old:outputpage{}}
}
\fi
\def\:temp{graphics}\ifx\@currname\:temp
\ifdefined\XeTeXversion
\PassOptionsToPackage{dvips}{graphics}
\fi
\fi
\def\:temp{xcolor}\ifx\@currname\:temp
\ifdefined\XeTeXversion
\PassOptionsToPackage{dvips}{xcolor}
\fi
\fi
\def\:temp{imakeidx}\ifx\@currname\:temp
\PassOptionsToPackage{noautomatic}{imakeidx}
\fi
\def\:temp{minted}\ifx\@currname\:temp
\AtEndOfPackage{%
\define@booleankey{minted@opt@g}{breaklines}{}{}{}%
}
\fi
\def\:temp{fancyhdr}\ifx\@currname\:temp
\AtEndOfPackage{%
\def\ps@fancy{}%
}
\fi
\endinput
相关代码如下:
\def\:temp{xr-hyper}\ifx \@currname\:temp
\AtEndOfPackage{\let\XR:\XR@
\def\XR@[#1][#2]#3{%
\AtBeginDocument{\XR:[#1][#2]{#3}}
}%
}
基本上,我们需要在文档前言结束后延迟加载外部文档,因为此时 TeX4ht 修补应该已经完成,您不会收到一些未定义的命令序列消息。
下面是单击外部文档的链接时显示的消息框的屏幕截图: