我正在使用natbib
带有 [authoryear,compress] 选项和 bibliographystyle 的 bibtex 包apalike
。是否可以修改natbib
包选项,以便文内引用按照出版年份排序?
这里已经有人问过同样的问题: 文本中按年份引用,采用类似阿帕拉契书目格式
不过,如果您的命令中的 bibtex-keys\citep{}
已经按正确的顺序排列(您只需避免该sort&compress
选项),则可接受的答案只是一种解决方法。但是,如果您希望它们根据出版年份自动排序(而不在命令中手动提供正确的排序)\citep{}
,则此答案无法解决问题。
有解决办法吗?这里的答案(最后一段)听起来有点不可能(?): https://tex.stackexchange.com/a/62411/112395
举一个实际的例子:
\documentclass[12pt,a4paper,hidelinks]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[authoryear,compress]{natbib} %Calls bibliography commands + Cite with author-year style (Harvard) instead of the numeric style. Let's just use compress instead of sort&compress: Note, however, that this means that the ordering of the in-text references follows the order you specified in the text (i. e., no automatical sorting is carried out!)
\begin{document}
%
\section*{References}
\label{sec:References}
\citep{Owen1876,
Berman1977,
Berman1987,
Berman1992,
Berman1993,
Berman1993_Seymouria,
Berman2003_Aspidosaurus,
Berman2004,
Berman2010_Fedexia,
Berman2011_Rotaryus,
Berman2014,
Berman2015}
\citep{Berman1977,
Berman1987,
Berman1992,
Berman1993,
Berman1993_Seymouria,
Berman2003_Aspidosaurus,
Berman2004,
Berman2010_Fedexia,
Berman2011_Rotaryus,
Berman2014,
Berman2015,
Owen1876}
\bibliographystyle{apalike}
\bibliography{myrefs}
\end{document}
使用以下 myref.bib 文件:
@Book{Owen1876,
title = {{Descriptive and illustrated catalogue of the Fossil Reptilia of South Africa in the collection of the British Museum}},
publisher = {British Museum (Natural History)},
year = {1876},
author = {Richard Owen},
address = {London, United Kingdom},
note = {88 pp.},
url = {http://gallica.bnf.fr/ark:/12148/bpt6k987042},
}
@Article{Berman1977,
author = {Berman, David S},
title = {{A new species of \textit{Dimetrodon} (Reptilia, Pelycosauria) from a non-deltaic facies in the Lower Permian of north-central New Mexico}},
journal = {Journal of Paleontology},
year = {1977},
volume = {51},
number = {1},
pages = {108--115},
}
@Article{Berman1987,
author = {David S. Berman and Robert R. Reisz and David A. Eberth},
title = {{\textit{Seymouria sanjuanensis} (Amphibia, Batrachosauria) from the Lower Permian Cutler Formation of north-central New {Mexico} and the occurrence of sexual dimorphism in that genus questioned}},
journal = {Canadian Journal of Earth Sciences},
year = {1987},
volume = {24},
number = {9},
pages = {1769--1784},
}
@Article{Berman1992,
author = {David S. Berman and Stuart S. Sumida and R. Eric Lombard},
title = {{Reinterpretation of the temporal and occipital regions in \textit{Diadectes} and the relationships of diadectomorphs}},
journal = {Journal of Paleontology},
year = {1992},
volume = {66},
number = {3},
pages = {481--499},
}
@InCollection{Berman1993,
author = {Berman, D. S.},
title = {{Lower Permian vertebrate localities of New Mexico and their assemblages}},
booktitle = {{Vertebrate Paleontology in New Mexico}},
publisher = {New Mexico Museum of Natural History},
year = {1993},
editor = {Spencer G. Lucas AND Jiri Zidek},
volume = {2},
pages = {11--21},
}
@Article{Berman1993_Seymouria,
author = {Berman, David S. and Martens, Thomas},
title = {{First occurrence of \textit{Seymouria} (Amphibia: Batrachosauria) in the Lower Permian Rotliegend of central Germany}},
journal = {Annals of Carnegie Museum},
year = {1993},
volume = {62},
number = {1},
pages = {63--79},
}
@Article{Berman2003_Aspidosaurus,
author = {Berman, David S. and Lucas, Spencer G.},
title = {{\textit{Aspidosaurus binasser} (Amphibia, Temnospondyli), a new species of Dissorophidae from the Lower Permian of Texas}},
journal = {Annals of Carnegie Museum},
year = {2003},
volume = {72},
number = {4},
pages = {241--262},
}
@Article{Berman2004,
author = {Berman, David S and Henrici, Amy C and Sumida, Stuart S and Martens, Thomas},
title = {{New materials of \textit{Dimetrodon teutonis} (Synapsida: Sphenacodontidae) from the Lower Permian of Germany}},
journal = {Annals of Carnegie Museum},
year = {2004},
volume = {73},
number = {2},
pages = {48--56},
}
@Article{Berman2010_Fedexia,
author = {David S Berman and Amy C. Henrici and David K. Brezinski and Albert D. Kollar},
title = {{A new trematopid amphibian (Temnospondyli: Dissorophoidea) from the Upper Pennsylvanian of Western Pennsylvania: earliest record of terrestrial vertebrates responding to a warmer, drier climate}},
journal = {Annals of Carnegie Museum},
year = {2010},
volume = {78},
number = {4},
pages = {289--318},
}
@Article{Berman2011_Rotaryus,
author = {David S Berman and Amy C. Henrici and Thomas Martens and Stuart S. Sumida and Jason S. Anderson},
title = {{\textit{Rotaryus gothae}, a new trematopid (Temnospondyli: Dissorophoidea) from the Lower Permian of central {Germany}}},
journal = {Annals of Carnegie Museum},
year = {2011},
volume = {80},
number = {1},
pages = {49--65},
}
@InCollection{Berman2014,
author = {Berman, David S and Henrici, Amy C. and Sumida, Stuart S. and Martens, Thomas and Pelletier, Valerie},
title = {{First European Record of a Varanodontine (Synapsida: Varanopidae): Member of a Unique Early Permian Upland Paleoecosystem, Tambach Basin, Central Germany}},
booktitle = {{Early Evolutionary History of the Synapsida}},
publisher = {Springer},
year = {2014},
editor = {Kammerer, Christian F. and Angielczyk, Kenneth D. and Fr{\"o}bisch, J{\"o}rg},
series = {Vertebrate Paleobiology and Paleoanthropology},
chapter = {5},
pages = {69--86},
address = {Dordrecht},
}
@InCollection{Berman2015,
author = {David S. Berman AND Amy C. Henrici AND Spencer G. Lucas},
title = {{Pennsylvanian-Permian Red Bed vertebrate localities of New Mexico an their assemblages}},
booktitle = {{Fossil Vertebrates in New Mexico}},
publisher = {New Mexico Museum of Natural History},
year = {2015},
editor = {Lucas, S. G. AND Sullivan, R. M.},
volume = {68},
pages = {65--76},
}
如您所见,在第二个引文中,参考文献不是按时间顺序排列的:1876 年的参考文献排在最后,而不是排在最前面。有没有办法改变这种情况(而不必手动执行所有命令\cite
)?
我更希望看到使用 bibtex 而不是 biblatex 的解决方案。
答案1
据我所知,natbib
选项sort
按参考书目中的顺序排序。因此自动排序只能为您提供参考书目中的顺序。
这是一个概念证明,它试图对引文进行与参考书目不同的排序。
它的工作原理如下:.bst
文件像往常一样生成参考书目。但随后它会按照所需的引用顺序再次对所有条目进行排序,并将顺序信息写入文件.bbl
。读取此顺序信息,将其写入.aux
,最终生成按所需引用顺序排列的所有条目键的排序列表。
然后,我们修改命令的内部定义\cite
,以便使用排序键列表对所有条目进行排序。这或多或少就是biblatex
对引用进行排序的方式。
因此,您需要修改.bst
文件。apalike.bst
如示例中所示,只需添加
FUNCTION {sort.again}
{
year field.or.null sortify
" "
*
sort.label
*
'sort.key$ :=
}
ITERATE {sort.again}
SORT
EXECUTE {newline$}
FUNCTION {produce.sortlist}
{
"\sortentry{"
cite$
*
"}"
*
write$
newline$
}
ITERATE {produce.sortlist}
在文件末尾获取排序信息。YMMV 具有不同的样式。假设新样式称为apalike-citesort.bst
。您可以从下载https://gist.github.com/moewew/22e70d3c0c6df24859bf949a44bffb62。
MWE 显示了 cite 宏的必要重新定义。我感觉natbib
使用新的引用列表应该更简单,但最终我不得不使用一条不太漂亮的路线。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[authoryear]{natbib}
\usepackage{etoolbox}
\makeatletter
\newcommand*{\sortentry}[1]{%
\if@filesw
\immediate\write\@auxout{\string\uNAT@aux@sortentry{#1}}%
\fi}
\newcommand*{\uNAT@aux@sortentry}{%
\listgadd{\uNAT@bibsortlist}}
\newcommand*{\uNAT@bibsortlist}{}
\newcommand*{\uNAT@citekeys}{}
\newcommand*{\uNAT@writetocitelistsort}[1]{%
\ifinlist{#1}{\uNAT@citekeys}
{\ifdefvoid{\NAT@cite@list}
{\def\NAT@cite@list{#1}}
{\expandafter\def\expandafter\NAT@cite@list\expandafter{\NAT@cite@list,#1}}%
\listgadd{\uNAT@foundkeys}{#1}}
{}}
% Let's be paranoid: we might have dropped an item that
% has not made it to the bibliography yet
\newcommand*{\uNAT@writetocitelistforgotten}[1]{%
\ifinlist{#1}{\uNAT@foundkeys}
{}
{\ifdefvoid{\NAT@cite@list}
{\def\NAT@cite@list{#1}}
{\expandafter\def\expandafter\NAT@cite@list\expandafter{\NAT@cite@list,#1}}}}
\newcommand*{\uNAT@sortcites}[1]{%
\let\NAT@cite@list\@empty
\let\uNAT@citekeys\@empty
\let\uNAT@foundkeys\@empty
\forcsvlist{\listadd{\uNAT@citekeys}}{#1}%
\forlistloop{\uNAT@writetocitelistsort}{\uNAT@bibsortlist}%
\forlistloop{\uNAT@writetocitelistforgotten}{\uNAT@citekeys}%
}
\def\NAT@citex%
[#1][#2]#3{%
\NAT@reset@parser
\NAT@sort@cites{#3}%
\uNAT@sortcites{#3}%<- this is new
\NAT@reset@citea
\@cite{\let\NAT@nm\@empty\let\NAT@year\@empty
\@for\@citeb:=\NAT@cite@list\do
{\@safe@activestrue
\edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
\@safe@activesfalse
\@ifundefined{b@\@citeb\@extra@b@citeb}{\@citea%
{\reset@font\bfseries ?}\NAT@citeundefined
\PackageWarning{natbib}%
{Citation `\@citeb' on page \thepage \space undefined}\def\NAT@date{}}%
{\let\NAT@last@nm=\NAT@nm\let\NAT@last@yr=\NAT@year
\NAT@parse{\@citeb}%
\ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
\let\NAT@name=\NAT@all@names
\global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
\fi
\ifNAT@full\let\NAT@nm\NAT@all@names\else
\let\NAT@nm\NAT@name\fi
\ifNAT@swa\ifcase\NAT@ctype
\if\relax\NAT@date\relax
\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}\NAT@date}%
\else
\ifx\NAT@last@nm\NAT@nm\NAT@yrsep
\ifx\NAT@last@yr\NAT@year
\def\NAT@temp{{?}}%
\ifx\NAT@temp\NAT@exlab\PackageWarningNoLine{natbib}%
{Multiple citation on page \thepage: same authors and
year\MessageBreak without distinguishing extra
letter,\MessageBreak appears as question mark}\fi
\NAT@hyper@{\NAT@exlab}%
\else\unskip\NAT@spacechar
\NAT@hyper@{\NAT@date}%
\fi
\else
\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{%
\NAT@aysep\NAT@spacechar}{\@citeb\@extra@b@citeb
}%
\NAT@date
}%
\fi
\fi
\or\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
\or\@citea\NAT@hyper@{\NAT@date}%
\or\@citea\NAT@hyper@{\NAT@alias}%
\fi \NAT@def@citea
\else
\ifcase\NAT@ctype
\if\relax\NAT@date\relax
\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
\else
\ifx\NAT@last@nm\NAT@nm\NAT@yrsep
\ifx\NAT@last@yr\NAT@year
\def\NAT@temp{{?}}%
\ifx\NAT@temp\NAT@exlab\PackageWarningNoLine{natbib}%
{Multiple citation on page \thepage: same authors and
year\MessageBreak without distinguishing extra
letter,\MessageBreak appears as question mark}\fi
\NAT@hyper@{\NAT@exlab}%
\else
\unskip\NAT@spacechar
\NAT@hyper@{\NAT@date}%
\fi
\else
\@citea\NAT@hyper@{%
\NAT@nmfmt{\NAT@nm}%
\hyper@natlinkbreak{\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi}%
{\@citeb\@extra@b@citeb}%
\NAT@date
}%
\fi
\fi
\or\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
\or\@citea\NAT@hyper@{\NAT@date}%
\or\@citea\NAT@hyper@{\NAT@alias}%
\fi
\if\relax\NAT@date\relax
\NAT@def@citea
\else
\NAT@def@citea@close
\fi
\fi
}}\ifNAT@swa\else\if*#2*\else\NAT@cmt#2\fi
\if\relax\NAT@date\relax\else\NAT@@close\fi\fi}{#1}{#2}}
\makeatother
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Owen1876,
title = {{Descriptive and illustrated catalogue of the Fossil Reptilia of South Africa in the collection of the British Museum}},
publisher = {British Museum (Natural History)},
year = {1876},
author = {Richard Owen},
address = {London, United Kingdom},
note = {88 pp.},
url = {http://gallica.bnf.fr/ark:/12148/bpt6k987042},
}
@article{Berman1977,
author = {Berman, David S},
title = {{A new species of \textit{Dimetrodon} (Reptilia, Pelycosauria) from a non-deltaic facies in the Lower Permian of north-central New Mexico}},
journal = {Journal of Paleontology},
year = {1977},
volume = {51},
number = {1},
pages = {108--115},
}
@article{Berman1993_Seymouria,
author = {Berman, David S. and Martens, Thomas},
title = {{First occurrence of \textit{Seymouria} (Amphibia: Batrachosauria) in the Lower Permian Rotliegend of central Germany}},
journal = {Annals of Carnegie Museum},
year = {1993},
volume = {62},
number = {1},
pages = {63--79},
}
@incollection{Berman2015,
author = {David S. Berman AND Amy C. Henrici AND Spencer G. Lucas},
title = {{Pennsylvanian-Permian Red Bed vertebrate localities of New Mexico an their assemblages}},
booktitle = {{Fossil Vertebrates in New Mexico}},
publisher = {New Mexico Museum of Natural History},
year = {2015},
editor = {Lucas, S. G. AND Sullivan, R. M.},
volume = {68},
pages = {65--76},
}
\end{filecontents}
\begin{document}
\citep{Owen1876,
Berman1977,
Berman1993_Seymouria,
Berman2015}
\citep{Berman1977,
Berman1993_Seymouria,
Berman2015,
Owen1876}
\bibliographystyle{apalike-citesort}
\bibliography{\jobname}
\end{document}