1

I would like to change the way that backref presents the list of backreferences.

To do so I made a small TeX command \Combine that reads in a list of backreferences like 1,1,2,3,56 and combines it into: 1-3, 56

It turns out that combine works when used in TeX and when I copy the part of it to a file combine.sty and use usepackage in LaTeX to bring that commands in it, it works inside the document but it doesn't work to make it work inside the redefinition of backrefalt

After studying the backref.sty file I tried changing the commands from inside the package itself with

\makeatletter
\let\oldBR@backref=\BR@backref
\renewcommand{\BR@backref}[1]{%
%\Combine{
test\oldBR@backref{#1}test
%}% 
}
\makeatother

but that doesn't work either What have I done wrong or am I missing here?? Any hints are welcome!!

%%%%%%%%%%%%%%%%%%%% 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 %%%%%%%%%%%%%%%%%%%%%%%

The combine function is programmed in \TeX as follows: When tested in \TeX it works fine.

%%%%%%%%%%%%%%%%%%%% 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 %%%%%%%%%%%%%%%%%%%%%%%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.