I would like my sections (and potentially subsections) to be in "sentencecase" no matter how I type them. I am happy with the way the \MakeSentenceCase
macro from the biblatex
package converts text with arbitrary capitalization into sentencecase. I am having difficulty integrating this into the \section
macro.
My first attempt was to redefine \section
to be
\renewcommand{\section}{\@startsection{section}{1}{\z@}{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus.2ex}{\normalfont\Large\bfseries\MakeSentenceCase}}
but this fails because the first token (or something like that) to \MakeSentenceCase
is not the first token of the text of my section heading, but rather related to the numbering and indenting. The following method works
\documentclass{article}
\usepackage{etoolbox}
\usepackage[backend=biber]{biblatex}
\makeatletter
\let\sectionOrig\section
\renewcommand{\section}{\@ifstar{\@sectionStar}{\@sectionNoStar}}%
\newcommand{\@sectionNoStar}[2][\relax]{\ifdefstring{\relax}{#1}{%
\sectionOrig{\MakeSentenceCase{#2}}%
}{%
\sectionOrig[#1]{\MakeSentenceCase{#2}}%
}}
\newcommand{\@sectionStar}[1]{\sectionOrig*{\MakeSentenceCase{#1}}}%
\makeatother
\begin{document}
\section{sections SHOULD BE IN {SENTENCECASE}}
\end{document}
by completely redefining the \section
command. I have tried to take care of the starred and unstarred forms and optional arguments, but I am worried that this approach is going to cause problems someplace else.
I guess I have 3 questions. First, is it reasonable to expect LaTeX to automatically handle the capitalization of sections. Second, is my approach reasonable. Third, is there a better approach (or an already existing package).
Best Answer
This is easy using the
titlesec
package. With theexplicit
option (p. 8, sec. 3.7), we can use an (I think) arbitrary transformation on the sectioning title stored as#1
. With this knowledge, the rest becomes a piece of cake:(Note that this solution can be easily applied to the other sectioning commands by just replacing
\section
and\thesection
appropriately.)As for your other questions:
titlesec
) for more functionality. (For example, if you had written your own\MakeSentenceCase
, that may have been a bit too much work—a lot of code means a lot of room for small errors.)