我正在尝试简化必须多次手动输入引用命令的过程。我想在变量中输入一次,然后命令cite
将多次读取该变量;这将为我节省大量手动输入。下面的例子可以最好地说明我所尝试做的事情。有什么建议吗?
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[backend=bibtex, style=authoryear,sorting=nyt]{biblatex}
\begin{filecontents}{\jobname.bib}
@article{test,
author = {Author},
title = {Title},
journaltitle = {Annalen der Physik},
year = {1905},
volume = {322},
number = {10},
pages = {891--921},
abstract = {Abstract}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\newcommand{\citeKey}{test}
%outputs the text `test'
\citeKey{}
%this works
\cite{test} \\
\citetitle{test} \\
\citefield{test}{abstract}
%this does not work
\cite{\citeKey{}} \\
\citetitle{\citeKey{}} \\
\citefield{\citeKey{}}{abstract}
\printbibliography
\end{document}
答案1
删除{}
仅适用于印刷命令的扩展尊重后面的空格,但不是语法的一部分。
\begin{filecontents}{\jobname.bib}
@article{test,
author = {Author},
title = {Title},
journaltitle = {Annalen der Physik},
year = {1905},
volume = {322},
number = {10},
pages = {891--921},
abstract = {Abstract}
}
\end{filecontents}
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[style=authoryear,sorting=nyt]{biblatex}
\addbibresource{\jobname.bib}
\begin{document}
\newcommand{\citeKey}{test}
%outputs the text `test'
\citeKey{}
%this works
\cite{test} \\
\citetitle{test} \\
\citefield{test}{abstract}
%this does not work
\cite{\citeKey} \\
\citetitle{\citeKey} \\
\citefield{\citeKey}{abstract}
\printbibliography
\end{document}
我建议也删除backend=bibtex
:biblatex
这样效果会好得多biber
。