我想改变 backref 呈现反向引用列表的方式。
为此,我制作了一个小型 TeX 命令\Combine
,它读入反向引用列表,如 1,1,2,3,56,并将其组合成:1-3, 56
事实证明,在 TeX 中使用时,combine 是有效的,当我将其部分复制到文件中combine.sty
,并在 LaTeX 中使用 usepackage 将该命令带入其中时,它在文档内部有效,但无法使其在 backrefalt 的重新定义中起作用
研究完文件后,backref.sty
我尝试使用以下命令从包内部更改命令
\makeatletter
\let\oldBR@backref=\BR@backref
\renewcommand{\BR@backref}[1]{%
%\Combine{
test\oldBR@backref{#1}test
%}%
}
\makeatother
但这也不起作用 我做错了什么或我遗漏了什么?欢迎任何提示!!
%%%%%%%%%%%%%%%%%%%% BEGIN MAINLATEX.TEX FILE %%%%%%%%%%%%%%%%%%%%%%%
\documentclass[a4paper]{book}
\usepackage{combine} %proberen van commando's in TeX
\newcommand{\tttt}[1]{%
\Combine{#1}
% this doesn't want to work inside the renewcommand from backrefalt!!
}
%\usepackage{hyperref} % to backref any references
% found on local ctan directory
% http://www.ctan.org/tex-archive/macros/latex/contrib/hyperref/
% to include links from my references to the pages where they are cited.
% there has to be an empty line between different bibitems for it to work!!
\usepackage[pagebackref=true]{hyperref}
% if the following two lines are discarded you get links in the pdf file
\hypersetup{ pdfborder={0 0 0},
colorlinks = false}
\renewcommand*{\backrefsep}{,} % inserted between entries except
% for the next cases,
% default is ", ".
\renewcommand*{\backreftwosep}{,} % inserted between entries
% in a list of two entries,
% default is " and~".
\renewcommand*{\backreflastsep}{,} % inserted between the last
% two entries of a list with more
% than two entries, default is ", and~".
\renewcommand*{\backref}[1]{} % for backref < 1.33 necessary
\renewcommand*{\backrefalt}[4]{%
%1. Number of citations without dupes.
%2. Back references list without dupes.
%3. Number of all citations (with dupes).
%4. Back reference list with all entries (with dupes).
#4% Back reference list with all entries (with dupes). works!!
% attempts to combine 1,1,2,2,3,4,6,7 to 1-4,6-7
% but it doesn't work
% Errormessage:
% ! Missing number, treated as zero.
% <to be read again> \protect lines 68
%\tttt{#4}% this doesn't work, gives errors!!
%\Combine{#4}% this doesn't work, gives errors!!
}
\begin{document}
This is the first page with a reference to \cite{lidlapff} and
\cite{lidlapff}
\clearpage
Testing if the command tttt works inside a \LaTeX document
\tttt{1,1,1,2,3,5,7,8,9,10,13,15,17,19,19,19,19,20,21,22,23,25,26}
% to check if this command works inside LaTeX document, it works
This is on the second page \cite{lidlff}
\clearpage
This is on the third page \cite{lidlapff}
\clearpage
On the fourth page there are the refences: \cite{lidlapff} and \cite{lidlff}
\clearpage
\begin{thebibliography}{99}
\bibitem{lidlapff}
Rudolf Lidl and Harald Niederreiter {\it Introduction
to finite fields and their applications}
Cambridge University Press
Revised Edition (1994) ISBN 0-521-46094-8 416p
\bibitem{lidlff}
Rudolf Lidl and Harald Niederreiter {\it Finite Fields}
Cambridge University Press
(1997) ISBN 0-521-06567-4 755p
\end{thebibliography}
\end{document}
%%%%%%%%%%%%%%%%%%%% END MAINLATEX.TEX FILE %%%%%%%%%%%%%%%%%%%%%%%
组合函数在 \TeX 中的编程如下:在 \TeX 中测试时,它运行良好。
%%%%%%%%%%%%%%%%%%%% BEGIN TESTCOMBINE.TEX FILE %%%%%%%%%%%%%%%%%%%%%%%
\magnification\magstep1
\hsize 5.5 true in
\hoffset 0.5 true in
\vsize 8.25 true in
\voffset = 2\baselineskip
\vbadness11000
\parskip\smallskipamount \tolerance1000
\font\narbold=cmb10 %% Bold non-extended
\font\titlefont=cmbx10 scaled \magstep3 %% For heading
\font\smc=cmcsc10 %% For running head
\parindent=0pt
\centerline{\titlefont Trying to make the command combine correct in \TeX??}
\nobreak\bigskip\hrule\bigskip
%%%%%% FROM HERE COPY/PASTE AS STY FILE AND NAME COMBINE.STY %%%%%%%%%%%%
% all that is written in tex, change filename to .sty, delete everything
above and below
% and use package to load in latex
% 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
% TeX by Topic p 105
\global\newcount\CountP%
\global\newcount\CountN%
\global\newcount\CountT%
\global\newcount\CTimes%
\global\newcount\State % 3: using kind=1 after reading in
% first element (state=2)
% 2: start, first element printed
% 1: during {--}.
% 0: otherwise (non-sequential)
% --- begin TO STORE THE RESULT
%\gdef\ResultDef{} % def to hold the result
% USING DEF TO STORE THE RESULT
\def\addToResultDef#1{\xdef\ResultDef{\ResultDef #1}}
% --- end TO STORE THE RESULT
\def\Combine#1{\gdef\ResultDef{}\CountP=-10000\CTimes=0\gdef\yui{#1}%
\ifx\yui\empty There are no entries \else \expandafter\xCombine\yui,xxx, \fi
%
\ResultDef}
\def\endpiece{xxx}
\def\xCombine#1,{\def\temp{#1}%
\ifx\temp\endpiece%
\global\advance \CountN by3% to process the last element
\Process{\the\CountN}%
\else\Process{#1}%
\expandafter\xCombine%
\fi}
\def\Process#1{%
\global\CountN=#1%
\global\ifnum\CountP=-10000%the first element
\global\CountP=\CountN%
\State=2%
\advance\CTimes by1%
\addToResultDef{\the\CountP}%
\else%
\global\ifnum\CountP=\CountN%
\advance\CTimes by1%
%CTimes has as (\the\CountP:\the\CountN) value: \the\CTimes end
\else % \CountP<\CountN
\ProcessA{#1}%
%
\global\CTimes=1%
\global\CountP=\CountN% the next element
%is processed and put in previous
\fi%
\fi%
}
\def\ProcessA#1{ % \Kind=0
\global\CountT=\CountP%
\advance\CountT by1%
\global\ifnum\CountN=\CountT%
\global\ifnum\State=0%
%\the\CountP
\addToResultDef{,\the\CountP}%
\fi%
\State=1%
\else%
\global\ifnum\State=0%
%, \the\CountP
\addToResultDef{,\the\CountP}%
\else%
\global\ifnum\State=1%
%{--} \the\CountP
\addToResultDef{{--}\the\CountP}%
\global\State=0%
\else%
\ifnum\State=2%
\global\State=0%
\else%
\typeout{Invalid State!!}%
\fi%
\fi%
\fi%
\fi%
}
%%%%%% UNTIL HERE COPY/PASTE AS STY FILE AND NAME COMBINE.STY %%%%%%%%%%%%
Combine on empty gives: \Combine{} %
Combine on 11 gives: \Combine{11} %
% probably problems with spaces between numbers! checking if this is the
case!!
% 1,1,1,2,2,2,3,5,7,8,9,10,13,15,17,19,19,19,19,20,21,22,23,25,26 \par
% \vspace{1cm}
Combine on 1, 1, 1, 2, 3, 5, 7, 8, 9, 10, 13, 15, 17, 19, 19, 19, 19, 20,
21, 22, 23, 25, 26 gives:
\Combine{1, 1, 1, 2, 3, 5, 7, 8, 9, 10, 13, 15, 17, 19, 19, 19, 19, 20, 21,
22, 23, 25, 26}%
Combine on 1,1,1,2,3,5,7,8,9,10,13,15,17,19,19,19,19,20,21,22,23,25,26
gives:
\Combine{1,1,1,2,3,5,7,8,9,10,13,15,17,19,19,19,19,20,21,22,23,25,26}
Combine on 1, 1, 2 gives: \Combine{1, 1, 2}%
\bye
%%%%%%%%%%%%%%%%%%%% END TESTCOMBINE.TEX FILE %%%%%%%%%%%%%%%%%%%%%%%