2

I use \cite commands both as \cite[99]{Turing} and \cite{Turing}.

I wish to redefine the command as it follows:

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

but then if I try just to use \cite{Turing}, I get an error.

\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}
5
  • 2
    \renewcommand{\cite}[2]{...} defines \cite to have two arguments. You should also use \cite{99}{Turing} after the redefinition.
    – cgnieder
    Commented Jul 31, 2013 at 14:56
  • do I really need letltxmacro?
    – mario
    Commented Jul 31, 2013 at 15:06
  • If \cite{99}{Turing} works apparently not. \cite{Turing} must go wrong as it needs a second argument the way you defined it. It's not really clear to me what you want to achieve, though...
    – cgnieder
    Commented Jul 31, 2013 at 15:08
  • 4
    I think you want \renewcommand{\cite}[2][]{[\oldcite[#1]{#2}]} (notice the second optional argument to \renewcommand). I believe with biblatex there are better ways to get square brackets around the citation.
    – cgnieder
    Commented Jul 31, 2013 at 15:10
  • YES, it works! great thks.
    – mario
    Commented Jul 31, 2013 at 15:40

1 Answer 1

3

The neatest solution is to use the rich facilities biblatex provides to deal with exactly this problem. The relevant command is \DeclareCiteCommand p. 131 of the biblatex documentation.

We define a new citation command \brackcite based on the definition of \parencite. Just add the code snippets to your preamble.

The following code should work for all standard biblatex styles.

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

In case this does not work properly - other styles like biblatex-philosophy and biblatex-apa use different macros -, find the definition of \parencite for that style (it should be in the .cbx file) copy its definition to your preamble, rename it to \brackcite and modify the definition from \mkbibparens to \mkbibbrackets.

To define the starred version provided by authortitle and authoryear, we do exactly the same

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

This command is not defined by all styles, just check your style's .cbx and copy and modify the definition as above.

You can then use \brackcite just like any other \*cite command.

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .