我正在使用biblatex
,我想知道是否有办法自动缩写引文中的页码范围。(我问这个问题的原因是因为我的引文都是长格式的,我需要更改大约 200 条引文)。所以我想要的是:
\cite[111-119]{book1}
给我:
Author1, Title1, pp. 111-9
这可能吗biblatex
?
答案1
biblatex
现有答案中多次提到了最近添加的页面范围压缩功能(版本 1.6)。此答案仅提供一些详细信息。
压缩是使用命令进行的。它可以通过\mkcomprange
应用于postnote
和字段。在 postnotes 中,可以处理页面范围列表,前提是它们由逗号和/或分号分隔。pages
\DeclareFieldFormat
\mkcomprange
\mkcomprange
可以使用三种不同的计数器配置行为。默认情况下:
\setcounter{mincomprange}{10}
\setcounter{maxcomprange}{100000}
\setcounter{mincompwidth}{1}
压缩适用于下限大于mincomprange
且位数不超过 的任何范围maxcomprange
。压缩范围内的上限至少使用 中的相同位数显示mincompwidth
。例外情况是压缩上限有前导零;这些零会被抑制。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear,maxcitenames=1]{biblatex}
\DeclareFieldFormat{postnote}{\mkcomprange[{\mkpageprefix[pagination]}]{#1}}
\DeclareFieldFormat{pages}{\mkcomprange{#1}}
% Compress ranges where lower limit > 100
\setcounter{mincomprange}{100}
% Don't compress beyond the fourth digit
\setcounter{maxcomprange}{1000}
% Display compressed upper limit with at least two digits,
% unless leading digit is zero
\setcounter{mincompwidth}{10}
\addbibresource{biblatex-examples.bib}
\begin{document}
\cites{salam}[100--110, 101--109, 101--110]{companion} \\
\cite[100--110; 101--110, esp. last paragraph]{companion} \\
\cite[101-110, 1000--1100, 10000--11000]{companion}
\printbibliography
\end{document}
答案2
这个问题已回答2010 年 3 月,Marco Daniel 在德语论坛 mrunix.de 上发布了此文章。Marco 使用了 xstring 包和一些(在我看来)巧妙的低级 TeX 技巧。在下面的例子中,我使用了 Marco 核心宏的原始代码\mdprintpages
(并标记了两个小改动),但无需更改article
参考书目驱动程序(而是使用\DeclareFieldFormat{pages}{\mdprintpages}
)。
\documentclass{article}
\usepackage{biblatex}
\usepackage{xstring}
% NB: These are much more restrictive than defaults in biblatex.sty
\DeclareRangeChars{-}
\DeclareRangeCommands{\bibrangedash}
\DeclareFieldFormat{pages}{\mkabbrpagerange{#1}}
\DeclareFieldFormat{postnote}{\mkabbrpagerange{#1}}
\newrobustcmd{\mkabbrpagerange}[1]{%
\ifthenelse{\ifpages{#1}\AND\NOT\ifnumeral{#1}}
{\ppno\ppspace\mdprintpages{#1}}
{\mkpageprefix[pagination]{#1}}}
\makeatletter
% START OF ORIGINAL CODE BY MARCO DANIEL
\newif\ifnum@one@empty
\newif\ifnum@two@empty
\def\mdprintpages#1{% EDITED
\StrDel{#1}{ }[\md@tempI]% EDITED
\StrSubstitute{\md@tempI}{\bibrangedash}{,}[\md@tempI]%
\StrSubstitute{\md@tempI}{--}{,}[\md@tempI]% ADDED
\StrSubstitute{\md@tempI}{-}{,}[\md@tempI]% ADDED
\expandafter\expandafter\expandafter\md@printpages\md@tempI,,\@nil}
\def\md@printpages#1,#2,#3\@nil{%
\def\num@one{#1}%
\def\num@two{#2}%
\ifx\@empty\num@one
\num@one@emptytrue
\else
\num@one@emptyfalse
\fi
\ifx\@empty\num@two
\num@two@emptytrue
\else
\num@two@emptyfalse
\fi
\ifnum@two@empty
\ifnum@one@empty
\else
% ,\ \num@one% DELETED BY LOCKSTEP
\num@one% ADDED BY LOCKSTEP
\fi
\else
\StrCompare{\num@one}{\num@two}[\Result]%
% ,\ \num@one\,--\,\StrGobbleLeft{0\num@two}{\Result}% DELETED BY LOCKSTEP
\num@one\,--\,\StrGobbleLeft{0\num@two}{\Result}% ADDED BY LOCKSTEP
\fi
}
\makeatother
% END OF ORIGINAL CODE BY MARCO DANIEL
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Abel1995,
author = {S. Abel and M. D. Nguyen and W. Chow and A. Theologis},
title = {\textit{ACS4}, a primary etc.},
journaltitle = {J Biol Chem},
year = {1995},
volume = {270},
number = {32},
pages = {19093--19099},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
Abbreviated page range: \cite[19093-19097]{Abel1995}
Abbreviated page range: \cite[19093--19097]{Abel1995}
Abbreviated page range: \cite[19093 \bibrangedash 19097]{Abel1995}
Page reference, but not a range: \cite[19093]{Abel1995}
Unabbreviated page range: \cite[19093--20093]{Abel1995}
Not recognized as a page range, so the page prefix must be added manually:
\cite[19093, 19094]{Abel1995}
\cite[19092, 19093--19097]{Abel1995}
\cite[19093--19095, last paragraph]{Abel1995}
\printbibliography
\end{document}
请注意,还有一个功能要求请参阅 SourceForge.net:biblatex 上的缩写页面范围。
编辑 1:仔细一看,这只是一个部分解决方案,因为它只影响参考书目中的页码格式。希望精通低级 TeX 黑客的人能展示如何以同样的方式格式化引文后记。
编辑 2:解决方案现在将页面范围缩写为引文中的后记,但范围仅由 指定-
。因此必须手动将前缀添加到不再被识别为页面范围的页面范围。这是有限制的,但可以避免后记中的其他材料被 省略\mdprintpages
。
编辑 3:SourceForge.net:biblatex 上的功能请求现在待办的并将在 biblatex v1.6 中实现。有关详细信息,请参阅 PLK 对其答案的评论。
编辑 4:包含范围压缩的 biblatex 1.6 于 2011 年 7 月 29 日发布。
答案3
我正在研究在下一版本中通过 biblatex 选项直接在 biber 中实现此功能。对于范围“111-118”,如下所示:
rangeend=auto
会让你
111--8
和
rangeend=2
将得到
111--18
默认为
rangeend=none
111--118
答案4
尝试一下这个:
\listfiles
\setcounter{errorcontextlines}{999}
\documentclass{article}
\usepackage{biblatex}
\usepackage{xstring}
% NB: These are much more restrictive than defaults in biblatex.sty
\DeclareRangeChars{-}
\DeclareRangeCommands{\bibrangedash}
\DeclareFieldFormat{pages}{\mkpageprefix[bookpagination]{#1}}
%\DeclareFieldFormat{postnote}{\mkabbrpagerange{#1}}
\DeclareListParser*{\testdoranges}{,}
\long\def\mdprintpages#1{%
\ifboolexpr{ test {\ifnumeral{#1}} or test {\ifnumerals{#1}}}%
{\mkpageprefix[pagination]{#1}}%
{\printtext{#1}}%
\setunit{\addcomma\space}%
}
\DeclareFieldFormat{postnote}{%
\testdoranges{\mdprintpages}{#1}%
}
\makeatletter
\long\def\blx@mkpageprefix@i[#1]#2{#1{\md@printpages{#2}}\endgroup}
% START OF ORIGINAL CODE BY MARCO DANIEL
\newif\ifnum@one@empty
\newif\ifnum@two@empty
\def\md@printpages#1{% EDITED
\StrDel{#1}{ }[\md@tempI]% EDITED
\StrSubstitute{\md@tempI}{\bibrangedash}{,}[\md@tempI]%
\StrSubstitute{\md@tempI}{--}{,}[\md@tempI]% ADDED
\StrSubstitute{\md@tempI}{-}{,}[\md@tempI]% ADDED
\expandafter\expandafter\expandafter\md@@printpages\md@tempI,,\@nil}
\def\md@@printpages#1,#2,#3\@nil{%
\def\num@one{#1}%
\def\num@two{#2}%
\ifx\@empty\num@one
\num@one@emptytrue
\else
\num@one@emptyfalse
\fi
\ifx\@empty\num@two
\num@two@emptytrue
\else
\num@two@emptyfalse
\fi
\ifnum@two@empty
\ifnum@one@empty
\else
% ,\ \num@one% DELETED BY LOCKSTEP
\num@one% ADDED BY LOCKSTEP
\fi
\else
\StrCompare{\num@one}{\num@two}[\Result]%
% ,\ \num@one\,--\,\StrGobbleLeft{0\num@two}{\Result}% DELETED BY LOCKSTEP
\num@one\,--\,\StrGobbleLeft{0\num@two}{\Result}% ADDED BY LOCKSTEP
\fi
}
\makeatother
% END OF ORIGINAL CODE BY MARCO DANIEL
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Abel1995,
author = {S. Abel and M. D. Nguyen and W. Chow and A. Theologis},
title = {\textit{ACS4}, a primary etc.},
journaltitle = {J Biol Chem},
year = {1995},
volume = {270},
number = {32},
pages = {19093--19099},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
Abbreviated page range: \cite[19093-19097]{Abel1995}
Abbreviated page range: \cite[19093--19097]{Abel1995}
Abbreviated page range: \cite[19093 \bibrangedash 19097]{Abel1995}
Page reference, but not a range: \cite[19093]{Abel1995}
Unabbreviated page range: \cite[19093--20093]{Abel1995}
Not recognized as a page range, so the page prefix must be added manually:
\cite[19093, 19094]{Abel1995}
\cite[19092, 19093--19097]{Abel1995}
\cite[19093--19095, last paragraph]{Abel1995}
\cite[first paragraph, 19093--19095]{Abel1995}
\cite[first paragraph, 19093--19095, 19092, 19093--19097 ]{Abel1995}
\printbibliography
\end{document}