renewcommand \cite[99]{Turing} 与 \cite{Turing}

renewcommand \cite[99]{Turing} 与 \cite{Turing}

我使用 \cite 命令作为\cite[99]{Turing}\cite{Turing}

我希望重新定义该命令如下:

\let\oldcite\cite
\renewcommand{\cite}[2]{[\oldcite[#1]{#2}]}

但是如果我尝试使用\cite{Turing},就会出现错误。

\documentclass[a4paper,10pt]{article}
\usepackage{biblatex}
\bibliography{prova}
\let\oldcite\cite
\renewcommand{\cite}[2]{[\oldcite[#1]{#2}]}
\begin{document}
text
\cite{99}{Turing} % Ok, but I would like to type \cite[99]{Turing} 
\cite{Turing} 
%error ! Paragraph ended before \blx@xsanitizeafter was complete.
\printbibliography 
\end{document}

答案1

最好的解决方案是使用biblatex提供的丰富工具来解决这个问题。相关命令是\DeclareCiteCommand biblatex文档第 131 页

\brackcite我们根据 的定义定义了一个新的引用命令\parencite。只需将代码片段添加到您的序言中即可。

以下代码适用于所有标准biblatex样式。

\DeclareCiteCommand{\brackcite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

如果这不能正常工作 - 其他样式如biblatex-philosophybiblatex-apa使用不同的宏 -,找到该样式的定义\parencite(它应该在文件中.cbx)将其定义复制到你的序言中,将其重命名为\brackcite,并将定义从修改\mkbibparens\mkbibbrackets

authortitle为了定义和提供的带星号的版本authoryear,我们做完全相同的事情

\DeclareCiteCommand*{\brackcite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citetitle}}% or \usebibmacro{citeyear} for authoryear
  {\multicitedelim}
  {\usebibmacro{postnote}}

并非所有样式都定义此命令,只需检查您的样式.cbx并按照上述方法复制和修改定义。

然后您就可以像使用\brackcite任何其他\*cite命令一样使用它。

\documentclass[a4paper,10pt]{article}
\usepackage[style=authoryear]{biblatex}
\addbibresource{biblatex-examples.bib}

\DeclareCiteCommand{\brackcite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

% use only for styles that support this (standard authordate and authortitle styles do)
% replace \usebibmacro{citetitle} by \usebibmacro{citeyear} for authoryear
\DeclareCiteCommand*{\brackcite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citetitle}}% change this to \usebibmacro{citeyear} for authoryear
  {\multicitedelim}
  {\usebibmacro{postnote}}

\begin{document}
\begin{tabular}{rl}
  \verb|\cite{herrmann}| & \cite{herrmann}\\
  \verb|\parencite{herrmann}| & \parencite{herrmann}\\
  \verb|\brackcite{herrmann}| & \brackcite{herrmann}\\
  \verb|\cite[99]{herrmann}| & \cite[99]{herrmann}\\
  \verb|\parencite[99]{herrmann}| & \parencite[99]{herrmann}\\
  \verb|\brackcite[99]{herrmann}| & \brackcite[99]{herrmann}\\
  \verb|\cite[see][99]{herrmann}| & \cite[99][see]{herrmann}\\
  \verb|\parencite[see][99]{herrmann}| & \parencite[see][99]{herrmann}\\
  \verb|\brackcite[see][99]{herrmann}| & \brackcite[see][99]{herrmann}\\
\end{tabular}
\printbibliography 
\end{document}

在此处输入图片描述

相关内容