反向引用問題:3-8 而非 3,4,5,6,7,8

反向引用問題:3-8 而非 3,4,5,6,7,8

考慮下面的引用風格:

在此輸入影像描述

我希望將其顯示為“1, and 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 層級上執行此操作。超連結是使用 OpTeX 實現的\hyperlinks,以表明這是可能的。您可以透過 處理此範例optex testfile。您可以重新定義巨集\cpR以使用 LaTeX 方法建立超連結。

\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 特定的,接下來的行是純 Plain TeX,除了可以在純 plain TeX 中\cpR定義的巨集(沒有超連結)。\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

第二步是透過line來完成的\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.

相關內容