[Tex/LaTex] How to force text to be displayed in title-case

apa-stylecapitalization

I'm trying to update apa.cls for 6th edition (a large task since I'm not a true latex hacker) and I'd like to force the headings for certain levels to conform to title case. That is the first letter of every word is in uppercase. For example:

  • Upper case = DELAYED SOCIAL TRANSITIONS DURING EMERGING ADULTHOOD
  • Lower case = delayed social transitions during emerging adulthood
  • Sentence case = Delayed social transitions during emerging adulthood
  • Title case = Delayed Social Transitions During Emerging Edulthood

So my questions are:

  1. Is there an easy way to do this that I just haven't found? or
  2. Can someone point me in the direction of what I would have to know to implement this myself?

Thanks all.

p.s. I know that this post has nothing to do with the tag 'cases', but I can't create new tags because I don't have enough reputation and nothing else fits 🙁

Best Answer

This code should get you started. It uses a couple of the stringstrings package's string manipulation routines, including its horrendously time-expensive \addlcwords to identify the words you'd prefer to typeset in lower case. The rest of the code hooks this into APA's sectioning commands (it's tedious but it does the trick).

Note that although this should get you going, it isn't completely ready for prime time, mainly because the work will take some time which, if it weren't something you wanted to proceed with, would divert me from things I'm actually supposed to be doing :). Nevertheless, if this were something you wanted to proceed with, you'll need to let stringstrings know that '-' (as in 'Knock-on') should be treated the same way as a space character (run the code below to see what I mean). That work would probably involve handing '-' to stringstrings's \encodetoken command and involve providing some extra buttressing code -- although I wouldn't be surprised if there were several ways to skin that particular cat.

Anyway, although there's still some work remaining, I hope it takes you in the direction you set out to go. (NB, don't forget: stringstrings's \addlcwords seems to scale time-exponentially. Or worse.)

\documentclass[jou]{apa}
\usepackage{lipsum}

\usepackage{stringstrings}
\addlcwords{all of the and a an is before on}
\DeclareRobustCommand*\MakeTitlecase[1]{%
  \caselower[e]{#1}%
  \capitalizetitle{\thestring}%
}

\makeatletter
% Four Levels with Sections in Title Case
\def\FourLevelHeadingTitleCase{%
    \def\section{\@ifnextchar*{\@sections}%
                {\@ifnextchar[{\@sectionb}{\@section}}}%
    \def\@sections*##1{\leveltwo{\MakeTitlecase{##1}}}%
    \def\@sectionb[##1]##2{\leveltwo{\MakeTitlecase{##2}}%
        \@mkboth{\MakeUppercase{##1}}{\MakeUppercase{##1}}%
        \addcontentsline{toc}{section}{\MakeTitlecase{##1}}}%
    \def\@section##1{\leveltwo{\MakeTitlecase{##1}}%
        \@mkboth{\MakeUppercase{##1}}{\MakeUppercase{##1}}%
        \addcontentsline{toc}{section}{\MakeTitlecase{##1}}}%
%
    \def\subsection{\@ifnextchar*{\@subsections}%
                   {\@ifnextchar[{\@subsectionb}{\@subsection}}}%
    \def\@subsections*##1{\levelthree{\MakeTitlecase{##1}}}%
    \def\@subsectionb[##1]##2{\levelthree{\MakeTitlecase{##2}}%
        \addcontentsline{toc}{subsection}{\MakeTitlecase{##1}}}%
    \def\@subsection##1{\levelthree{\MakeTitlecase{##1}}%
        \addcontentsline{toc}{subsection}{\MakeTitlecase{##1}}}%
%
    \def\subsubsection{\@ifnextchar*{\@subsubsections}%
                      {\@ifnextchar[{\@subsubsectionb}{\@subsubsection}}}%
    \def\@subsubsections*##1{\levelfour{\MakeTitlecase{##1}}}%
    \def\@subsubsectionb[##1]##2{\levelfour{\MakeTitlecase{##2}}%
        \addcontentsline{toc}{subsubsection}{\MakeTitlecase{##1}}}%
    \def\@subsubsection##1{\levelfour{\MakeTitlecase{##1}}%
        \addcontentsline{toc}{subsubsection}{\MakeTitlecase{##1}}}%
%
    \let\paragraph=\levelfive%
}
\makeatother
\FourLevelHeadingTitleCase

\title{On the Bodleianisation of L-Space Interior Topologies}
\author{The Librarian}
\affiliation{Unseen University}
\shorttitle{Ook}
\rightheader{Oook}
\leftheader{Capitalised Headers}
\abstract{\lipsum[1]}
\begin{document}
\maketitle
\section{Library-Space is NOT countable}
\lipsum[1]
\subsection{Turtles ALL the way down}
\lipsum[2]
\subsubsection{On THE Knock-ON Effect oN wood}
\lipsum[3]
\subsubsection{an orang And a utan}
\lipsum[3]
\end{document}