Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional append in sourcemap? #251

Closed
moewew opened this issue Jan 28, 2019 · 5 comments
Closed

Conditional append in sourcemap? #251

moewew opened this issue Jan 28, 2019 · 5 comments

Comments

@moewew
Copy link
Contributor

moewew commented Jan 28, 2019

Consider the following MWE where the value of a field fpp is appended to the note field. In appleby the note field is already populated and things go smoothly, but in hacker the field is not existent and so we end up with a leading comma. Additionally biber --trace is unhappy

Use of uninitialized value $orig in concatenation (.) or string at C:\Users\Moritz\AppData\Local\Temp\par-4d6f7269747a\cache-b499addb80b3706a003bc9fcde51a97832c83aee\inc\lib/Biber/Input/file/bibtex.pm line 806.
Use of uninitialized value $orig in concatenation (.) or string at C:\Users\Moritz\AppData\Local\Temp\par-4d6f7269747a\cache-b499addb80b3706a003bc9fcde51a97832c83aee\inc\lib/Biber/Input/file/bibtex.pm line 808.
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}


\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=foo, final]
      \step[fieldset=note, fieldvalue={,}, append]
      \step[fieldset=note, origfieldval, append]
    }
  }
}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{appleby,
  author    = {Humphrey Appleby},
  title     = {On the Importance of the Civil Service},
  date      = {1980},
  foo       = {A},
  note      = {foo,bar},
}
@book{hacker,
  author    = {James Hacker},
  title     = {On the Importance of the Civil Service},
  date      = {1981},
  foo       = {B},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\DeclareFieldFormat{note}{\mkbibbold{#1}}

\begin{document}
\cite{appleby,hacker}
\printbibliography
\end{document}

It is possible to work around this issue with a more clunky definition such as

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=note, final]
      \step[fieldsource=foo, final]
      \step[fieldset=note, fieldvalue={,}, append]
      \step[fieldset=note, origfieldval, append]
    }
    \map{
      \step[fieldsource=foo, final]
      \step[fieldset=note, origfieldval, append]
    }
  }
}

See also https://tex.stackexchange.com/q/420294/35864
But that feels a bit awkward and repetitive.

  1. Would it be possible to add a new kind of append keyword condappend (or appendifnonempty or appendifexists ...) or similar that only appends its value if the field exists already?
  2. Would it be possibly to make append slightly more robust against non-existing fields, so that biber --trace does not have to complain?
plk added a commit to plk/biblatex that referenced this issue Jan 29, 2019
plk added a commit that referenced this issue Jan 29, 2019
@plk
Copy link
Owner

plk commented Jan 29, 2019

Bug fixed and new option appendstrict implemented which only appends to non-empty fields.

@moewew
Copy link
Contributor Author

moewew commented Jan 29, 2019

The warning is gone, but there seems to be an issue with appendstrict. In the following MWE it produces

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}


\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=foo, final]
      \step[fieldset=note, fieldvalue={,}, appendstrict]
      \step[fieldset=note, origfieldval, append]
    }
  }
}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{appleby,
  author    = {Humphrey Appleby},
  title     = {On the Importance of the Civil Service},
  date      = {1980},
  foo       = {A},
  note      = {foo,bar},
}
@book{hacker,
  author    = {James Hacker},
  title     = {On the Importance of the Civil Service},
  date      = {1981},
  foo       = {B},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\DeclareFieldFormat{note}{\mkbibbold{#1}}

\begin{document}
\nocite{appleby,hacker}
\printbibliography
\end{document}

Appleby, Humphrey (1980). On the Importance of the Civil Service. ,A.
Hacker, James (1981). On the Importance of the Civil Service. ,B.

while I would hope for

Appleby, Humphrey (1980). On the Importance of the Civil Service. foo,bar,A.
Hacker, James (1981). On the Importance of the Civil Service. B.

It seems that appendstrict clears out the existing value before it appends and that it still applies even if the set-field is empty.

@plk
Copy link
Owner

plk commented Jan 29, 2019

Hmm, I have a nasty feeling I uploaded the wrong biber version then, this was what happened while developing it ... checking.

@plk
Copy link
Owner

plk commented Jan 29, 2019

Can you try this again with the latest biblatex/biber? Your example works fine for me now.

@moewew
Copy link
Contributor Author

moewew commented Jan 29, 2019

The MWE and another example I tried work as hoped and expected now. Thank you.

@plk plk closed this as completed Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants