44

Simple question: Is there a simple way to get cleveref to use the Oxford comma?

\documentclass{article}
\usepackage[standard]{ntheorem}
\usepackage{cleveref}

\begin{document}

\begin{proposition}\label{thm:roses}
  Roses are red.
\end{proposition}

\begin{proposition}\label{thm:violets}
  Violets are blue.
\end{proposition}

\begin{proposition}
  42.
\end{proposition}

\begin{proposition} \label{thm:orchids}
  Orchids are orchid.
\end{proposition}

\begin{theorem}
  There exist flowers in at least three different colors.
\end{theorem}
\begin{proof}
  Immediate from \cref{thm:roses,thm:violets,thm:orchids}.
\end{proof}

\end{document}

Output

Should say “propositions 1, 2, and 4.”

3 Answers3

51

If you define this new command

\newcommand{\creflastconjunction}{, and\nobreakspace}

you will get Oxford comma everywhere you use multiple references like those.

MWE:

\documentclass{article}
\usepackage[standard]{ntheorem}
\usepackage{cleveref}

\newcommand{\creflastconjunction}{, and\nobreakspace}

\begin{document}

\begin{proposition}\label{thm:roses}
  Roses are red.
\end{proposition}

\begin{proposition}\label{thm:violets}
  Violets are blue.
\end{proposition}

\begin{proposition}
  42.
\end{proposition}

\begin{proposition} \label{thm:orchids}
  Orchids are orchid.
\end{proposition}

\begin{theorem}
  There exist flowers in at least three different colors.
\end{theorem}
\begin{proof}
  Immediate from \cref{thm:roses,thm:violets,thm:orchids}.
\end{proof}

\end{document} 

Output:

enter image description here


ADDENDUM

If you were wondering why you have to use \newcommand instead of renewcommand, this is why.

cleveref defines, at the beginning of the document, a lot of commands depending on the language. If you don't specify any language, english is loaded. This is the relevant part of cleveref.sty:

\DeclareOption{english}{%
  \AtBeginDocument{%
    ....
    \def\creflastconjunction@preamble{ and\nobreakspace}%
    ....

Also, you can find the following lines

\AtBeginDocument{%
  ....
  \@ifundefined{creflastconjunction}{%
    \let\creflastconjunction\creflastconjunction@preamble%
  }{%
  ....
  }%

which, at the beginning of the document, assign to \creflastconjunction the meaning of \creflastconjunction@preamble when it has not been defined yet.

In other words, \creflastconjunction gets defined only after \begin{document}. In fact, if you try to put the line

\newcommand{\creflastconjunction}{, and\nobreakspace}

inside the document, you will get an error. In this case, you would have written

\renewcommand{\creflastconjunction}{, and\nobreakspace}
karlkoeller
  • 124,410
  • 1
    Does \newcommand{\creflastconjunction}{, and~} work the same? In other words, can you replace the \nobreakspace with a ~? – MSC Jan 24 '17 at 22:22
  • 1
    @MSC No problems with your substitution. – karlkoeller Jan 26 '17 at 17:55
  • Is it possible to restrict this change of last conjunction just to English language (and do something else when \cref is issued in the context where the language is, say, German)? –  Jan 31 '20 at 22:01
  • As I wondered about this: with just two references (\cref{thm:roses,thm:violets}) this correctly expands to propositions 1 and 2, without the extra comma. – Thom Wiggers Nov 30 '22 at 13:25
11

Simple answer: You can use

\newcommand{\creflastconjunction}{, and~}

From the manual:

\creflastconjunction is used between the penultimate and final cross-reference in a list of more than two [pg. 12, at least for the 2012-03-07 version of the manual I have]


Redoing your example:

\documentclass{article}
\usepackage\[standard\]{ntheorem}
\usepackage{cleveref}

\newcommand{\creflastconjunction}{, and~}

\begin{document}

\begin{proposition}\label{thm:roses}
  Roses are red.
\end{proposition}

\begin{proposition}\label{thm:violets}
  Violets are blue.
\end{proposition}

\begin{proposition}
  42.
\end{proposition}

\begin{proposition} \label{thm:orchids}
  Orchids are orchid.
\end{proposition}

\begin{theorem}
  There exist flowers in at least three different colors.
\end{theorem}
\begin{proof}
  Immediate from \cref{thm:roses,thm:violets,thm:orchids}.
\end{proof}

\end{document}

The compiled example, saying "Immediate from propositions 1, 2, and 4."

8

You can use \crefmultiformat:

\documentclass{article}
\usepackage[standard]{ntheorem}
\usepackage{cleveref}

\crefmultiformat{proposition}{propositions~#2#1#3}%
  { and~#2#1#3}{, #2#1#3}{, and~#2#1#3}

\begin{document}

\begin{proposition}\label{thm:roses}
  Roses are red.
\end{proposition}

\begin{proposition}\label{thm:violets}
  Violets are blue.
\end{proposition}

\begin{proposition}
  42.
\end{proposition}

\begin{proposition} \label{thm:orchids}
  Orchids are orchid.
\end{proposition}

\begin{theorem}
  There exist flowers in at least three different colors.
\end{theorem}
\begin{proof}
  Immediate from \cref{thm:roses,thm:violets,thm:orchids}.
  Immediate from \cref{thm:roses,thm:violets}.
\end{proof}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Aha! It's a little piecemeal (will need to repeat for different theorem sets), but it should work. Thanks. – Luke Maurer Feb 19 '14 at 20:14
  • 1
    @LukeMaurer see karlkoeller's answer for a solution affecting all reference types. – Gonzalo Medina Feb 19 '14 at 20:23
  • Out of curiosity, why the #2#1#3 instead of #1#2#3? – Sean Allred Feb 20 '14 at 04:14
  • Is it possible to restrict this change of last conjunction just to English language (and do something else when \cref is issued in the context where the language is, say, German)? –  Jan 31 '20 at 22:03