12

How can I enter the following title (of an imaginary book) in a Bib(La)TeX entry: "How to use { in Bib(La)TeX?"

BibTeX suggests that braces can be backslash-escaped, but both BibTeX processor and Biber fail to process the title if entered this way.

@book{test_123,
        title = {How to use \{ in Bib(La)TeX?}
}

Biber produces

INFO - This is Biber 1.9 running in TOOL mode
INFO - Logfile is 'test.bib.blg'
INFO - Looking for bibtex format file 'test.bib'
INFO - Decoding LaTeX character macros into UTF-8
INFO - Found BibTeX data source 'test.bib'
WARN - Entry test_123 does not parse correctly
WARN - BibTeX subsystem: C:\*********\test.bib_5644.utf8, line 3, warning: possible runaway string started at line 2
ERROR - BibTeX subsystem: C:\********\test.bib_5644.utf8, line 4, syntax error: at end of input, expected one of: number, name (entry type, key, field, or macro name) or quoted string ({...} or "...")
INFO - WARNINGS: 2
INFO - ERRORS: 1

This also fails in the "abstract" and "file" fields.

I reported this to the Biber developers and was told that someone here might know a trick. Also, this was previously asked (in a roundabout way I guess) here

Aurimas
  • 253

2 Answers2

8

You can use the \vphantom command to include the closing bracket but not showing it, i.e.

@book{test_123,
    title = {How to use \{\vphantom{\}} in Bib(La)TeX?},
    author = {Vinckevicius, Aurimas}
}

works for me with normal BibTeX and the following tex file:

\documentclass{article}
\begin{document}
\cite{test_123}
\bibliography{references}
\bibliographystyle{alpha}
\end{document}

Here is how it looks:

output pdf

It might be that (vertical) spacing is slightly influenced.

zuphilip
  • 196
  • 3
  • Welcome to TeX.SX! Can you elaborate a little bit on your solution, showing an full example and a screen shot of the output? –  Mar 01 '15 at 12:03
  • Okay, I added a minimal LaTeX example, link to some documentation and a picture of the output. – zuphilip Mar 01 '15 at 12:35
3

Apparently, Biber knows about \textbraceleft and tries to translate it into a brace, which kills it. :(

Here's a workaround:

\begin{filecontents*}{\jobname.bib}
@article{testbrace,
  author={A. Uthor},
  title={How to use {\biberbraceleft} with Bib(La)\TeX?},
  journal={Trans. \TeX.SX},
  year={2015},
  pages={1-10},
}
\end{filecontents*}

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{biblatex}
\addbibresource{\jobname.bib}

\newcommand{\biberbraceleft}{\textbraceleft}

\begin{document}

\fullcite{testbrace}

\end{document}

enter image description here

I made some experiments: with

  title={How to use
    \iftrue\textbraceleft\else\textbraceright\fi
    or
    \iftrue\{\else\}\fi\space with Bib(La)\TeX?},

Biber doesn't complain and writes

  \field{labeltitle}{How to use \iftrue{\else}\fi or \iftrue\{\else\}\fi\space with Bib(La)\TeX?}

so it's evident that there are two problems:

  1. \textbraceleft, which ought to work, writes instead an unescaped {

  2. \{ breaks at Biber processing time, because it's considered as a brace and it's not matched.

A field such as

title={\{Braced\}},

will work, while

title={\textbraceleft Braced\textbraceright},

outputs

\field{title}{{Braced}}

which is clearly a bad bug in Biber.

egreg
  • 1,121,712
  • Ugh. That's unfortunate. Should Biber really be expanding that macro though? I can take this upstream to Biber if that's actually an issue. I'm working on a BibTeX export filter for Zotero, so the above solution, while great, is not really something I can apply. – Aurimas Mar 01 '15 at 11:23
  • @Aurimas Working on it. But using \{ seems out of question. – egreg Mar 01 '15 at 11:37
  • 2
    This was a bug in biber and is fixed in the current DEV branch. \textbraceleft and \textbractright are now excluded from UTF8 decoding (they were already excluded from encoding). \{ is out of the question as it would require changes in the underlying parser. – PLK Mar 01 '15 at 14:14
  • 1
    @PLK Thanks for confirming my suspect. I can understand that working on unbalanced \{ might not be worthy the effort. Maybe a note in the manuals could be added. You could consider about adding something like \providecommand\gobble[1]{} in the LaTeX code, so that an unbalanced braces can be input as \{\gobble\} or \gobble\{\} to keep the parser happy. – egreg Mar 01 '15 at 14:20