![使用 BibLaTeX 模仿 BibTeX “apalike”-(biblatex-apa 坏了?)](https://linux22.com/image/247104/%E4%BD%BF%E7%94%A8%20BibLaTeX%20%E6%A8%A1%E4%BB%BF%20BibTeX%20%E2%80%9Capalike%E2%80%9D-%EF%BC%88biblatex-apa%20%E5%9D%8F%E4%BA%86%EF%BC%9F%EF%BC%89.png)
我正在尝试转向 BibLaTeX。使用 BibTeX,Styleapalike
提供了我需要的一切,如以下 MWE 所示:
\documentclass{article}
\usepackage{xcolor}
\usepackage{natbib}
\usepackage{hyperref}
\hypersetup{%
colorlinks=true,
citecolor=blue}
\begin{document}
Some text as written by \cite{Attanasio2010} and \citep{Galindo2002}
\bibliographystyle{apalike}
\bibliography{bib}
\end{document}
其中的内容bib
由 Mendeley 生成,如下所示:
@article{Attanasio2010,
abstract = {This paper provides a critical survey of the large literature on the life cycle model of consumption, both from an empirical and a theoretical point of view. It discusses several approaches that have been taken in the literature to bring the model to the data, their empirical successes and failures. Finally, the paper reviews a number of changes to the standard life cycle model that could help solve the remaining empirical puzzles.},
author = {Kaminsky, Graciela Laura and Schmukler, Sergio L.},
journal = {NBER Working Paper},
month = feb,
shorttitle = {Consumption and saving},
title = {{Consumption and saving: models of intertemporal allocation and their implications for public policy}},
url = {http://papers.ssrn.com/sol3/papers.cfm?abstract\_id=1558816 http://www.nber.org/papers/w15756},
volume = {756},
number = {12},
year = {2010}
}
@article{Galindo2002,
author = {Galindo, Arturo and Schiantarelli, Fabio and Weiss, Andrew},
journal = {American Economic Review},
month = apr,
shorttitle = {Does Financial Liberalization Improve the Allocati},
title = {{Does Financial Liberalization Improve the Allocation of Investment?: Micro Evidence from Developing Countries}},
url = {http://ideas.repec.org/p/idb/wpaper/4295.html},
volume = {47},
number = {2},
year = {2002}
}
我所需要的实际上非常简单,并通过我的例子进行了演示
- 引用如示例所示(cite:括号中的年份或 citep:作者-年份,以逗号分隔)
- 当作者超过 2 人时,使用 et al.。
- 参考书目:仅限名字/中间名的首字母。
- 姓氏,名字
- 切勿使用 et al。
- 仅显示年份,即使指定了月份
- 从不显示 URL(取自...)
- 问题在卷号旁边的括号中
- 如果使用超链接,请创建完整引用的链接,而不仅仅是年份。
结果应如下所示:
我可能忘记了一些东西,但这些是显而易见的。我整天都在玩不同风格的 BibLaTeX,包括 authoryear 和 apa,但我无法重现简单的 apalike 风格。事实上,我无法让 apa 让 BibLaTeX 工作,因为我得到了以下错误:
Package biblatex Warning: Bibliography string 'retrieved' undefined(biblatex) at entry 'Attanasio2010'
编辑1:我无法工作的 biblatex-apa MWE 是:
\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{%
colorlinks=true,
citecolor=blue}
\usepackage{polyglossia}
\setmainlanguage[variant=american]{english}
\usepackage{csquotes}
\PassOptionsToPackage{
natbib=true,
style=apa,
hyperref=true,
backend=biber,
maxbibnames=99,
firstinits=true,
maxcitenames=2,
parentracker=true
} {biblatex}
\usepackage{biblatex}
\DeclareNameAlias{default}{last-first}
\DeclareLanguageMapping{american}{american-apa}
\addbibresource{bib.bib}
\begin{document}
Some text as written by \cite{Attanasio2010} and \citep{Galindo2002}
\printbibliography
\end{document}
会产生错误:
Undefined control sequence: <argument> \mkbibdateapalongextra :
Package biblatex Warning: Bibliography string 'retrieved' undefined(biblatex) at entry 'Galindo2002'
Package biblatex Warning: Bibliography string 'from' undefined(biblatex) at entry 'Galindo2002'
看起来像这样:
编辑2:问题出在多语上。使用 \usepackage[american]{babel} 则不会出现错误。
编辑3:进一步的测试表明,使用多语制时,必须使用\DeclareLanguageMapping{english}{american-apa}
。这可以解决Bibliography string 'retrieved' undefined
错误,但日期仍然错误,并且Undefined control sequence: \mkbibdateapalongextra
仍然存在。
答案1
我能够使用在 tex.sx 上找到的各种技巧来回答我自己的问题。正如 @PLK 指出的那样,polyglossia 和 Biblatex 似乎存在兼容性问题,但在我尝试的所有样式中,这个问题仅在 APA 样式中可见。所以我改用 authoryear-comp,它符合我所述的要求。这可能对任何想要简单、阿帕莱克风格,尤其是在使用 Mendeley 时。
- 引用: cite: 年份(括号内)或 citep: 作者-年份(以逗号分隔)->
\let\citealp\cite
\let\cite\textcite
- 如果使用超链接,则创建完整引用的链接,而不仅仅是年份。->回答来自@Audrey,请参阅下面的 MWE。
当作者超过 2 人时使用 et al.。->
maxcitenames=2
参考书目:仅限名字/中间名的首字母。->
giveninits=true, uniquename=init
姓氏,名字 ->
\DeclareNameAlias{sortname}{family-given}
- 切勿使用 et al。->
maxbibnames=99
- 仅显示年份,即使指定了月份 ->
\AtEveryBibitem{% \clearfield{month}{}% \clearlist{language}{}% }
(也省略了语言字段) - 永不显示 URL(取自...)->
url=false, doi=false, isbn=false, eprint=false
- 在卷旁边的括号中发出 -> 参见下面的 MWE。
下面的 MWE 中还有一些其他调整,例如,对于反向引用使用“cited”而不是“cit.”,删除文章中的“in:”,增加 bib 项目的垂直空间。
\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{%
colorlinks=true,
citecolor=blue}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\usepackage{csquotes}
\PassOptionsToPackage{
natbib=true,
style=authoryear-comp,
hyperref=true,
backend=biber,
maxbibnames=99,
giveninits=true,
uniquename=init,
maxcitenames=2,
parentracker=true,
url=false,
doi=false,
isbn=false,
eprint=false,
backref=true,
} {biblatex}
\usepackage{biblatex}
\DeclareNameAlias{sortname}{family-given}
% remove "in:" from articles. Thanks to Herbert.
\renewbibmacro{in:}{%
\ifentrytype{article}{}{%
\printtext{\bibstring{in}\intitlepunct}}}
% mit "month" and "language" from Bibliography
\AtEveryBibitem{%
\clearfield{month}{}%
\clearlist{language}{}%
}
% some natbib backwards compatibility
\let\citealp\cite
\let\cite\textcite
% increase vertical space between bibliography items.
\setlength\bibitemsep{0.5ex}
\setlength\bibnamesep{1.2ex}
% Comma before and after journal volume. Thanks to lockstep.
\renewbibmacro*{volume+number+eid}{%
\setunit*{\addcomma\space}% NEW
\printfield{volume}%
\printfield{number}%
\printfield{eid}}
\DeclareFieldFormat[article]{number}{(#1)}% number of a journal
% Citation Hyperlinks (not just years), thanks to Audrey.
\makeatletter
\renewbibmacro*{cite}{% Based on cite bib macro from authoryear-comp.cbx
\iffieldundef{shorthand}
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
{\printtext[bibhyperref]{% Include labelname in hyperlink
\DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
\usebibmacro{cite:label}%
\setunit{\addspace}%
\usebibmacro{cite:labelyear+extrayear}}%
\usebibmacro{cite:reinit}}
{\iffieldequals{namehash}{\cbx@lasthash}
{\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
\(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
{\setunit{\addcomma}%
\usebibmacro{cite:extrayear}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labelyear+extrayear}%
\savefield{labelyear}{\cbx@lastyear}}}
{\printtext[bibhyperref]{% Include labelname in hyperlink
\DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
\printnames{labelname}%
\setunit{\nameyeardelim}%
\usebibmacro{cite:labelyear+extrayear}}%
\savefield{namehash}{\cbx@lasthash}%
\savefield{labelyear}{\cbx@lastyear}}}}
{\usebibmacro{cite:shorthand}%
\usebibmacro{cite:reinit}}%
\setunit{\multicitedelim}}
\renewbibmacro*{textcite}{% Based on textcite bib macro from authoryear-comp.cbx
\iffieldequals{namehash}{\cbx@lasthash}
{\iffieldundef{shorthand}
{\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
\(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
{\setunit{\addcomma}%
\usebibmacro{cite:extrayear}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labelyear+extrayear}%
\savefield{labelyear}{\cbx@lastyear}}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:shorthand}%
\global\undef\cbx@lastyear}}
{\ifnameundef{labelname}
{\printtext[bibhyperref]{% Include labelname in hyperlink
\DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
\iffieldundef{shorthand}
{\usebibmacro{cite:label}%
\setunit{%
\global\booltrue{cbx:parens}%
\addspace\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\usebibmacro{cite:labelyear+extrayear}}
{\usebibmacro{cite:shorthand}}%
\ifthenelse{\iffieldundef{postnote}\AND
\(\value{multicitetotal}=0\AND\value{citetotal}=1\)}
{\bibcloseparen% Include closing parenthesis in hyperlink
\global\boolfalse{cbx:parens}}
{}}}
{\printtext[bibhyperref]{% Include labelname in hyperlink
\DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
\printnames{labelname}%
\setunit{%
\global\booltrue{cbx:parens}%
\addspace\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\iffieldundef{labelyear}
{\usebibmacro{cite:label}}
{\usebibmacro{cite:labelyear+extrayear}}%
\savefield{labelyear}{\cbx@lastyear}}
{\usebibmacro{cite:shorthand}%
\global\undef\cbx@lastyear}%
\ifthenelse{\iffieldundef{postnote}\AND
\(\value{multicitetotal}=0\AND\value{citetotal}=1\)}
{\bibcloseparen% Include closing parenthesis in hyperlink
\global\boolfalse{cbx:parens}}
{}}%
\savefield{namehash}{\cbx@lasthash}}}%
\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\multicitedelim}}
\makeatother
% Backrefs "cited" instead of "cit"
\DefineBibliographyStrings{english}{%
backrefpage={cited on p\adddot},
backrefpages={cited on pp\adddot}
}
\addbibresource{bib.bib}
\begin{document}
Finally, as written by \cite{Attanasio2010}, my Bibliography is cool \citep{Galindo2002}. Furthermore (see, for example, \citealp{Attanasio2010}) there are some cool tweaks.
\printbibliography
\end{document}