# Why does not MakeSentenceCase work with escaped math accents in bibliography titles?

I read here that if I want to automatically adjust capitalization for titles, I could use \DeclareFieldFormat[article]{titlecase}{\MakeSentenceCase{#1}}. However this breaks compilation.

Here is a somewhat minimal example

\documentclass{article}
\usepackage{biblatex}
\usepackage{accents}
\DeclareFieldFormat[article]{titlecase}{\MakeSentenceCase{#1}} %%% <- offending line
\usepackage{filecontents}
\begin{filecontents}{test.bib}
@article{A01,
author = {Author, A.},
year = {2001},
title = {Alpha: {$Q_t=H\left(\underaccent{\leftarrow}S,\underaccent{\leftarrow}R,\Delta_t\right)A$}},
journaltitle = {Some journ.}
}
\end{filecontents}

\begin{document}
Can it survive titlecase \autocite{A01}?

\printbibliography
\end{document}


PDF is not produced at all with offending line uncommented.

EDIT 6/8/2014

What a gaffe. I made a typo while I was moving things around. I had both lines, but I guess I was confused while making a minimal example. Original code still produces some "abstract" error Undefined control sequence and an error like Illegal parameter number in definition of \@tempa. I'd like to "suspend" this question till I clarify the situation. I suspect it is because of math in title, also it is contained within {}.

EDIT 6/9/2014

I updated the sample code. It compiles okay as is unless I uncomment that line with titlecase. Note that math is contained within curly braces.

EDIT 6/10/2014

Example was made lean and mean without unnecessary stuff as per request in comments.

• Why have you substituted title for titlecase? You are not using the declaration specified in the answer you linked to. – cfr Jun 8 '14 at 23:54
• Try \DeclareFieldFormat[article]{titlecase}{\MakeSentenceCase*{#1}} instead. (I just realised that that is the suggestion in the answer you linked to, why did you change that? You can still have \DeclareFieldFormat[article]{title}{#1} to get rid of the quotation marks.) – moewe Jun 9 '14 at 5:38
• Technically, \MakeSentenceCase should be fine with maths - especially if it is escaped in braces (you will want to escape your maths otherwise the formulae will be converted to sentence case as well and mayhem will ensue). The error "Illegal parameter number in definition of \@tempa" is very hard to investigate without an actual case where it occurs. – moewe Jun 9 '14 at 7:30
• It seems like accent's \underaccent is too much for \MakeSentenceCase to cope. Even escaping does not seem to help. – moewe Jun 9 '14 at 17:58
• You might want to make your example more minimal in light of this: We don't need all the other .bib entries and redefinitions of macros like date+extrayear and changes of bibstrings. – moewe Jun 10 '14 at 5:56

Can it survive? Yes, it can, provided you simplify your input: you should never write explicitly \underaccent{\leftarrow}{S} in your document, but define a macro for it. Since biblatex loads etoolbox, we have \newrobustcmd available, which solves the problem.

\documentclass{article}
\usepackage{biblatex}
\usepackage{accents}

\newrobustcmd{\ula}[1]{\underaccent{\leftarrow}{#1}}

\DeclareFieldFormat[article]{titlecase}{\MakeSentenceCase{#1}} %%% <- offending line
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{A01,
author = {Author, A.},
year = {2001},
title = {Alpha: {$Q_t=H(\ula{S},\ula{R},\Delta_t)A$}},
journaltitle = {Some journ.}
}
\end{filecontents}

I also removed \left and \right not because they cause problems, but because they serve no purpose in that context.