역참조 질문: 3,4,5,6,7,8 대신 3-8

역참조 질문: 3,4,5,6,7,8 대신 3-8

아래에서 다음 인용 스타일을 고려하십시오.

여기에 이미지 설명을 입력하세요

위의 내용 대신 ''1, 3-8''로 표시하고 싶습니다. 어떤 제안이 있으십니까? 나는 3과 8이 각각 3과 8 페이지에 연결되기를 원합니다. 실제로 더 이상 4~7페이지로 직접 연결되는 링크가 없습니다.

덧셈:나는 다음을 사용하고 있습니다 :

\usepackage[backref=page]{hyperref}  
\usepackage[sort]{natbib}   
\hypersetup{   
    colorlinks=true,         
    allcolors=blue       
} 

\renewcommand*{\backref}[1]{}  
\renewcommand*{\backrefalt}[4]{\%  
\ifcase #1 (Not cited.)\%  
    \or        \footnotesize (Cited on page~#2.)\%  
    \else      \footnotesize (Cited on pages~#2.)\%  
    \fi  
}

추가(최소 예): https://www.dropbox.com/sh/nvg52ixdt0h7bkb/AACMv8tsM1C0xGdRspJ300zga?dl=0

답변1

당신이 LaTeX 예제를 제공하지 않았고 나는 그러한 예제를 준비하고 싶지 않기 때문에 일반 TeX 수준에서 수행하는 방법을 보여줍니다. 하이퍼링크는 \hyperlinks그것이 가능하다는 것을 보여주기 위해 OpTeX를 사용하여 구현됩니다. 이 예제를 로 처리할 수 있습니다 optex testfile. \cpRLaTeX 방법을 사용하여 하이퍼링크를 생성하도록 매크로를 다시 정의할 수 있습니다 .

\hyperlinks\Blue\Blue
% destinations to previous 30 pages:
\fornum 1..30 \do{\null\label[cp-#1]\wlabel{}\vfil\break} 

% macro \citedpages:
\def\afterfi#1#2\fi{\fi#1}
\newcount\cpnum
\def\citedpages#1{\let\next=\cpA \def\cplist{}\cpnum=-1 \cpA#1,,\end}
\def\cpA#1,{\ifx,#1,\expandafter\cpB \else
   \ifnum#1=\cpnum % do nothing:  3,3 -> 3
   \else \ifnum#1=\numexpr\cpnum+1\relax % 3,4 -> 3-4
         \advance\cpnum by1
   \else \edef\cplist{\cplist -\the\cpnum, #1}% 3,5 -> 3, 5
         \cpnum=#1\relax
   \fi\fi \expandafter\cpA \fi
}
\def\cpB#1\end{\edef\cplist{\cplist-\the\cpnum}%
   \expandafter\cpC\cplist, 0-0,
}
\def\cpC#1-#2, #3-#4, {\ifnum#4=0 and \fi % end game
   \ifnum #2=-1 % starting node, ignored
   \else \ifnum #1=#2 \cpR{#1}\cpD{#4}
         \else \cpR{#1}--\cpR{#2}\cpD{#4}
   \fi\fi 
   \ifnum #4=0 \else \afterfi{\cpC #3-#4, }\fi
}
\def\cpD#1{\ifnum#1=0 \else,\fi}
\def\cpR#1{\pgref[cp-#1]}% OpTeX's hyperlink to the page.

% test:
Cited on pages \citedpages{1,3,4,5,6,7,8,20,21,22,25,27,30}.

\end

처음 세 줄은 OpTeX 전용이고, 다음 줄은 순수 일반 TeX (하이퍼링크 없이) \cpR로 정의될 수 있는 매크로를 제외하고 순수 일반 TeX입니다 .\def\cpR#1{#1}

매크로 \citedpages는 두 단계로 작동합니다. 첫 번째 단계에서는 다음과 같이 읽습니다.

{1,3,4,5,6,7,8,20,21,22,25,27,30}
 

(이 예에서는) 다음 \cplist내용으로 매크로를 생성합니다.

--1, 1-1, 3-8, 20-22, 25-25, 27-27, 30-30

두 번째 단계는 라인에 의해 수행됩니다 \expandafter\cpC\cplist, 0-0,. 원하는 결과가 생성됩니다.

\cpR{1}, \cpR{3}--\cpR{8}, \cpR{20}--\cpR{22}, \cpR{25}, \cpR{27}, and \cpr{30}

편집하다:natbib 및 재정의와 함께 이 매크로를 사용하려는 경우 \backrefalt이 재정의는 다음과 같습니다.

\renewcommand*{\backrefalt}[4]{%
        \ifcase #1 (Not cited.)%
        \or        \footnotesize (Cited   on   {{#2}}.)%
        \else   
               \def\cplist{}\cpnum=-1
               \expandafter\readcplist #2\backrefxxx{0}%
               \footnotesize (Cited on pages~{{\expandafter\cpA\cplist,,\end}}.)%
        \fi
}
\def\readcplist #1\backrefxxx#2{%
    \ifnum#2=0 \else \edef\cplist{\cplist #2,}\expandafter\readcplist\fi}

하지만 이 솔루션은 하이퍼링크 없이 페이지 목록을 추가합니다. 하이퍼링크를 추가하려면 \cpR다음과 같이 정의하십시오.

\def\cpR#1{\backrefxxx{#1}{}{}}% hyperref backref page links.

관련 정보