2

I would like to make the optional argument I pass to a theorem environment (which puts the argument in a parenthetical next to the theorem number - typically for naming a theorem) have title case i.e. non-articles should be capitalized. I am able to do this for section headings using the titlecaps and titlesec packages (see the MWE below), but I'm unsure how this behavior can be obtained without manually doing it each time in the theorem argument.

I'm using a self made definition environment (through amsthm) and have a lot of named definitions in the beginning of my document so it would be nice not to have to capitalize all of their titles by hand.

MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{titlesec,titlecaps}


\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[subsection]
\newtheorem{definition}[theorem]{Definition}

\Addlcwords{is with the a an}
\titleformat{\section}[block]{}{\normalfont\Large\bfseries\thesection.\;}{0pt}{\formatsectiontitle}
\newcommand{\formatsectiontitle}[1]{\normalfont\Large\bfseries\titlecap{#1}}

\begin{document}


\section{this is an automatically title capitalized section}
\begin{definition}[I wish this was title capitalized]
Definition.
\end{definition}

\end{document}
2
  • Please provide a minimum working example that generates the issue you wish to fix.
    – Mico
    Jul 28 '21 at 17:57
  • @Mico Updated with an MWE, thanks!
    – Lockjaw
    Jul 28 '21 at 22:54
3
+50

The following redefines the definition environment and inserts \titlecap{...} around the optional argument supplied to it:

enter image description here

\documentclass{article}

\usepackage{amsthm}
\usepackage{titlecaps}

\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[subsection]
\newtheorem{definition}[theorem]{Definition}

\Addlcwords{is with the a an}

\begin{document}

Original definition:

\begin{definition}[I wish this was capitalized]
Definition.
\end{definition}

Manual title case for definition:

\begin{definition}[\titlecap{I wish this was capitalized}]
Definition.
\end{definition}

\let\olddefinition\definition
\let\endolddefinition\enddefinition
\RenewDocumentEnvironment{definition}{ o }{%
  \IfValueTF{#1}
    {\olddefinition[\titlecap{#1}]}
    {\olddefinition}%
}{%
  \endolddefinition
}

Automated title cap definition:

\begin{definition}[I wish this was capitalized]
Definition.
\end{definition}

\end{document}

This only holds for the definition environment. You'll need to \usepackage{xparse} if you don't have an up-to-date LaTeX.

3
  • Thank you for the answer! What would the xparse package do? I'm unfamiliar with this.
    – Lockjaw
    Jul 30 '21 at 22:54
  • @Lockjaw: xparse provides \RenewDocumentEnvironment (and similar definitions) and an easy way to test whether optional arguments are supplied or not (through \IfValueTF{<arg>}{<true>}{<false>}). It's definitions were included as part of the LaTeX kernel/core in October 2020 (press release).
    – Werner
    Jul 30 '21 at 23:10
  • maybe it would be instructive to chose an example title containing "and, in, to", etc. in the title, so that the title case becomes more apparent. Aug 2 '21 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.