3

I have a bibliography file which contains definitions in the journal name field, for example \pra, and I define this in my file as \def \pra {Phys. Rev. A}, which is what I want for my bibliography.

Now I would also like to be able to have a command like \citearticleshort or something, which would insert a shorthand for the journal name, for example PRA in this case, plus volume number and possibly page.

How can I get \pra to expand to Phys. Rev. A in one case and PRA in another case? I saw there is something like mapping in biblatex, but I couldn't figure out how to use it to solve my problem.

Mico
  • 506,678
fifaltra
  • 1,977
  • Mapping probably won't help you (as mapping changes a field permanently for biblatex), but biblatex provides \ifcitation and \ifbibliography that are true only if we are currently in a citation or in the bibliography, respectively. So you might do \newcommand*{\pra}{\ifcitation{PRA}{Phys. Rev. A}}. Of course you also might use a completely custom toggle here, but then you need to be more specific as to when what is to appear. (Not tested for lack of an MWE.) – moewe Feb 23 '15 at 07:15
  • that does exactly what I want! thanks a lot. If you convert your comment into an answer, I'll accept it – fifaltra Feb 23 '15 at 07:39

1 Answers1

3

biblatex has the \ifcitation and \ifbibliography tests to check whether we are in a citation or the bibliography, respectively.

In your case, we might define \pra as

\newcommand*{\pra}{%
  \ifcitation
    {PRA}
    {Phys. Rev. A}}

such that \pra expands to "PRA" in a citation and to "Phys. Rev. A" everywhere else (especially in the bibliography).

MWE

\documentclass{article}
\usepackage[style=authoryear,backend=biber]{biblatex}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{pra,
  author = {Anne Uthor},
  title = {Title},
  journal = {\pra},
  year = {2008},
  volume = {15},
  number = {7},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\newcommand*{\pra}{\ifcitation{PRA}{Phys. Rev. A}}

\begin{document}
\fullcite{pra}

\printbibliography
\end{document}

enter image description here

moewe
  • 175,683