Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a question about the smartcite command from biblatex.

I redefined it in the following way:

\documentclass{article}
\usepackage[style=alphabetic, autocite=footnote]{biblatex}

\DeclareCiteCommand{\smartcite}[\iffootnote\mkbibparens\mkbibfootnote]
    {\usebibmacro{prenote}}
    {\usebibmacro{citeindex}%
               \printtext[brackets]{\usebibmacro{cite} \usebibmacro{postnote}}}
    {\multicitedelim}
    {}

\DeclareMultiCiteCommand{\smartcites}
   [\iffootnote\mkbibparens\mkbibfootnote]{\smartcite}{\multicitedelim}

\DeclareAutoCiteCommand{footnote}[f]{\smartcite}{\smartcites}

\begin{filecontents*}{bibliography.bib}
@BOOK{ABC,
  author = {Cornelisse, J. W. and Schöyer, H. Ferry R. and Wakker, Karel F.},
  title = {Rocket Propulsion and Spaceflight Dynamics},
  year = {1979},
  publisher = {Pitman},
}
\end{filecontents*}

\bibliography{bibliography.bib}

\begin{document}
   Normal text\footnote{Some text \autocite[][20]{ABC}}.}
\end{document}

With this I get a footnote citation within the normal text and a parenthesized citation in a footnote when using the \autocite command.

The problem is when I use e.g. \footnote{Some text \autocite[][20]{ABC}}.} I get as result Some text ([ABC, S. 20]). but what I would like to see is Some text [ABC, S. 20]. when I don't give a prenote. But when there is a prenote like \footnote{Some text \autocite[see][20]{ABC}}.} I would like to get Some text (see [ABC, S. 20]). as a result.

I tried to redefine the \smartcite command with:

   \DeclareCiteCommand{\smartcite}[\iffootnote{\ifthenelse{\iffieldundef{prenote}}{\textnormal}{\mkbibparens}}{\mkbibfootnote}]
    {\usebibmacro{prenote}}
    {\usebibmacro{citeindex}%
               \printtext[brackets]{\usebibmacro{cite} \usebibmacro{postnote}}}
    {\multicitedelim}
    {}

but it seems like the \ifthenelse command has no effect.

Has anybody an idea how to fix it?

Regards

share|improve this question
    
It seems as though the \iffieldundef{prenote} is not available in the wrapper argument of \DeclareCiteCommand. –  moewe Mar 30 at 13:32

1 Answer 1

up vote 6 down vote accepted

\iffieldundef{prenote} does not seem to be available to biblatex in the wrapper argument to \DeclareCiteCommand, so we have to delay the test until it is possible.

This can be done as follows

\newtoggle{weareinfootnote}
\settoggle{weareinfootnote}{false}

\newbibmacro*{smartprenote}{%
  \iffieldundef{prenote}
    {}
    {\iftoggle{weareinfootnote}
       {\bibopenparen}%
       {}%
     \printfield{prenote}%
     \setunit{\prenotedelim}}}

\DeclareCiteCommand{\smartcite}[\iffootnote{\settoggle{weareinfootnote}{true}}{\settoggle{weareinfootnote}{false}\mkbibfootnote}]
    {\usebibmacro{smartprenote}}
    {\usebibmacro{citeindex}%
     \printtext[brackets]{\usebibmacro{cite}\usebibmacro{postnote}}}
    {\multicitedelim}
    {\ifboolexpr{not test {\iffieldundef{prenote}} and test {\iftoggle{weareinfootnote}}}
      {\bibcloseparen}%
      {}}

smartprenote prints an opening parenthesis additionally to the prenote if it is in a \footnote. Finally in the "postcode" section, we close the parentheses if a prenote is present in a footnote. We cannot use the standard \iffootnote test in the citation command since it will always yield true (if it was called in a footnote it obviously does, while if it was called in-text, we start a footnote ourselves resulting in \iffootnote evaluating to true), so we define a toggle weareinfootnote that checks whether we were in a footnote before the command was issued.

Note that this might go horribly wrong with multiple citations or \smartcites code.

\documentclass{article}
\usepackage[style=alphabetic, autocite=footnote]{biblatex}

\newtoggle{weareinfootnote}
\settoggle{weareinfootnote}{false}

\newbibmacro*{smartprenote}{%
  \iffieldundef{prenote}
    {}
    {\iftoggle{weareinfootnote}
       {\bibopenparen}%
       {}%
     \printfield{prenote}%
     \setunit{\prenotedelim}}}

\DeclareCiteCommand{\smartcite}[\iffootnote{\settoggle{weareinfootnote}{true}}{\settoggle{weareinfootnote}{false}\mkbibfootnote}]
    {\usebibmacro{smartprenote}}
    {\usebibmacro{citeindex}%
     \printtext[brackets]{\usebibmacro{cite}\usebibmacro{postnote}}}
    {\multicitedelim}
    {\ifboolexpr{not test {\iffieldundef{prenote}} and test {\iftoggle{weareinfootnote}}}
      {\bibcloseparen}%
      {}}

\addbibresource{biblatex-examples.bib}

\begin{document}
   Normal in-text cite \autocite[20]{wilde} indeed\autocite[see][20]{wilde}. Normal text\footnote{Some text \autocite[][20]{wilde}} and\footnote{Some text \autocite[see][20]{wilde}}.

   Normal in-text cite \autocite{wilde,cicero} indeed \autocite[see][]{wilde,cicero}. Normal text\footnote{Some text \autocite{wilde,cicero}} and\footnote{Some text \autocite[see][]{wilde,cicero}}.
\end{document}

enter image description here

share|improve this answer
    
Thank you works great. One thing, I don't realize till I implement your solution. When I write Normal in-text cite \autocite[see][20]{wilde}. I have the problem that I get (see [Wil99, p. 20]) in the footnote which looks a bit odd it should be See [Wil99, p. 20]. Is this possible? I think in this case a test if one came from the normal text and went into the footnote or a test if the prenote is the first text in the footnote is required. –  user2653422 Mar 30 at 15:14
    
@user2653422 Thanks for catching that, it was thanks to biblatex's \iffootnote, I have changed that. Do you have any thoughts about citations with multiple keys (and post and pre notes) or the multicite version? –  moewe Mar 30 at 15:38
    
Nice, works flawless. For the multi citations I use the \autocites(see)()[][]{key1}[][]{key2}, which results in the desired output, even when I use pre notes for a concrete key. Only for \footnote{Some text \autocites()()[][]{key1}[][]{key2}} one can argue that the round brackets are unnecessary, but I wouldn't type it that way. –  user2653422 Mar 30 at 16:19
    
@user2653422 OK, glad to hear it works. –  moewe Mar 30 at 16:20

Your Answer

 
discard

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.