6

I'm writing a document where each chapter is a reading record of a paper. So I want the name of the chapter to be the title of the paper, and the header of the chapter to be the short citation of the bib reference.

Here is what I've done so far :

\documentclass{book}
\usepackage{filecontents}
\usepackage{lipsum}

\begin{filecontents}{ECM.bib}
@ARTICLE{greenwade93,
  author  = "George Greenwade",
  title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
  year    = "1993",
  journal = "TUGBoat",
  volume  = "14",
  number  = "3",
  pages   = "342--351"
}
\end{filecontents}

\usepackage[style=apa,backend=biber]{biblatex}
\DeclareLanguageMapping{french}{french-apa}
\addbibresource{ECM.bib}

\usepackage{forest, philex}

\begin{document}
\chapter[\cite{greenwade93}]{\citetitle{greenwade93}}
\sectionmark{version for header}
\lipsum

\end{document}

But as you can see, the header prints the bib key instead of the real short citation. Is there a way to print Greenwade, 1993, instead of greenwade93?

BonyHoax
  • 969
  • Just an idea: is it possible to "memorise" the result of the \cite{} inside a string variable? – BonyHoax Apr 11 '14 at 12:03
  • 2
    The problem is that the optional argument to \chapter (the one in square brackets) is uppercased, that leads to the argument to the cite command also being uppercased and subsequently biblatex trying to find the entry key "GREENWADE93" (all uppercase letter). – moewe Apr 11 '14 at 14:55
  • A work-around would be \newcommand{\citegreen}{\cite{greenwade93}} and then \chapter[\protect\citegreen]{\citetitle{greenwade93}} or \DeclareRobustCommand{\citegreen}{\cite{greenwade93}} and \chapter[\citegreen]{\citetitle{greenwade93}} as per UK TeX FAQ: Case-changing oddities. – moewe Apr 11 '14 at 18:21
  • The [UK] TeX FAQ as mentioned in @moewe's comment has moved. The reference is now at https://texfaq.org/FAQ-casechange – barbara beeton Aug 26 '22 at 02:11

3 Answers3

6

Update

If you are using a current version of the LaTeX kernel, the case changing code will automatically leave \cite alone.

\documentclass{book}

\begin{filecontents}{\jobname.bib} @ARTICLE{greenwade93, author = "George Greenwade", title = "The {Comprehensive} {TeX} {Archive} {Network} ({CTAN})", year = "1993", journal = "TUGBoat", volume = "14", number = "3", pages = "342--351" } \end{filecontents}

\usepackage[style=apa,backend=biber]{biblatex} \addbibresource{\jobname.bib} \begin{document} \chapter[\cite{greenwade93}]{\citetitle{greenwade93}} Lorem \newpage Ipsum \end{document}

If you are using a command that the case changer does not leave alone (e.g. \autocite or \textcite), you can tell it to with

\AddToNoCaseChangeList{\autocite \textcite}

Old Answer

The problem you experience is because the optional argument to \chapter is passed to \MakeUppercase. That will cause the \cite{greenwade93} command to come out as \cite{GREENWADE93}, but of course biblatex cannot find the entry to that cite key.

The List of TeX FAQs: Case-changing oddities actually describes several remedies for that situation.

You could define a helper command \citegreen

\newcommand{\citegreen}{\cite{greenwade93}}

And \protect the call to \citegreen in \chapter

\chapter[\protect\citegreen]{\citetitle{greenwade93}}

Alternatively, \citegreen can be made robust by definition

\DeclareRobustCommand{\citegreen}{\cite{greenwade93}}
\chapter[\citegreen]{\citetitle{greenwade93}}

A solution without a helper macro is to use David Carlisle's textcase package with the overload option. This will replace \MakeUppercase by a slightly more sophisticated \MakeTextUppercase macro that deals with the commands above as expected.

Load the package

\usepackage[overload]{textcase}

You can just use

\chapter[\cite{greenwade93}]{\citetitle{greenwade93}}

then.

MWE

\documentclass{book}
\usepackage{filecontents}
\usepackage[overload]{textcase}
\begin{filecontents}{\jobname.bib}
@ARTICLE{greenwade93,
  author  = "George Greenwade",
  title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
  year    = "1993",
  journal = "TUGBoat",
  volume  = "14",
  number  = "3",
  pages   = "342--351"
}
\end{filecontents}

\usepackage[style=apa,backend=biber]{biblatex} \addbibresource{\jobname.bib} \begin{document} \chapter[\cite{greenwade93}]{\citetitle{greenwade93}} Lorem \newpage Ipsum \end{document}

moewe
  • 175,683
  • How can I ensure that \AddToNoCaseChangeList is available as a command? I have two PCs, and this answer works on one of them but not the other (undefined control sequence). Both have TeX Live 2022 installed and are trying to compile the same project. – Mew Apr 01 '23 at 12:33
  • @Mew Tricky. \AddToNoCaseChangeList is part of the LaTeX kernel. If one of your systems is too old to have it, I don't think you can easily code an alternative. You can try to use \ifundef to avoid the error (see https://tex.stackexchange.com/q/95734/35864), but then you need to keep in mind that things will probably only work properly on the newer system that actually has the command. – moewe Apr 04 '23 at 05:28
  • I'm unfamiliar with TeX's versioning system, but I was under the impression that versions were stable year-over-year. Is it possible that \AddToNoCaseChangeList was added somewhere in 2022, and that I missed it by a couple of months on only one of my installations? – Mew Apr 05 '23 at 14:41
  • @Mew With TeX Live the binaries are stable for each version, but packages (and the LaTeX kernel) may change. (With MikTeX not even binaries are the same, they can get updated year-round.) Depending on how you installed your systems and when you last updated them, you may have different versions. TeX Live 2023 is out now, so if you install it on both systems and update now, you should get matching versions. – moewe Apr 05 '23 at 16:15
5

@moewe has already explained why this happens. A package free solution (well, almost package free) is to remove \MakeUppercase from the definition of \chaptermark (which I insist was a design error to begin with):

\documentclass{book}
\usepackage{filecontents}
\usepackage{lipsum}

\begin{filecontents}{\jobname.bib}
@ARTICLE{greenwade93,
  author  = "George Greenwade",
  title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
  year    = "1993",
  journal = "TUGBoat",
  volume  = "14",
  number  = "3",
  pages   = "342--351"
}
\end{filecontents}

\usepackage[style=apa,backend=biber]{biblatex}
\DeclareLanguageMapping{french}{french-apa}
\addbibresource{\jobname.bib}

\usepackage{forest, philex,etoolbox}
\makeatletter
\patchcmd{\chaptermark}{\MakeUppercase}{\@firstofone}{}{}
\makeatother

\begin{document}
\chapter[\cite{greenwade93}]{\citetitle{greenwade93}}
\sectionmark{version for header}
\lipsum

\end{document}

Using \patchcmd is easier than doing

\makeatletter
\renewcommand{\chaptermark}[1]{%
  \markboth{%
    \ifnum\c@secnumdepth>\m@ne
      \if@mainmatter
        \@chapapp\ \thechapter.\ %
      \fi
    \fi
    #1%
  }{}%
}
\makeatother

where I copied the definition from book.cls and removed the dreaded \MakeUppercase.

egreg
  • 1,121,712
2

I don't know why, but if you use uppercase only in the refname, it works:

@ARTICLE{GREENWADE93,
  author  = "George Greenwade",
  title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
  year    = "1993",
  journal = "TUGBoat",
  volume  = "14",
  number  = "3",
  pages   = "342--351"
}

and

\chapter[\cite{GREENWADE93}]{\citetitle{GREENWADE93}}

I found it, because my log gives me:

Package biblatex Warning: The following entry could not be found
(biblatex)                in the database:
(biblatex)                GREENWADE93
(biblatex)                Please verify the spelling and rerun
(biblatex)                LaTeX afterwards.
musicman
  • 3,559
  • Yes, you're right, it also works for me. But for other reasons, I can't change the whole list of entries of my bibliography database. So I can't really use this trick :/ – BonyHoax Apr 11 '14 at 11:23
  • If you have a "static" bib-file it's a very easy regex. In case you can need it: You can search for pattern (^@.*?\{)(.*?,) and replace it with \1\U\2 – musicman Apr 11 '14 at 11:29
  • I'm not sure I understand what you mean. I don't know what you mean by "static" bib-file (like I always use the same file, which is not modified?), and I don't know what a regex is. And your pattern symbols are chinese for me :) – BonyHoax Apr 11 '14 at 11:40
  • With "static" I mean you're working on your bibfile per hand and it doesn't get created dynamically by a program etc. Then you can use regex as a workaround (- so this is no latex solution). With using the patterns I wrote you can easily make all your refnames uppercase. Look for a text editor which features Regex, like Notepad++. The rest the internet will tell you. – musicman Apr 11 '14 at 11:52
  • Oh ok. So no, I don't have a static bib-file. I'm not sure yet if it's the final version, so I can modify it by hand. So your solution may be useful. But I would prefer not to have to modify it, in case I have to generate it again. – BonyHoax Apr 11 '14 at 12:02