1

I am wondering if it is possible to turn off the effects of \DeclareSourceMap part way through a tex document. Any tips on how to do this?


Here is some more information on the situation I am in. I am trying to get a unique citation style to work, which is based around biblatex:

\usepackage[backend=biber,bibstyle=nature,citestyle=authoryear,maxcitenames=2,maxbibnames=99,uniquelist=false,sorting=ydnt]{biblatex}

I use the following to add the journal name to the authoryear cite style:

% add journal name to inline citation
\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
       {\printnames{labelname}%
        \setunit{\printdelim{nameyeardelim}}}%
     \setunit{\addcomma\space}%
     \usebibmacro{journal}
     \setunit{\addcomma\space}%
     \usebibmacro{cite:labeldate+extradate}}%
    {\usebibmacro{cite:shorthand}}}

Finally, I use \DeclareSourceMap to shorted journal titles in the text. The result is as desired, which is references showing up as [Doe RSI 2006] when cited in the text.

HOWEVER, I would like to turn off the shortening of journal titles when I actually print the bibliography at the end of the document using \printbibliography. At the moment, my bibliography looks like:

Doe, A. B. & Smith, J. S. A journal article with a cool title. RSI (2006).

I would like the bibliography to look like this:

Doe, A. B. & Smith, J. S. A journal article with a cool title. Review of Scientific Instruments (2006).

But I need to preserve the citation formatting in the text as explained above.

Is there a way to turn off the effects of \DeclareSourceMap directly before the \printbibliography call?

Thanks for your help.


A MWE is included below:

\documentclass{article}

\usepackage[backend=biber,bibstyle=nature,citestyle=authoryear,maxcitenames=2,maxbibnames=99,uniquelist=false,sorting=ydnt]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{mybibfile.bib}
    @article{file,
    author = {Doe, A. B. and Smith, J. S. and Author, G. B.},
    title = {A journal article with a cool title},
    journal = {Review of Scientific Instruments},
    year = {2006}
    }
\end{filecontents}

\addbibresource{mybibfile.bib}

% add journal name to inline citation
\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
      {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
      {\printnames{labelname}%
        \setunit{\printdelim{nameyeardelim}}}%
     \setunit{\addcomma\space}%
     \usebibmacro{journal}
     \setunit{\addcomma\space}%
     \usebibmacro{cite:labeldate+extradate}}%
    {\usebibmacro{cite:shorthand}}}

% abbreviate journal names
\DeclareSourcemap{
 \maps[datatype=bibtex,overwrite=true]{
  \map{
    \step[fieldsource=journal,
          match=\regexp{Review\sof\sScientific\sInstruments},
          replace={RSI}]
  }
 }
}

\begin{document}

This works as intended: \parencite{file}

This does not work as intended: 
\printbibliography
\end{document}
3
  • Generally speaking, a sourcemap directly manipulates the data when it is read from the .bib file. Any changes you make are as if you made them yourself directly in the .bib file. If you shorten the journaltitle field and don't save the original field value there is no way to get them back on the biblatex side.
    – moewe
    Nov 15, 2020 at 7:10
  • It would be much, much easier to help you if you could embed the code snippets shown so far into a fully compilable example document (ideally with one or two example .bib entries). At the moment we have to rebuild a lot of stuff to get started helping you. Please consider adding a so-called MWE to your question (tex.meta.stackexchange.com/q/228/35864, tex.meta.stackexchange.com/q/4407/35864).
    – moewe
    Nov 15, 2020 at 7:13
  • Hi @moewe, thanks for responding to the question! I've added a MWE to the main text. Is there a convenient way to store the original field value with \DeclareSourceMap so that it can recovered later?
    – Oak Nelson
    Nov 15, 2020 at 23:33

1 Answer 1

2

biblatex ojffers the field shortjournal (not used by standard style), so what you can do is to set the value of the shortjournal and use shortjournal in the citation. This can be achieved by using \printfield{shortjournal} instead of \usebibmacro{journal} in the definition of \cite

\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
      {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
      {\printnames{labelname}%
        \setunit{\printdelim{nameyeardelim}}}%
     \setunit{\addcomma\space}%
     \printfield{shortjournal} % changed line
     \setunit{\addcomma\space}%
     \usebibmacro{cite:labeldate+extradate}}%
    {\usebibmacro{cite:shorthand}}}

and a \DeclareSourceMap that add a value for shortjournal

\DeclareSourcemap{
 \maps[datatype=bibtex,overwrite=true]{
  \map{
    \step[fieldsource=journal,
          match=\regexp{Review\sof\sScientific\sInstruments},
          fieldset=shortjournal,
          fieldvalue={RSI}]
  }
 }
}

The two changes above yield:

enter image description here

1
  • Thanks this is great! There is a small type in your answer - it should be \printfield{shortjournal}. With this correction it works great!
    – Oak Nelson
    Nov 16, 2020 at 3:24

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.