TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the right way to define a macro with an optional argument that can be called within the <postnote> optional argument to biblatex \cite?

The last two \cite below don't work.

(Unless they are enclosed in braces as the third and fourth \cite)

enter image description here

\usepackage[backend=biber, style=authortitle]{biblatex}


@Book{mykey, author={Author}, title={Title}, journal={Journal}, year={1950}}

\newcommand         \x [2][] {\ifthenelse{\equal{#1}{}}{}{(#1)}#2}
\NewDocumentCommand \y {mo}  {#1\IfValueT{#2}{(#2)}}


\cite [\x{100}]      {mykey}

\cite [\y{100}]      {mykey}

\cite [{\x[a]{100}}] {mykey}

\cite [{\y{100}[a]}] {mykey}

\cite [\x[a]{100}]   {mykey}

\cite [\y{100}[a]]   {mykey}

share|improve this question
Adding the braces is the right thing to do. {} matching is built in to the TeX parser (that is matching characters of catcode 1 and 2) LaTeX [] options are parsed with a delimited macro so they end at the first ] without counting nested []. So you need the {} to hide the inner square bracket. – David Carlisle Jan 23 '13 at 23:31
@DavidCarlisle That's true for commands defined using the standard LaTeX method (which is what biblatex does), but not those using xparse, which does deal correctly with the nesting here. – Joseph Wright Jan 24 '13 at 15:25
up vote 7 down vote accepted

The postnote formatting directive already acts on the contents of the postnote field. Its default definition can be found in biblatex.def:


Passing macros like \x{100} to the postnote argument prevents biblatex from recognizing page references. So you should modify the directive instead. The example below takes this approach. Postnotes can be specified in the form:

\cite[<prenote>][(<postnote prefix>)(<postnote suffix>)<postnote stem>]{<key>}

where the postnote prefix and suffix arguments are optional. When only one is given it is assumed to be a suffix. New directives are used to format each of the three postnote parts.


% just for demonstration








\subsection*{Without postnote affixes}
\cite[See][11--19 and the last section]{companion}
\subsection*{With postnote affixes}
\cite[See][(pre)(post)11--19 and the last section]{companion}

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.