5

This question is basically a duplicate of Error with percent sign in bib entry field when using biblatex/biber, however the accepted solution (biber configuration file set to skip the abstract field entirely) does not satisfy me and the question is a bit old so maybe something changed.

On the one hand, I would like to be able to use the abstract field if needed; on the other hand, export tools of some editors routinely include an unescaped "%" in abstracts. Is there a way around this that does not involve replacements in .bib files by hand or by an external software?

(BTW, I fail to see how biber can skip the abstract field even if it contains a "%", which proves that at some point it is not in LateX-mode of "ignore the comments", but cannot escape it reliably - that's purely for curiosity, but since I'm asking...)

MWE if needed: (the first pdflatex and biber compilations will work, for a successive pdflatex will fail with "Runaway argument?")

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{filecontents}

\begin{filecontents}{biblio.bib}
@article{key1,
    author="Ann Onymous",  
    journal="Some journal",  
    title="Title",  
    year="2017",  
    abstract={This abstract will fail because of an unescaped percent sign:
        10\% is fine, 10% is not.},  
    }
\end{filecontents}
\usepackage[backend=biber]{biblatex}
\addbibresource{biblio.bib}

\begin{document}
    Citation: \parencite{key1}.

    \printbibliography
\end{document}
2
  • 6
    Rule of thumb: downloaded database entries are never to be trusted and need manual checking. Handling percent sign within this procedure is not time consuming.
    – Johannes_B
    Feb 8, 2017 at 9:28
  • 2
    @Johannes_B really hits the nail on the head -- we have quite a few questions that boil down to downloaded bib file is broken in a predictable way. This is one of the reasons why I recommend managing bibfiles with a good programmers's text editor. For example in your case I could just find ([0-9.]+)% and replace with $1\\% (regular expressions) to escape an unescaped percent sign if it follows digits or decimal points. This wouldn't deal with things like "x%", neither would it handle "10 %". Either of these cases could be fixed easily.
    – Chris H
    Feb 8, 2017 at 9:52

1 Answer 1

6

biber is almost never in "LaTeX Mode". It is perl programm. It is easy for it to remove the complete entry. biber also doesn't choke on the %. But if it doesn't ignore it the whole entry ends up in a file processed by LaTeX. And then LaTeX chokes.

You can use a sourcemap to replace a % by \%. But imho it doesn't make much sense. If you want to use the abstract in LaTeX then you will have to go through the text anyway to check and correct the typesetting and change e.g. - to -- or a path like C:\documents.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{filecontents}

\begin{filecontents}{biblio.bib}
@article{key1,
    author="Ann Onymous",
    journal="Some journal",
    title="Title",
    year="2017",
    abstract={This abstract will fail because of an unescaped percent sign:
        10\% is fine, 10% is not.},
    }
\end{filecontents}
\usepackage[backend=biber]{biblatex}
\addbibresource{biblio.bib}

\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{
       \step[fieldsource = abstract,
          match = \regexp{([^\\])\%},
          replace = \regexp{$1\\\%}]
    }
  }
}


\begin{document}
    Citation: \parencite{key1}.

    \printbibliography
\end{document}
4
  • 1
    "You can use a sourcemap to replace a % by \%. But imho it doesn't make much sense." May I ask why? If I don't want to touch the .bib files themselves, that looks like a great option.
    – JM114516
    Feb 10, 2017 at 17:49
  • 1
    @JM114516: I said why in the next sentence. I agree with Chris in the comment above that every bib entry should be checked and corrected before use anyway. Feb 10, 2017 at 17:54
  • Why it does not make sense to replace % with \% on bib files using this DeclareSourcemap?
    – user
    May 16, 2019 at 1:33
  • 1
    @user because it is much better to correct the bib once and for all instead of doing it again and again at every compilation and in every document. May 16, 2019 at 7:11

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.