# Case protection with emphasis in biblatex

Following the question What is the proper casing to use when storing titles in the bibliography database? I am storing titles in Title Case in the .bib file and {Protecting} proper nouns etc. I had been using biblatex-chicago so far where I didn't run into any problems, as Chicago mandates Title Case anyways.

But now I am running into trouble with biblatex-apa – APA prefers sentence casing – with quotation marks and emphasis. Since \mkbibquote{} and \mkbibemph{} already case-protect what's inside, enclosing them in an extra set of braces {\mkbibquote{}} un-case-protects them. But then, I'm having a number of problems.

Consider this MWE:

% !TEX TS-program = xelatexmk
\documentclass{article}

\usepackage{polyglossia}
\setdefaultlanguage[variant=american]{english}
\usepackage{csquotes}
\usepackage[style=apa]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{bib.bib}

@book{Author2000,
Title = {This is a Title with Something in {\mkbibquote{Quotes that Should Be Downcased}}},
Author = {Author, Anton},
Date = {1990},
}
@book{Author2000a,
Title = {{\mkbibquote{But if the Title starts in Quotes}} It Turns into All Caps},
Author = {Author, Anton},
Date = {2000},
}
@book{Author2000b,
Title = {A Discussion of the Book {\mkbibemph{{My} New Book}}: It Should Keep the First Word Capitalized},
Author = {Author, Anton},
Date = {2010},
}
@book{Author2000c,
Title = {{\mkbibemph{And if the Title starts with Emphasis}} It also Turns into All Caps and Doesn't Apply the Emphasis},
Author = {Author, Anton},
Date = {2001},
}
@book{Author2000d,
Title = {And If {\mkbibquote{an Acronym {{{AAEE}}} is Included}}, How to Preserve it?},
Author = {Author, Anton},
Date = {2011},
}

\end{filecontents}

\begin{document}
\autocites{Author2000,Author2000a,Author2000b,Author2000c,Author2000d}
\printbibliography % print the bibliography
\end{document}


It gives this output:

There are numerous problems. If mkbibquote or mkbibemph are issued at the beginning of the string, then it turns the entire string into ALL CAPS. Also I have no idea how to protect specific words within a string that is already enclosed by mkbibquote or mkbibemph.

The sentence casing function for biblatex is implemented in LaTeX. BibTeX's sentence casing, on the other hand, is implemented in BibTeX directly. That means that there are some subtle and not so subtle differences between the two. In particular biblatex's sentence case function will try to expand macros if possible.

The major issue here is that curly braces are overloaded with meaning: For LaTeX they serve as argument delimiters or apply grouping; for BibTeX they protect strings from case change and mark up LaTeX macros for non-ASCII characters such as ä -> {\"a} (cf. How to write “ä” and other umlauts and accented letters in bibliography?). The different meanings clash from time to time, in those cases workaround are needed to resolve the issue.

For the use cases you show in the MWE I can offer the following workaround. The idea is to get around using braces by using delimited arguments (a sort of \foo <argument>\endfoo syntax). Delimited arguments come with their own issues when they are nested, but they work well enough in the MWE.

\documentclass{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage[style=apa]{biblatex}

\protected\def\horriblemkbibquote#1\endhorriblemkbibquote{\mkbibquote{#1}}
\let\endhorriblemkbibquote\relax
\protected\def\horriblemkbibemph#1\endhorriblemkbibemph{\mkbibemph{#1}}
\let\endhorriblemkbibemph\relax

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Author2000,
title  = {This is a Title with Something in {\mkbibquote{Quotes that Should Be Downcased}}},
author = {Author, Anton},
date   = {1990},
}
@book{Author2000a,
title = {\horriblemkbibquote {But} if the Title starts in Quotes\endhorriblemkbibquote{} It Turns into All Caps},
author = {Author, Anton},
date = {2000},
}
@book{Author2000b,
title = {A Discussion of the Book \horriblemkbibemph{My} New Book\endhorriblemkbibemph{}: It Should Keep the First Word Capitalized},
author = {Author, Anton},
date = {2010},
}
@book{Author2000c,
title = {\horriblemkbibemph {And} if the Title starts with Emphasis\endhorriblemkbibemph{} It also Turns into All Caps and Doesn't Apply the Emphasis},
author = {Author, Anton},
date = {2001},
}
@book{Author2000d,
title = {And If \horriblemkbibquote an Acronym {AAEE} is Included\endhorriblemkbibquote{}, How to Preserve it?},
author = {Author, Anton},
date = {2011},
}

\end{filecontents}

\begin{document}
\autocites{Author2000,Author2000a,Author2000b,Author2000c,Author2000d}
\printbibliography % print the bibliography
\end{document}


In the long run the desirable solution seems to me to implement a new case changing function that uses a different markup to specify the protected strings, so that curly braces don't clash with it any more.

FWIW BibTeX's case change function has similar issues. It doesn't capitalise words at the beginning of the string, so it does not suffer from the ALL-CAPS issue, but the other two protect-within-unprotect issues are also present.

• +1: \horriblemkbibquote:) – Dr. Manuel Kuehner Feb 25 at 8:50
• Awesome, thank you! Just out of curiosity (I also read the github thread you linked to): When you mention a solution in the long run, would that mean that the markup for protecting strings would change? As that would, of course, require considerable .bib database updates ... – jan Feb 25 at 14:26
• @jan I guess it would have to mean that, yes. With the current syntax where braces are just too overloaded with meaning I can't see a way to make every (legitimate) use case working properly. Even mild changes to the way the macro works at the moment (for example adding a rule to unprotect strings by adding more braces) has the potential to break people's code (some exporters use a lot of braces already) and the syntax would still be awful. So if we could start over with a new syntax that would be best. I currently have no plans to do anything about this ... – moewe Feb 25 at 14:33
• ... and while Joseph said he might look at this at some point, I don't think it is going to be anytime soon. Clearly, if we decide to go for something new that works properly we need to think about backwards compatibility. So for the time being I don't expect any changes. This really is a long-term goal/nice-to-have. – moewe Feb 25 at 14:35
• @jan Well, the delimited argument syntax of \horriblemkbibquote is not really LaTeX-y, in LaTeX one usually has mandatory arguments in {...} and optional arguments in [...]. Additionally, nesting will not work properly with delimited arguments. – moewe Feb 26 at 5:50