3

I am behind Fidus Writer, which is an open source online editor with a Latex export function.

I have recently turned our bib(la)tex importer/exporter into an independent package (link here) that should be usable in other online projects.

There is at least one thing we don't quite seem to be able to figure out: What are the exact rules for case-preservation in biblatex?

We have looked at the biblatex manual, which mentions braces. But as Emiliano Heyns has pointed out, there are circumstances under which said braces do not have this effect. As far as I can tell, the rules are:

  1. One opening brace that is immediately followed by "\", is ignored. The same applies to the corresponding closing brace. So in the following case, the case is not preserved:

    {\textbf{...}}
    

    nor

    {\textbf{...}....}
    
  2. Two opening braces that are followed immediately by \ are honored. So for example here, the case is preserved:

    {{\textbf{...}}}
    

    and

    {{\textbf{...}....}}
    
  3. One opening brace that is followed by anything else than \ is honored. So in this case, the case is preserved:

    {...}
    

    and

    {{...}}
    

    and

    {...\textbf{...}}
    

Are these the exact rules, or is it more complex than this?

moewe
  • 175,683
  • See https://github.com/plk/biblatex/issues/459, https://github.com/plk/biblatex/issues/357, I seem to remember a few questions about biblatex's specific behaviour before, but I can't find them now. – moewe Nov 22 '16 at 17:13
  • Something of an aside, but if you are exporting to a .bib file, you should make sure that you are not 'forcing' (non-)capitalization. It is the .bbx (or .bst) that determines capitalization, not the .bib file, so you should be careful about how you intervene in the conversion process. Ultimately, it is best to write the fields in CamelCase and let the style determine capitalization (excluding, in English, proper nouns). – jon Nov 22 '16 at 21:46
  • I'm also not sure why \textbf would appear in a .bib entry field, but it nesting of emphasis is relatively common (better to use \mkbibemph, however, in biblatex-based .bib files). But rather than fiddle with the very important and useful {\cmd tracker, you could export italics so it is \mkbibemph{{italics}}. But, again, such interventions should be rare.... – jon Nov 22 '16 at 21:52
  • The end using will have a webbased interface on what part of the text she/he wants to apply emphasis, no case change, etc. . The ultimate decision of what it will be capitalized lies with the chosen citation style, but I need to make sure that the exported biblatex file doesn't specify nocase change for a letters where the user only specified emphasis.

    The export ma actually be less problematic, because we can say they only get biblatex export. The problem is the import, as users will probably mix bibtex and biblatex syntax. We may have to guess what the user is trying to achieve.

    – johanneswilm Nov 22 '16 at 21:54
  • 2
    biblatex-only export would simplify things. And people can use Biber to convert from there to a BibTeX-encoded .bib anyway. But if ultimate responsibility of the imported file lies with the user, then maybe double-bracing the argument of the command is the easiest solution to enforce preservation of the original capitalization-in-macros scheme. (... or it may be worth a shot, anyway.) – jon Nov 22 '16 at 21:59

1 Answers1

4

biblatex's case change is - unlike BibTeX's case changing - implemented on the LaTeX level. Unfortunately, this kind of case changing is really hard to get right on the LaTeX side. There have been some notable improvements over time, but still the macro is not ideal, unfortunately it is the best there is at the moment (if anybody has any ideas for improving the LaTeX implementation of \MakeSentenceCase, please drop by at https://github.com/plk/biblatex/issues to discuss things). In particular some of the 'rules' below are not by design, they are a result of the implementation and its quirks.

The rules are as follows

  1. The initial letter is converted to uppercase. All following letters are converted into lowercase. (Assuming no protection. See 51)
  2. In non-initial position
    1. brace groups normally prevent a case change, this includes the braced group for macro arguments. See 53 as well as 01.
    2. But a group with one level of outer bracing that starts with a macro is not protected from case change. See 61 and 02, but compare 03 etc. etc.

This seems easy enough, right? The method to protect titles would be as follows: Protect things from case change with one level of braces (A Short Grammar of {Greek}). Un-protect things in macro arguments by wrapping the entire macro in one level of braces (Why {\emph{Brontosaususes}} are cool.).

Problematic behaviour occurs if we are dealing with the initial word.

  1. The initial letter is always capitalised. See 51.
  2. The initial letter can be protected from capitalisation with a brace group. See 52.
  3. If the initial letter consists of a first-level brace group starting with a macro, the entire group is capitalised. See 12 and 31.

So things get messy as soon as initial words need to be taken care of. It is easy enough to protect titles starting with a macro (see 11), but one can't really start a title with a macro and get the same output that one would get if there was no macro. The only work-around is to split the argument of the macro into the first word that then gets implicitly protected by the argument braces and then the rest with an additional group to un-protect it, see 23. That is very unsatisfying, but the best I can offer at the moment.

Note that some custom biblatex styles may treat the next word after a colon like an initial word.

MWE

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

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

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{01,
  author  = {Test01, Anne},
  title   = {Lorem \emph{Ipsum dolor Sit ABC amet} Consectur},
  date    = {1981},
}
@book{02,
  author  = {Test02, Anne},
  title   = {Lorem {\emph{Ipsum dolor Sit ABC amet}} Consectur},
  date    = {1982},
}
@book{02b,
  author  = {Test02b, Anne},
  title   = {Lorem {s\emph{Ipsum dolor Sit ABC amet}} Consectur},
  date    = {1982},
}
@book{02c,
  author  = {Test02c, Anne},
  title   = {Lorem {S\emph{Ipsum dolor Sit ABC amet}} Consectur},
  date    = {1982},
}
@book{02d,
  author  = {Test02d, Anne},
  title   = {Lorem {{}\emph{Ipsum dolor Sit ABC amet}} Consectur},
  date    = {1982},
}
@book{03,
  author  = {Test03, Anne},
  title   = {Lorem {{\emph{Ipsum dolor Sit ABC amet}}} Consectur},
  date    = {1983},
}
@book{04,
  author  = {Test04, Anne},
  title   = {Lorem {{{\emph{Ipsum dolor Sit ABC amet}}}} Consectur},
  date    = {1984},
}
@book{11,
  author  = {Test11, Anne},
  title   = {\emph{Ipsum dolor Sit ABC amet} Consectur},
  date    = {1991},
}
@book{12,
  author  = {Test12, Anne},
  title   = {{\emph{Ipsum dolor Sit ABC amet}} Consectur},
  date    = {1992},
}
@book{12a,
  author  = {Test12a, Anne},
  title   = {{s\emph{Ipsum dolor Sit ABC amet}} Consectur},
  date    = {1992},
}
@book{12b,
  author  = {Test12b, Anne},
  title   = {{{}\emph{Ipsum dolor Sit ABC amet}} Consectur},
  date    = {1992},
}
@book{13,
  author  = {Test13, Anne},
  title   = {{{\emph{Ipsum dolor Sit ABC amet}}} Consectur},
  date    = {1993},
}
@book{14,
  author  = {Test14, Anne},
  title   = {{{{\emph{Ipsum dolor Sit ABC amet}}}} Consectur},
  date    = {1993},
}
@book{21,
  author  = {Test21, Anne},
  title   = {{}\emph{Ipsum dolor Sit ABC amet} Consectur},
  date    = {1994},
}
@book{22,
  author  = {Test22, Anne},
  title   = {{}{\emph{Ipsum dolor Sit ABC amet}} Consectur},
  date    = {1995},
}
@book{23,
  author  = {Test23, Anne},
  title   = {\emph{Ipsum }{\emph{dolor Sit ABC amet}} Consectur},
  date    = {1995},
}
@book{31,
  author  = {Test31, Anne},
  title   = {{\em Ipsum dolor Sit ABC amet\/} Consectur},
  date    = {1931},
}
@book{32,
  author  = {Test32, Anne},
  title   = {{{\em Ipsum dolor Sit ABC amet\/}} Consectur},
  date    = {1931},
}
@book{51,
  author  = {Test51, Anne},
  title   = {lOrem Ipsum},
  date    = {1951},
}
@book{52,
  author  = {Test52, Anne},
  title   = {{lorem} Ipsum},
  date    = {1952},
}
@book{53,
  author  = {Test53, Anne},
  title   = {{{lorem}} Ipsum},
  date    = {1953},
}
@book{54,
  author  = {Test54, Anne},
  title   = {Lorem {Ipsum dolor Sit ABC amet} Consectur},
  date    = {1981},
}
@book{61,
  author  = {Test61, Anne},
  title   = {Lorem {\relax Ipsum Dolor ABC sit amet} sit},
  date    = {1961},
}
@book{62,
  author  = {Test62, Anne},
  title   = {Lorem {{\relax Ipsum Dolor ABC sit amet}} sit},
  date    = {1962},
}
@book{63,
  author  = {Test63, Anne},
  title   = {Lorem {{{\relax Ipsum Dolor ABC sit amet}}} sit},
  date    = {1963},
}
@book{64,
  author  = {Test64, Anne},
  title   = {Lorem {{{{\relax Ipsum Dolor ABC sit amet}}}} sit},
  date    = {1964},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}


\begin{document}
\nocite{*}
\printbibliography
\end{document}

enter image description here

This answers refers to biblatex 3.11 with Biber 2.11. In ancient versions of biblatex the sentence casing macro had a few bugs that were resolved a while ago. Some older Biber versions would too aggressively remove braces in titles, this is not the case any more. So if you obtain different results, check your biblatex and Biber versions.

moewe
  • 175,683