4

How can I use shorthands or aliases with the citation style authoryear-comp? Specifically, I would like to have

First text citation:

Bravo & Charlie (2002, hereafter Paper I)

Bravo & Charlie (2002, hereafter Paper I) and Charlie & Delta (2004)

Bravo & Charlie (2002, hereafter Paper I, 2003) and Charlie & Delta (2004)

Bravo & Charlie (2001, 2002, hereafter Paper I) and Charlie & Delta (2004)

Alpha & Bravo (2000) and Bravo & Charlie (2002, hereafter Paper I)

First parenthesized citation:

(Bravo & Charlie 2002, hereafter Paper I)

(Bravo & Charlie 2002, hereafter Paper I; Charlie & Delta 2004)

(Bravo & Charlie 2002, hereafter Paper I, 2003; Charlie & Delta 2004)

(Bravo & Charlie 2001, 2002, hereafter Paper I; Charlie & Delta 2004)

(Alpha & Bravo 2000; Bravo & Charlie 2002, hereafter Paper I)

Subsequent text citations:

Paper I

Paper I and Charlie & Delta (2004)

Paper I, Bravo & Charlie (2003), and Charlie & Delta (2004)

Bravo & Charlie (2001), Paper I, and Charlie & Delta (2004)

Alpha & Bravo (2000) and Paper I

Subsequent parenthesized citations:

(Paper I)

(Paper I; Charlie & Delta 2004)

(Paper I; Bravo & Charlie 2003; Charlie & Delta 2004)

(Bravo & Charlie 2001; Paper I; Charlie & Delta 2004)

(Alpha & Bravo 2000; Paper I)

The style is based off the Astrophysical Journal (ApJ). I am not aware of specific instructions regarding punctuations and sorting in the case of shorthands or aliases, so the examples above may be slightly incorrect.

It is easy enough to get the ApJ style from authoryear-comp with

\renewcommand*\finalnamedelim
  {\ifbibliography{\finalandcomma}{}\addspace\&\space}
\renewcommand*\nameyeardelim{\addspace}
\DefineBibliographyStrings{english}{citedas={hereafter}}

but hacking authoryear-comp to get shorthands or aliases to work is beyond me.

Edit 1: Per comment from @moewe, here is a test example. Shorthands are of course not yet working as intended. (Curious note: 0 cannot be used as an entry key.)

\documentclass{article}
\usepackage[style=authoryear-comp, backend=biber]{biblatex}
\begin{filecontents}{\jobname.bib}
@article{1,
  author    = "Alpha, A. and Bravo, B.",
  year      = "2000"
}
@article{2,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2001"
}
@article{3,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2002",
  shorthand = "Paper I"
}
@article{4,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2003"
}
@article{5,
  author    = "Charlie, C. and Delta, D.",
  year      = "2004"
}
\end{filecontents}
\addbibresource{\jobname}
\renewcommand*\finalnamedelim
  {\ifbibliography{\finalandcomma}{}\addspace\&\space}
\renewcommand*\nameyeardelim{\addspace}
\DefineBibliographyStrings{english}{citedas={hereafter}}
\begin{document}
\parindent0em\relax
\textcite{3}\citereset\par
\textcite{3, 5}\citereset\par
\textcite{3, 4, 5}\citereset\par
\textcite{2, 3, 5}\citereset\par
\textcite{1, 3}\citereset\vskip\bigskipamount
\parencite{3}\citereset\par
\parencite{3, 5}\citereset\par
\parencite{3, 4, 5}\citereset\par
\parencite{2, 3, 5}\citereset\par
\parencite{1, 3}\vskip\bigskipamount
\textcite{3}\par
\textcite{3, 5}\par
\textcite{3, 4, 5}\par
\textcite{2, 3, 5}\par
\textcite{1, 3}\vskip\bigskipamount
\parencite{3}\par
\parencite{3, 5}\par
\parencite{3, 4, 5}\par
\parencite{2, 3, 5}\par
\parencite{1, 3}
\end{document}

Edit 2: Here is an extended test followed by expected results.

\documentclass{article}
\usepackage[letterpaper, left=1in, right=1in]{geometry}
\usepackage[style=authoryear-comp, citetracker, backend=biber]{biblatex}
\begin{filecontents}{\jobname.bib}
@article{1,
  author    = "Alpha, A. and Bravo, B.",
  year      = "2001"
}
@article{2,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2002"
}
@article{3,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2003"
}
@article{4,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2004",
  shorthand = "Paper I"
}
@article{5,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2005"
}
@article{6,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2006"
}
@article{7,
  author    = "Charlie, C. and Delta, D.",
  year      = "2007"
}
\end{filecontents}
\addbibresource{\jobname}
\renewcommand*\finalnamedelim
  {\ifbibliography{\finalandcomma}{}\addspace\&\space}
\renewcommand*\nameyeardelim{\addspace}
\DefineBibliographyStrings{english}{citedas={hereafter}}
\begin{document}
\pagestyle{empty}\parindent0em\relax
\textcite{4}\citereset\par
\textcite{1, 4}\citereset\par
\textcite{4, 7}\citereset\par
\textcite{1, 2, 4}\citereset\par
\textcite{1, 4, 5}\citereset\par
\textcite{2, 4, 7}\citereset\par
\textcite{4, 5, 7}\citereset\par
\textcite{1, 2, 3, 4}\citereset\par
\textcite{1, 3, 4, 5}\citereset\par
\textcite{1, 4, 5, 6}\citereset\par
\textcite{2, 3, 4, 7}\citereset\par
\textcite{3, 4, 5, 7}\citereset\par
\textcite{4, 5, 6, 7}\citereset\par
\textcite{1, 2, 3, 4, 7}\citereset\par
\textcite{1, 3, 4, 5, 7}\citereset\par
\textcite{1, 4, 5, 6, 7}\citereset\newpage
\parencite{4}\citereset\par
\parencite{1, 4}\citereset\par
\parencite{4, 7}\citereset\par
\parencite{1, 2, 4}\citereset\par
\parencite{1, 4, 5}\citereset\par
\parencite{2, 4, 7}\citereset\par
\parencite{4, 5, 7}\citereset\par
\parencite{1, 2, 3, 4}\citereset\par
\parencite{1, 3, 4, 5}\citereset\par
\parencite{1, 4, 5, 6}\citereset\par
\parencite{2, 3, 4, 7}\citereset\par
\parencite{3, 4, 5, 7}\citereset\par
\parencite{4, 5, 6, 7}\citereset\par
\parencite{1, 2, 3, 4, 7}\citereset\par
\parencite{1, 3, 4, 5, 7}\citereset\par
\parencite{1, 4, 5, 6, 7}\newpage
\textcite{4}\par
\textcite{1, 4}\par
\textcite{4, 7}\par
\textcite{1, 2, 4}\par
\textcite{1, 4, 5}\par
\textcite{2, 4, 7}\par
\textcite{4, 5, 7}\par
\textcite{1, 2, 3, 4}\par
\textcite{1, 3, 4, 5}\par
\textcite{1, 4, 5, 6}\par
\textcite{2, 3, 4, 7}\par
\textcite{3, 4, 5, 7}\par
\textcite{4, 5, 6, 7}\par
\textcite{1, 2, 3, 4, 7}\par
\textcite{1, 3, 4, 5, 7}\par
\textcite{1, 4, 5, 6, 7}\newpage
\parencite{4}\par
\parencite{1, 4}\par
\parencite{4, 7}\par
\parencite{1, 2, 4}\par
\parencite{1, 4, 5}\par
\parencite{2, 4, 7}\par
\parencite{4, 5, 7}\par
\parencite{1, 2, 3, 4}\par
\parencite{1, 3, 4, 5}\par
\parencite{1, 4, 5, 6}\par
\parencite{2, 3, 4, 7}\par
\parencite{3, 4, 5, 7}\par
\parencite{4, 5, 6, 7}\par
\parencite{1, 2, 3, 4, 7}\par
\parencite{1, 3, 4, 5, 7}\par
\parencite{1, 4, 5, 6, 7}
\end{document}
Bravo & Charlie (2004, hereafter Paper I)
Alpha & Bravo (2001) and Bravo & Charlie (2004, hereafter Paper I)
Bravo & Charlie (2004, hereafter Paper I) and Charlie & Delta (2007)
Alpha & Bravo (2001) and Bravo & Charlie (2002, 2004, hereafter Paper I)
Alpha & Bravo (2001) and Bravo & Charlie (2004, hereafter Paper I, 2005)
Bravo & Charlie (2002, 2004, hereafter Paper I) and Charlie & Delta (2007)
Bravo & Charlie (2004, hereafter Paper I, 2005) and Charlie & Delta (2007)
Alpha & Bravo (2001) and Bravo & Charlie (2002, 2003, 2004, hereafter Paper I)
Alpha & Bravo (2001) and Bravo & Charlie (2003, 2004, hereafter Paper I, 2005)
Alpha & Bravo (2001) and Bravo & Charlie (2004, hereafter Paper I, 2005, 2006)
Bravo & Charlie (2002, 2003, 2004, hereafter Paper I) and Charlie & Delta (2007)
Bravo & Charlie (2003, 2004, hereafter Paper I, 2005) and Charlie & Delta (2007)
Bravo & Charlie (2004, hereafter Paper I, 2005, 2006) and Charlie & Delta (2007)
Alpha & Bravo (2001), Bravo & Charlie (2002, 2003, 2004, hereafter Paper I), and Charlie & Delta (2007)
Alpha & Bravo (2001), Bravo & Charlie (2003, 2004, hereafter Paper I, 2005), and Charlie & Delta (2007)
Alpha & Bravo (2001), Bravo & Charlie (2004, hereafter Paper I, 2005, 2006), and Charlie & Delta (2007)

(Bravo & Charlie 2004, hereafter Paper I)
(Alpha & Bravo 2001; Bravo & Charlie 2004, hereafter Paper I)
(Bravo & Charlie 2004, hereafter Paper I; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2002, 2004, hereafter Paper I)
(Alpha & Bravo 2001; Bravo & Charlie 2004, hereafter Paper I, 2005)
(Bravo & Charlie 2002, 2004, hereafter Paper I; Charlie & Delta 2007)
(Bravo & Charlie 2004, hereafter Paper I, 2005; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2002, 2003, 2004, hereafter Paper I)
(Alpha & Bravo 2001; Bravo & Charlie 2003, 2004, hereafter Paper I, 2005)
(Alpha & Bravo 2001; Bravo & Charlie 2004, hereafter Paper I, 2005, 2006)
(Bravo & Charlie 2002, 2003, 2004, hereafter Paper I; Charlie & Delta 2007)
(Bravo & Charlie 2003, 2004, hereafter Paper I, 2005; Charlie & Delta 2007)
(Bravo & Charlie 2004, hereafter Paper I, 2005, 2006; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2002, 2003, 2004, hereafter Paper I; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2003, 2004, hereafter Paper I, 2005; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2004, hereafter Paper I, 2005, 2006; Charlie & Delta 2007)

Paper I
Alpha & Bravo (2001) and Paper I
Paper I and Charlie & Delta (2007)
Alpha & Bravo (2001), Bravo & Charlie (2002), and Paper I
Alpha & Bravo (2001), Paper I, and Bravo & Charlie (2005)
Bravo & Charlie (2002), Paper I, and Charlie & Delta (2007)
Paper I, Bravo & Charlie (2005), and Charlie & Delta (2007)
Alpha & Bravo (2001), Bravo & Charlie (2002, 2003), and Paper I
Alpha & Bravo (2001), Bravo & Charlie (2003), Paper I, and Bravo & Charlie (2005)
Alpha & Bravo (2001), Paper I, and Bravo & Charlie (2005, 2006)
Bravo & Charlie (2002, 2003), Paper I, and Charlie & Delta (2007)
Bravo & Charlie (2003), Paper I, Bravo & Charlie (2005), and Charlie & Delta (2007)
Paper I, Bravo & Charlie (2005, 2006), and Charlie & Delta (2007)
Alpha & Bravo (2001), Bravo & Charlie (2002, 2003), Paper I, and Charlie & Delta (2007)
Alpha & Bravo (2001), Bravo & Charlie (2003), Paper I, Bravo & Charlie (2005), and Charlie & Delta (2007)
Alpha & Bravo (2001), Paper I, Bravo & Charlie (2005, 2006), and Charlie & Delta (2007)

(Paper I)
(Alpha & Bravo 2001; Paper I)
(Paper I; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2002; Paper I)
(Alpha & Bravo 2001; Paper I; Bravo & Charlie 2005)
(Bravo & Charlie 2002; Paper I; Charlie & Delta 2007)
(Paper I; Bravo & Charlie 2005; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2002, 2003; Paper I)
(Alpha & Bravo 2001; Bravo & Charlie 2003; Paper I; Bravo & Charlie 2005)
(Alpha & Bravo 2001; Paper I; Bravo & Charlie 2005, 2006)
(Bravo & Charlie 2002, 2003; Paper I; Charlie & Delta 2007)
(Bravo & Charlie 2003; Paper I; Bravo & Charlie 2005; Charlie & Delta 2007)
(Paper I; Bravo & Charlie 2005, 2006; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2002, 2003; Paper I; Charlie & Delta 2007)
(Alpha & Bravo 2001; Bravo & Charlie 2003; Paper I; Bravo & Charlie 2005; Charlie & Delta 2007)
(Alpha & Bravo 2001; Paper I; Bravo & Charlie 2005, 2006; Charlie & Delta 2007)
  • Would it be possible to provide a short MWE of what you have so far along with a few example entries? That way you can ensure that we actually have something to play around with that comes close to what you use at your end. – moewe Jun 9 '16 at 6:47
2

Unfortunately, -comp styles are often a bit ugly to modify (one ends up with many lines of codes even for relatively trifling changes).

The modification needed for the cite bibmacro, however, is straightforward. Replace the test \iffieldundef{shorthand} by \ifboolexpr{test {\iffieldundef{shorthand}} or not test {\ifciteseen}} and add \usebibmacro{shorthandintro} to the end of the non-shorthand blocks.

Since you want slightly different \textcite citations we had to restructure that macro a bit. The shorthand logic was moved up a few nesting levels.

In order to get textcitecount and friends right, we also had to modify the \textcite cite command a bit.

We then also modify the shorthandintro macro to fit your wishes.

The relevant code in the MWE below is the bit between \makeatletter/\makeatother. Note that you need to enable the citetracker feature for this to work.

\documentclass{article}
\usepackage[style=authoryear-comp, backend=biber, citetracker]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{1,
  author    = "Alpha, A. and Bravo, B.",
  year      = "2000"
}
@article{2,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2001"
}
@article{3,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2002",
  shorthand = "Paper I"
}
@article{4,
  author    = "Bravo, B. and Charlie, C.",
  year      = "2003"
}
@article{5,
  author    = "Charlie, C. and Delta, D.",
  year      = "2004"
}
\end{filecontents}
\addbibresource{\jobname.bib}
\renewcommand*\finalnamedelim
  {\ifbibliography{\finalandcomma}{}\addspace\&\space}
\renewcommand*\nameyeardelim{\addspace}
\DefineBibliographyStrings{english}{citedas={hereafter}}

\makeatletter
\renewbibmacro*{cite}{%
  \ifboolexpr{test {\iffieldundef{shorthand}} or not test {\ifciteseen}}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}%
        \usebibmacro{cite:labelyear+extrayear}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                       \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
             {\setunit{\addcomma}%
              \usebibmacro{cite:extrayear}}
             {\setunit{\compcitedelim}%
              \usebibmacro{cite:labelyear+extrayear}%
              \savefield{labelyear}{\cbx@lastyear}}}
          {\printnames{labelname}%
           \setunit{\printdelim{nameyeardelim}}%
           \usebibmacro{cite:labelyear+extrayear}%
           \savefield{namehash}{\cbx@lasthash}%
           \savefield{labelyear}{\cbx@lastyear}}}%
    \usebibmacro{shorthandintro}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}

\renewbibmacro*{textcite}{%
  \ifboolexpr{test {\iffieldundef{shorthand}} or not test {\ifciteseen}}
    {\iffieldequals{namehash}{\cbx@lasthash}
       {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                      \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
            {\setunit{\addcomma}%
             \usebibmacro{cite:extrayear}}
            {\setunit{\compcitedelim}%
             \usebibmacro{cite:labelyear+extrayear}%
             \savefield{labelyear}{\cbx@lastyear}}}
        {\ifnameundef{labelname}
           {\usebibmacro{cite:label}%
            \setunit{%
              \global\booltrue{cbx:parens}%
              \printdelim{nonameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
              {\usebibmacro{prenote}}
              {}%
            \usebibmacro{cite:labelyear+extrayear}}
           {\printnames{labelname}%
            \setunit{%
              \global\booltrue{cbx:parens}%
              \printdelim{nameyeardelim}\bibopenparen}%
            \ifnumequal{\value{citecount}}{1}
              {\usebibmacro{prenote}}
              {}%
            \iffieldundef{labelyear}
               {\usebibmacro{cite:label}}
               {\usebibmacro{cite:labelyear+extrayear}}%
             \savefield{labelyear}{\cbx@lastyear}}%
         \stepcounter{textcitecount}}%
     \usebibmacro{shorthandintro}%
     \savefield{namehash}{\cbx@lasthash}}
    {\usebibmacro{cite:shorthand}%
     \stepcounter{textcitecount}%
     \global\undef\cbx@lasthash
     \global\undef\cbx@lastyear}%
    \setunit{%
      \ifbool{cbx:parens}
        {\bibcloseparen\global\boolfalse{cbx:parens}}
        {}%
      \textcitedelim}}

\renewbibmacro*{shorthandintro}{%
  \iffieldundef{shorthandintro}
    {\iffieldundef{shorthand}
       {}
       {\setunit{\addcomma\space}%
        \printtext{%
          \bibstring{citedas}\space
          \printfield{shorthand}}}}
    {\setunit{\addcomma\space}%
     \printtext{\printfield{shorthandintro}}}}

%\iffieldequals{namehash}{\cbx@lasthash}{N}{}\ifciteseen{S}{}\iffieldundef{shorthand}{U}{}
\DeclareCiteCommand{\textcite}[\cbx@textcite@init\cbx@textcite]
  {\gdef\cbx@savedkeys{}%
   \citetrackerfalse%
   \pagetrackerfalse%
   \DeferNextCitekeyHook%
   \usebibmacro{cite:init}}
  {\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}
     {\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
      \global\clearfield{multipostnote}}
     {}%
   \xappto\cbx@savedkeys{\thefield{entrykey},}%
   \citetrackertrue
   \ifboolexpr{not test {\iffieldequals{namehash}{\cbx@lasthash}} or (not test {\iffieldundef{shorthand}} and test {\ifciteseen}) }
     {\stepcounter{textcitetotal}%
      \savefield{namehash}{\cbx@lasthash}%
      \ifboolexpr{not test {\iffieldundef{shorthand}} and test {\ifciteseen}}
        {\global\undef\cbx@lasthash}{}}
     {}%
   \citetrackerfalse}
  {}
  {\protected@xappto\cbx@savedcites{%
     [\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}
\makeatother


\begin{document}
\parindent0em\relax
\textcite{3}\citereset\par
\textcite{3, 5}\citereset\par
\textcite{3, 4, 5}\citereset\par
\textcite{2, 3, 5}\citereset\par
\textcite{1, 3}\citereset\vskip\bigskipamount
\parencite{3}\citereset\par
\parencite{3, 5}\citereset\par
\parencite{3, 4, 5}\citereset\par
\parencite{2, 3, 5}\citereset\par
\parencite{1, 3}\vskip\bigskipamount
\textcite{3}\par
\textcite{3, 5}\par
\textcite{3, 4, 5}\par
\textcite{2, 3, 5}\par
\textcite{1, 3}\vskip\bigskipamount
\parencite{3}\par
\parencite{3, 5}\par
\parencite{3, 4, 5}\par
\parencite{2, 3, 5}\par
\parencite{1, 3}
\end{document}

four example blocks from OP

  • Thanks! I've tested your fix: it works for all parenthesized citations, but not for subsequent text citations. Using the example you've supplied, I would expect "KpV" on the second line instead of "Kant (KpV)". – photon.engine Jun 9 '16 at 19:44
  • @photon.engine I have modified the textcite macro to hopefully give the expected output now. Have a look at the edited answer and let me know. – moewe Jun 10 '16 at 4:54
  • This however seems to mess up the "and" connective between multiple groups of authors; for example, in line 2, one would expect "KpV and Sigfridsson & Ryde (1998)". Let me see if I can't understand the code and make a change. – photon.engine Jun 10 '16 at 15:52
  • @photon.engine Ah yes, that required some more work in the innards of the texcite system. Try the edited version and let me know if it works for you, please. – moewe Jun 11 '16 at 5:43
  • Thank you for the heroic effort! There are a few edge cases missed out (see my edit above), but they are sufficiently artificial that one may never reasonably encounter them, so I'll mark your answer as accepted. Of course you're more than welcome to take a shot at those weird cases :) – photon.engine Jun 11 '16 at 15:14

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.