![hyperref 包的宏,以便它返回的结果像 1-3,5-7,9,11-12,而不是 1,2,3,5,6,7,9,11,12](https://linux22.com/image/250776/hyperref%20%E5%8C%85%E7%9A%84%E5%AE%8F%EF%BC%8C%E4%BB%A5%E4%BE%BF%E5%AE%83%E8%BF%94%E5%9B%9E%E7%9A%84%E7%BB%93%E6%9E%9C%E5%83%8F%201-3%2C5-7%2C9%2C11-12%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%201%2C2%2C3%2C5%2C6%2C7%2C9%2C11%2C12.png)
我想要请求您就以下问题提供协助: 使用 hyperref 包后,我的参考书目中出现了许多反向引用,如 1,1,1,2,2,3,5,8,9,10,11,11,11,12,12,13,17,19 现在我想编写一个宏将此结果转换为: if Kind = 0 1-3,5,8-13,17,19 if Kind = 1 1,3;2,2;3;5;8;9;10;11,3;12,2;13;17;19 其中 Kind 是一个变量,可根据您的选择采用特定的布局 当我运行文件 PROBEERTEST.TEX 时,上面的例子是正确的,但下面的例子前面有很多“我假设有空格”(我尝试在每一行后添加 % 并删除所有空格,但仍然会出现这些空格)。有人能帮助我吗(我希望 aa 后面立即跟着结果,而不是后面跟着这个空闲的房间)
文件探测器.TEX *
% To turn 1,1,1,2,2,3,5,8,9,10,11,11,11,12,12,13,17,19 into % 1-3,5,8-13,17,19 if Kind = 0 % To turn 1,1,1,2,2,3,5,8,9,10,11,11,11,12,12,13,17,19 into % 1,3;2,2;3;5;8;9;10;11,3;12,2;13;17;19 if Kind = 1 % Based on TeX by Topic p 105 \newcount\Kind % 0: like 1--3,5,7,10--12, % 1: like 1,2;3,2;number,# of number; \newcount\CountP % Previous \newcount\CountN % Next \newcount\CountT % Temp \newcount\CTimes % Number of times \newcount\State % 3: using kind=1 after reading in % first element (state=2) % 2: start, first element printed % 1: during {--}. % 0: otherwise (non-sequential) \CountP=-10000 \CTimes=0 \Kind=0 % --- begin TO STORE THE RESULT \def\ResultDef{} % def to hold the result % USING DEF TO STORE THE RESULT \def\addToResultDef#1{ \edef\ResultDef{\ResultDef #1} } \def\printResultDef{ \ResultDef } % --- end TO STORE THE RESULT \def\Combine#1{\xCombine#1,xxx, \printResultDef \CountP=-10000 \CTimes=0 \def\ResultDef{} } \def\endpiece{xxx} \def\xCombine#1,{\def\temp{#1} \ifx\temp\endpiece \advance \CountN by 3 % to process the last element \Process{\the\CountN} \else \Process{#1} \expandafter \xCombine \fi} \def\Process#1{ \CountN=#1 \ifnum\CountP=-10000 \CountP=\CountN \State=2 \advance \CTimes by 1 %\the\CountP \addToResultDef{\the\CountP} \else \ifnum\CountP=\CountN \advance \CTimes by 1 \else % \CountP<\CountN \ifnum\Kind=0 \ProcessA{#1} \else \ProcessB{#1} \fi \CTimes=1 \CountP=\CountN \fi \fi } \def\ProcessA#1{ % \Kind=0 \CountT=\CountP \advance\CountT by 1 \ifnum\CountN=\CountT \ifnum\State=0 %\the\CountP \addToResultDef{,\the\CountP} \fi \State=1 \else \ifnum\State=0 %, \the\CountP \addToResultDef{,\the\CountP} \else \ifnum\State=1 %{--} \the\CountP \addToResultDef{{--}\the\CountP} \State=0 \else \ifnum\State=2 \State=0 \else \typeout{Invalid State!!} \fi \fi \fi \fi } \def\ProcessB#1{ % \Kind=1 \ifnum\State=2 \ifnum\CTimes=1 \else \addToResultDef{,\the\CTimes} \fi \State=3 \else % State=3 \ifnum\CTimes=1 \addToResultDef{;\the\CountP} \else \addToResultDef{;\the\CountP,\the\CTimes} \fi \fi }
文件 PROBEERTEST.TEX *
%% To test probeer.tex in TeX itself to see if it works accordonly \magnification\magstep1 \hsize 5.5 true in \hoffset 0.5 true in \vsize 8.25 true in \voffset = 2\baselineskip \vbadness11000 \input probeer \noindent 1,1,1,2,3,4,5,6,7,11,12,13,15,17 \hfill \break becomes \hfill \break \Combine{1,1,1,2,3,4,5,6,7,11,12,13,15,17} \hfill \break \hfill \noindent New attempt: \hfill \break 1,2,3,4,5,6,7,11,12,12,13,15,17,17,21,22,23 \hfill \break becomes \hfill \break \Combine{1,2,3,4,5,6,7,11,12,12,13,15,17,17,21,22,23} \hfill \break \hfill \vbox{ \hbox to \hsize{1,2,3,4,5,5,6,7,11,12,13,15,17,21,22,23 \hfill} \hbox to \hsize {becomes \hfill} \hbox to \hsize{aa\Combine{1,2,3,4,5,5,6,7,11,12,13,15,17,21,22,23}bb \hfill} \vfill} \bye
答案1
每个非宏,特别是宏定义内部的宏{
或}
后面跟着换行符的宏都会创建一个空格。
如果你不相信那些人有责任,你可以把
\endlinechar=-1
在文件顶部
\endlinechar=13
在底部恢复到之前的行为。在这种情况下,您必须注意“反向”问题:您有几个数字实际上在该行末尾正确终止,但不再如此。您可以通过编写类似
\ifnum\State=1 %
即使关闭了行末字符,注释符号前的空格仍然可见。
不过我不得不同意 wasteofspace 的评论:这个组合超链接应该指向哪里并不明显。