我使用括号来补充参考书目中缺失的信息。但是当我在文本的引文中包含这些信息时,这些括号不应该出现。在下面的例子中,文本应该是
正如约翰·列侬在 1970 年所写的那样……
尽管如此,参考书目仍应保留括号。(自定义\citeauthorfullname
宏是我发现的这里)。
\documentclass{article}
\usepackage[style = authoryear]{biblatex}
\DeclareCiteCommand{\citeauthorfullname}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\DeclareNameAlias{labelname}{first-last}%
\usebibmacro{prenote}}
{\ifciteindex
{\indexnames{labelname}}
{}%
\printnames{labelname}}
{\multicitedelim}
{\usebibmacro{postnote}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{lennon1970,
AUTHOR = "J[ohn] Lennon",
TITLE = "This book was released with my Imagine album",
YEAR = "[1970]"}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
As \citeauthorfullname{lennon1970} wrote in \citeyear{lennon1970} \ldots
\printbibliography
\end{document}
答案1
这只是部分答案,但我想详细说明我的评论。
例如,要格式化名称,您可以尝试以下操作:
\documentclass{article}
\usepackage[style = authoryear]{biblatex}
\DeclareCiteCommand{\citeauthorfullname}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\DeclareNameAlias{labelname}{first-last}%
\usebibmacro{prenote}}
{\ifciteindex
{\indexnames{labelname}}
{}%
\printnames{labelname}}
{\multicitedelim}
{\usebibmacro{postnote}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{lennon1970,
AUTHOR = {Lennon, John},
TITLE = {This book was released with my Imagine album},
YEAR = 1971}
\end{filecontents}
\addbibresource{\jobname.bib}
\makeatletter
\def\mybrack#1#2\@nil{#1[#2]}
\AtBeginBibliography{%
\renewcommand*\mkbibnamefirst[1]{%
\mybrack#1\@nil}}
\makeatother
\begin{document}
As \citeauthorfullname{lennon1970} wrote in \citeyear{lennon1970} \ldots
\printbibliography
\end{document}
答案2
下面显示如何实现bareyear
仅包含年份而没有额外括号的字段,并且可以在字段中\citeyear
使用bareauthor
。
首先,我们必须biblatex
通过文件了解我们的新字段datamodel
(将以下内容保存为barefields.dbx
并将其放置在 LaTeX 可以找到的地方)
\ProvidesFile{barefields.dbx}[2014/04/02 allow for bracket-less fields]
\RequireBiber[3]
\DeclareDatamodelFields[type=field,datatype=literal]{bareyear}
\DeclareDatamodelEntryfields{bareyear}
\DeclareDatamodelFields[type=list,datatype=name]{bareauthor}
\DeclareDatamodelEntryfields{bareauthor}
\endinput
我们简单地定义一个对所有条目类型有效的文字字段bareyear
,以及一个名称列表bareauthor
。
我们通过以下方式填充字段
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=year,
match=\regexp{\A\[(.+)\]\z},
final]
\step[fieldset=bareyear, fieldvalue={$1}]
\step[fieldset=sortyear, fieldvalue={$1}]
}
\map[overwrite]{
\step[fieldsource=author, match=\regexp{\[(.+)\]}, final]
\step[fieldset=bareauthor, origfieldval]
\step[fieldsource=bareauthor, match=\regexp{\[(.+)\]}, replace=\regexp{$1}]
}
}
}
正如 PLK 所描述的那样在 biblatex 2.7 中按括号年份对参考文献进行排序.(第二部分在某些情况下可能会有更多的错误和中断,year
但整个系统应该可以正常工作。)
剩下的就是\citeyear
利用bareyear
和\citeauthorfullname
使用bareauthor
\DeclareCiteCommand{\citeyear}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\iffieldundef{bareyear}
{\printfield{year}}
{\printfield{bareyear}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\citeauthorfullname}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\DeclareNameAlias{labelname}{first-last}%
\usebibmacro{prenote}}
{\ifnameundef{bareauthor}
{\printnames{labelname}}
{\printnames{bareauthor}}}
{\multicitedelim}
{\usebibmacro{postnote}}
您会注意到,即使labelname
实际上设置为编辑器,这也将始终打印作者,但我认为您必须接受这一点。(我无法labelname
在源映射过程中访问,因为[大概]那时biblatex
还不确定要将哪个名称字段作为labelname
。只是一个想法:您可以创建bareauthor
和bareeditor
字段并将它们列在命令中的author
和editor
字段之前\DeclareLabelname
,因此biblatex
更喜欢bare...
版本而不是“正常”名称 - 那么就不需要修改引用命令了。)
平均能量损失
\documentclass{article}
\usepackage[style = authoryear,datamodel=barefields]{biblatex}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=year,
match=\regexp{\A\[(.+)\]\z},
final]
\step[fieldset=bareyear, fieldvalue={$1}]
\step[fieldset=sortyear, fieldvalue={$1}]
}
\map[overwrite]{
\step[fieldsource=author, match=\regexp{\[(.+)\]}, final]
\step[fieldset=bareauthor, origfieldval]
\step[fieldsource=bareauthor, match=\regexp{\[(.+)\]}, replace=\regexp{$1}]
}
}
}
\DeclareCiteCommand{\citeauthorfullname}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\DeclareNameAlias{labelname}{first-last}%
\usebibmacro{prenote}}
{\ifnameundef{bareauthor}
{\printnames{labelname}}
{\printnames{bareauthor}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\citeyear}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\iffieldundef{bareyear}
{\printfield{year}}
{\printfield{bareyear}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{lennon1969,
author = {J[ohn] Lennon},
title = {Some work from 69 -- maybe Summer of},
year = {1969},
}
@book{lennon1970,
author = {J[ohn] Lennon},
title = {This book was released with my Imagine album},
year = {[1970]},
}
@book{lennon1971,
author = {J[ohn] Lennon},
title = {This is from 71},
year = {1971},
}
@book{lennon1972,
author = {John Lennon},
title = {This Really is by John Lennon},
year = {1972},
}
\end{filecontents*}
\begin{filecontents*}{barefields.dbx}
\ProvidesFile{barefields.dbx}[2014/04/02 allow for bracket-less fields]
\RequireBiber[3]
\DeclareDatamodelFields[type=field,datatype=literal]{bareyear}
\DeclareDatamodelEntryfields{bareyear}
\DeclareDatamodelFields[type=list,datatype=name]{bareauthor}
\DeclareDatamodelEntryfields{bareauthor}
\endinput
\end{filecontents*}
\addbibresource{\jobname.bib}
\nocite{*}
\begin{document}
As \citeauthorfullname{lennon1970} wrote in \citeyear{lennon1970} \ldots\ and in \citeyear{lennon1972}.
\printbibliography
\end{document}
答案3
您可以尝试使用包编写宏xstring
。我试了一段时间,但无法让它工作。也许这里的其他人可以做到...
它是一个函数\strDel
,你可以用它从字符串中删除子字符串:
\StrDel{Hello there J[ohn]}{[}[\result]%remove [ and save in \result
\StrDel{\result}{]}[\result]%remove ] and save in \result
上面的代码可以运行,但遗憾的是下面的宏却不行。它只是打印出的内容\citeyear{#1}
:
\newcommand{\citeyearp}[1]{%
\StrDel{\citeyear{#1}}{[}[\result]%
\StrDel{\result}{]}[\result]%
\result%
}