5

I'm using shorthands for some of my citations and generally using \textcite to get the authors without parenthesis and the year in parenthesis. My problem is that for the references with a shorthand \textcite replaces the year with the shorthand for the first citation.

I would like the first citation to be formatted like this: author (year, "hereafter" shorthand)

And the following: shorthand

MWE:

\documentclass[british,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{filecontents}
\usepackage[backend=biber,style=authoryear,citetracker=true,bibstyle=authoryear]{biblatex}
\DefineBibliographyStrings{english}{citedas = {hereafter}}

\begin{filecontents*}{\jobname.bib}
@article{jd14,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {Some Title},
  journal = {Some Journal},
  year    = {2014},
  shorthand = {JD14},
}
@article{jd13,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {No shorthand here},
  journal = {Some Other Journal},
  year    = {2013},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\newbibmacro*{longcite}{%
  \ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
    {\usebibmacro{cite:label}%
     \setunit{\addspace}}
    {\printnames{labelname}%
     \setunit{\nameyeardelim}}%
  \usebibmacro{cite:labelyear+extrayear}}

\renewbibmacro*{cite}{%
  \ifciteseen
    {\iffieldundef{shorthand}
      {\usebibmacro{longcite}}
      {\usebibmacro{cite:shorthand}}}
    {\usebibmacro{longcite}
     \usebibmacro{shorthandintro}}}

\begin{document}
  \cite{jd14} again \cite{jd14}.

  Just for comparison \textcite{jd13}.

  \printbibliography
\end{document}

Example

2 Answers2

2

I would suggest you to adapt textcite rather than cite, for it looks more like the final result you are intending. The following produces citations as specified:

\documentclass[british,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage{filecontents}
\usepackage[backend=biber,style=authoryear,citetracker=true,bibstyle=authoryear]{biblatex}
\DefineBibliographyStrings{english}{citedas = {hereafter}}

\begin{filecontents*}{\jobname.bib}
@article{jd14,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {Some Title},
  journal = {Some Journal},
  year    = {2014},
  shorthand = {JD14},
}
@article{jd13,
  author  = {Doe, J. and Smith, J. and Bar, F.},
  title   = {No shorthand here},
  journal = {Some Other Journal},
  year    = {2013},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\renewbibmacro*{textcite}{%
    \ifnameundef{labelname}
    {\iffieldundef{shorthand}
        {\usebibmacro{cite:label}%
            \setunit{%
                \global\booltrue{cbx:parens}%
                \printdelim{nonameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            \usebibmacro{cite:labelyear+extrayear}}
        {\usebibmacro{cite:shorthand}}}
    {\iffieldundef{shorthand}
        {\printnames{labelname}%
            \setunit{%
                \global\booltrue{cbx:parens}%
                \printdelim{nameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
            \usebibmacro{citeyear}}
        {\ifciteseen
            {\usebibmacro{cite:shorthand}}
            {\printnames{labelname}%
                \setunit{%
                    \global\booltrue{cbx:parens}%
                    \printdelim{nameyeardelim}\bibopenparen}%
                \ifnumequal{\value{citecount}}{1}
                {\usebibmacro{prenote}}
                {}%
                \iffieldundef{labelyear}
                {\usebibmacro{cite:label}
                    \setunit{\addcomma\addspace}%
                    \iffieldundef{shorthandintro}
                    {\printtext{\bibstring{citedas}}}
                    {\printtext{\printfield{shorthandintro}}}
                    \usebibmacro{cite:shorthand}}
                {\usebibmacro{cite:labelyear+extrayear}
                    \setunit{\addcomma\addspace}%
                    \iffieldundef{shorthandintro}
                    {\printtext{\bibstring{citedas}}}
                    {\printtext{\printfield{shorthandintro}}}
                    \usebibmacro{cite:shorthand}}}}}}

\begin{document}
  \textcite{jd14} again \textcite{jd14}.

  Just for comparison \textcite{jd13}.

  \printbibliography
\end{document}

Which gives us:

enter image description here

You could probably simplify this, if the need to handle all cases of missing/present fields originally dealt with in the original textcite of the authoryear style is not a concern.

gusbrs
  • 13,740
  • @Artturi Björk, I'm glad the solution worked for you. But do also take into consideration moewe's observations and suggestions. He's way more experienced in biblatex than I am, and if he offered a second (different) answer, it is likely he is seeing something I'm not. – gusbrs Jun 16 '17 at 19:23
2

It can be beneficial to redefine \cite and not use \textcite if you want the standard placement of pre- and postnotes.

Try

\documentclass[british,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage[backend=biber, style=authoryear, citetracker=true]{biblatex}
\DefineBibliographyStrings{english}{citedas = {hereafter}}

\newbibmacro*{shorthandintro:noparen}{% \iffieldundef{shorthandintro} {\iffieldundef{shorthand} {} {\setunit{\addcomma\space}% \bibstring{citedas}\space \printfield{shorthand}}} {\setunit{\addcomma\space}% \printfield{shorthandintro}}}

\newbibmacro*{cite:normal}{% \ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}} {\usebibmacro{cite:label}% \setunit{\printdelim{nonameyeardelim}}} {\printnames{labelname}% \setunit{\printdelim{nameyeardelim}}}% \printtext{\bibopenparen}% \usebibmacro{cite:labeldate+extradate}}

\renewbibmacro*{cite}{% \ifciteseen {\iffieldundef{shorthand} {\usebibmacro{cite:normal}% \printtext{\bibcloseparen}} {\usebibmacro{cite:shorthand}}} {\usebibmacro{cite:normal}% \usebibmacro{shorthandintro:noparen}% \printtext{\bibcloseparen}}}

\begin{filecontents}{\jobname.bib} @article{jd14, author = {Doe, J. and Smith, J. and Bar, F.}, title = {Some Title}, journal = {Some Journal}, year = {2014}, shorthand = {JD14}, } @article{jd13, author = {Doe, J. and Smith, J. and Bar, F.}, title = {No shorthand here}, journal = {Some Other Journal}, year = {2013}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} \cite{jd14} again \cite{jd14}.

Just for comparison \textcite{jd13}.

\printbibliography \end{document}

Doe, Smith and Bar (2014, hereafter JD14) again JD14. Just for comparison Doe, Smith and Bar (2013).

moewe
  • 175,683