3

This question is closely related to Biblatex: Autocite dependent on shorthand but since that question asks about autocite, I decided to open a new question.

I am trying to to declare a citation command \mycite, which behaves like \footcite for bib-entries without a shorthand field and for bib-entries with shorthand field when they are cited for the first time. If a bib-entry with shorthand field is cited for the second time \mycite should behave like \parencite

Here is a MWE:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @book{Book1, author={Author 1}, title={Title 1}, shorthand={Shorthand1}}
    @book{Book2, author={Author 2}, title={Title 2}}
\end{filecontents}

\usepackage[style=verbose,backend=biber]{biblatex}
\addbibresource{\jobname.bib}

\DeclareCiteCommand{\mycite}[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

\begin{document}
Citing an entry with defined shorthand field for the first time \mycite{Book1}.

Citing an entry with undefined shorthand field \mycite{Book2}.

Citing an entry with defined shorthand field for the second time \mycite{Book1}.
\end{document}

This gives the following output:

enter image description here enter image description here

I would like \mycite to output instead:

enter image description here enter image description here

Sadly the following declaration of \mycite does not work:

\DeclareCiteCommand{\mycite}[\iffieldundef{shorthand}\mkbibfootnote\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{cite:postnote}}

So what I tried instead, was to repurpose the <precode> and <postcode> fields by copy pasting the definitions of \mkbibparens and others, which seems to work for simple tasks like using square or rounded brackets depending on the shorthand field:

\makeatletter
\DeclareCiteCommand{\mycite}[]
  {\iffieldundef{shorthand}{%
    \begingroup
    \blx@blxinit
    \blx@setsfcodes
    \bibopenparen
    \usebibmacro{prenote}}{%
    \begingroup
    \blx@blxinit
    \blx@setsfcodes
    \bibopenbracket
    \usebibmacro{prenote}}%
   }
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\iffieldundef{shorthand}{%
    \usebibmacro{cite:postnote}%
    \bibcloseparen%
    \endgroup}{%
    \usebibmacro{cite:postnote}%
    \bibclosebracket%
    \endgroup}
  }
\makeatother

This might well be a very bad and ugly hack. And I have no idea how to do this with the \mkbibfootnote wrapper, which is more complex then the ones for \mkbibparens or \mkbibbrackets.

I would like to note, that the most important thing for me here is, to have a cite command which behaves like \footcite for entries without shorthand field and which behaves like \parencite for entries with shorthand field.

  • What would you want to happen if you were to cite two works that would trigger different behaviour as in \cite{foo,bar} where foo does have a shorthand and bar does not? If you only ever cite one work at a time a workaround is very easy (just move \ifciteseen and \mkbibfootnote into the loopcode), if not one would probably have to resort to more trickery. – moewe Aug 8 '15 at 13:36
  • 2
    The problem I have with what you are aiming at is that it makes it really hard for readers to track citations properly: Sometimes they will appear in the footnote, sometimes in the body. Especially if a shorthand is introduced a reader will have read the footnote in order to understand a subsequent shorthand in the text, so no footnote skipping would be allowed. – moewe Aug 8 '15 at 13:39
  • I can come up with a not that ugly solution, which unfortunately does only work if you restrict yourself to only citing one work per \mycite. Give me a shout if you would like to see that. Incidentally, the answer has pretty much the form of Guido's answer in the linked question. – moewe Aug 8 '15 at 14:00
  • @moewe Thank you for your comments and suggestions. You have good points there. When citing multiple entries the best solution for me would be to have them all in a footnote. But since I rarely do that, it would be sufficient to just use \footcite in these cases, I guess. Also your point about readability is sound. As I briefly mentioned, having the first citation of a bib-entry with shorthand field in a footnote is not all that important to me, but it would still be nice to know, how to do that. If you could show me your solution for citing one work at a time, that would really help me. – Wamseln Aug 8 '15 at 16:13
2

The following solution will work smoothly if you only ever cite one work per \mycite. This is because we had to move all the code into the loopcode of the citation command which is executed for every key cited. As we need to access information about the entry (i.e. does it have a shorthand field?) which is only available in the loopcode (and to a certain degree in the pre and postcodes?), it was necessary to make this adjustment.

\DeclareCiteCommand{\mycite}[\unspace]
  {}
  {\usebibmacro{citeindex}%
   \ifboolexpr{not test {\iffieldundef{shorthand}} and test {\ifciteseen}}%
     {\space\mkbibparens{\usebibmacro{prenote}\printfield{shorthand}\usebibmacro{cite:postnote}}}
     {\mkbibfootnote{\usebibmacro{prenote}\usebibmacro{cite}\usebibmacro{cite:postnote}}}}
  {\multicitedelim}
  {}

The idea is straightforward, we check if we have an entry with a shorthand that was already cited, if so we default to a \parencite with the shorthand; otherwise we do a normal cite in the footnote.

MWE

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
    @book{Book1, author={Author 1}, title={Title 1}, shorthand={Shorthand1}}
    @book{Book2, author={Author 2}, title={Title 2}}
\end{filecontents*}

\usepackage[style=verbose,backend=biber]{biblatex}
\addbibresource{\jobname.bib}

\DeclareCiteCommand{\mycite}[\unspace]
  {}
  {\usebibmacro{citeindex}%
   \ifboolexpr{not test {\iffieldundef{shorthand}} and test {\ifciteseen}}%
     {\space\mkbibparens{\usebibmacro{prenote}\printfield{shorthand}\usebibmacro{cite:postnote}}}
     {\mkbibfootnote{\usebibmacro{prenote}\usebibmacro{cite}\usebibmacro{cite:postnote}}}}
  {\multicitedelim}
  {}

\begin{document}
Citing an entry with defined shorthand field for the first time\mycite[Cf.][1]{Book1}.

Citing an entry with undefined shorthand field \mycite[2]{Book2}.

Citing an entry with defined shorthand field for the second time\mycite[4]{Book1}.
\end{document}

enter image description here

  • Thank you moewe! I changed it a little to \mkbibparens{\iffieldundef{prenote}{}{\printfield{prenote} }\usebibmacro{cite:shorthand}\iffieldundef{postnote}{}{ \printfield{postnote}}} Maybe you should consider to post your answer as an example to the question Biblatex: Autocite dependent on shorthand since my question now seems kind of a replicate to that one and you could help @Denis with it. Of course I could add a link to this post there, if you wish. Anyway: Thank you! – Wamseln Aug 9 '15 at 9:45
  • 1
    @Wamseln Was there anything that prompted you to do that change? I could not find any undesirable behaviour with my code and I think that internally the macros pretty much do what you want (plus/minus setting an appropriate separator which can be controlled via \postnotedelim and \prenotedelim). I don't think it is necessary to add this answer to the other question, Guido's answer pretty much covers it and the question is already linked to so people can see they are related. – moewe Aug 9 '15 at 11:44
  • Thanks again moewe. You are right. The additional \iffieldundef's are not necessary. But I use \usebibmacro{cite:shorthand} instead of \printfield{shorthand} because I made some changes to the bibmacro {cite:shorthand} and I want these changes to take effect. So now I use: \mkbibparens{\usebibmacro{prenote}\usebibmacro{cite:shorthand}\usebibmacro{cite:postnote}} – Wamseln Aug 9 '15 at 12:34
  • Sorry. I now tested with my real document and not with the MWE and remembered again, why I did use the additional \iffieldundef's: It's a quick and dirty hack in order to prevent any kind of special formatting for articles. Without the additional \iffieldundef's I get an additional _here: _ in front of the page number when citing a shorthand entry, which I do not want. To clarify: With your unchanged MWE I would get: Shorthand1, here: p. 12. With my hackish change I get: Shorthand1, p.12 I didn't want to take the time, figuring out how to do this the proper way. – Wamseln Aug 9 '15 at 12:45
  • I am sorry for my chaotic explanations and for using three comments instead of just one. But to clarify further: I wanted to suppress special formatting like Shorthand1, here: p. 12 for articles. Therefore I used \printfield instead of \usebibmacro. But the \printfield printed undesired spaces when empty, so I added \iffieldundef in order to prevent the spaces, when the field was empty. – Wamseln Aug 9 '15 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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