# How can I force text to be displayed in title-case?

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 :(

-
Hum, technically it will be tricky, because as I under stand it, short, unimportant words like of or in are not supposed to be capitalized in title case. So you will need to either maintain a very nice list of exceptions, or just ignore them. If you want to implement something like this, you may want to take a look at ctan.org/tex-archive/help/Catalogue/entries/mfirstuc.html for some ideas. – Willie Wong Nov 2 '10 at 0:14
Here's a Lua version implementing a title-case algorithm: lua-users.org/lists/lua-l/2008-08/msg00353.html. – Will Robertson Nov 2 '10 at 2:12
@Will - There's a few differences between the Gruber-Gouch algorithm and APA style: APA wants all three-letter prepositions and conjunctions to be lower-case (e.g., out, off, per, so), so these would need to be added. Then, APA wants compounds including prepositions to be capitalised, e.g., "Knock-On Effect." But these are easily fixed and I'm surprised at what a good approximation this does. – Charles Stewart Nov 2 '10 at 9:33
Interesting, thanks! I'd be pretty interested in a TeX-based solution for this, but I understand the difficulty in putting it together. I'd be more than happy with a LuaTeX implementation, otherwise :) – Will Robertson Nov 2 '10 at 10:32
Wow. It's almost as if APA was trying to make their stuff difficult to implement... – Seamus Nov 2 '10 at 11:40

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\section{\@ifnextchar*{\@sections}%
{\@ifnextchar[{\@sectionb}{\@section}}}%
\def\@sections*##1{\leveltwo{\MakeTitlecase{##1}}}%
\def\@sectionb[##1]##2{\leveltwo{\MakeTitlecase{##2}}%
\@mkboth{\MakeUppercase{##1}}{\MakeUppercase{##1}}%
\def\@section##1{\leveltwo{\MakeTitlecase{##1}}%
\@mkboth{\MakeUppercase{##1}}{\MakeUppercase{##1}}%
%
\def\subsection{\@ifnextchar*{\@subsections}%
{\@ifnextchar[{\@subsectionb}{\@subsection}}}%
\def\@subsections*##1{\levelthree{\MakeTitlecase{##1}}}%
\def\@subsectionb[##1]##2{\levelthree{\MakeTitlecase{##2}}%
\def\@subsection##1{\levelthree{\MakeTitlecase{##1}}%
%
\def\subsubsection{\@ifnextchar*{\@subsubsections}%
{\@ifnextchar[{\@subsubsectionb}{\@subsubsection}}}%
\def\@subsubsections*##1{\levelfour{\MakeTitlecase{##1}}}%
\def\@subsubsectionb[##1]##2{\levelfour{\MakeTitlecase{##2}}%
\def\@subsubsection##1{\levelfour{\MakeTitlecase{##1}}%
%
\let\paragraph=\levelfive%
}
\makeatother

\title{On the Bodleianisation of L-Space Interior Topologies}
\author{The Librarian}
\affiliation{Unseen University}
\shorttitle{Ook}
\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}
-
But where is \capitalizetitle defined? I also get an error: ! Undefined control sequence. <recently read> \addlcwords l.6 \addlcwords {all of the and a an is before on – user22731 Nov 30 '12 at 5:48

The titlecaps package (http://ctan.org/pkg/titlecaps, but note that CTAN is hosed in that it doesn't show in a search, but is actually there) does this. Having written the "horrendously time-expensive" stringstrings package (as Geoffrey correctly notes), I endeavored to do better for the situation of titling. The titlecaps package is the result.

An example in the documentation shows how the fully lower-cased source:

\documentclass{article}

\usepackage{titlecaps}
\parskip 1em
\parindent 0em
\def\bs{$\backslash$}
\begin{document}
\Resetlcwords
\Addlcwords{for a is but and with of in as the etc on to if}
\titlecap{%
to know that none of the words typed in this paragraph were initially
upper cased might be of interest to you.  it is done to demonstrate the
behavioral features of this package.  first, you should know the words
that i have pre-designated as lower case.  they are:  for a is but and
with of in as the etc on to if.''  you can define your own list.  note
that punctuation, like the period following the word if'' did not mess
up the search for lower case (nor did the quotation marks just now).
punctuation which is screened out of the lower-cased word search pattern
include . , : ; ( ) [ ] ? !  ' however, I cannot screen text braces;
\{for example in\} is titled, versus (for example in), since the braces
are not screened out in the search for pre-designated lower-case words
like for and in.  However, \texttt{\bs textnc} provides a workaround:
\{\textnc{for example in}\}.  titlecap will consider capitalizing
following a (, [, \{, or - symbol, such as (abc-def).  you can use your
text\textit{\relax xx} commands, like i just did here with the prior xx,
but if you want the argument of that command to not be titled, you
either need, in this example, to add \textit{xx} to the lowercase word
list, which you can see i did not.  instead, i put \bs relax~xx'' as
the argument, so that, in essence, the \bs relax was capitalized, not
the x.  Or you could use \texttt{\bs textnc} .  here i demonstrate that
text boldface, \textbf{as in the \bs textbf command}, also works fine,
as do \texttt{texttt}, \textsl{textsl}, \textsc{textsc},
\textsf{textsf}, \textit{etc}.  titlecap will work on diacritical marks,
such as \"apfel, \c cacao \textit{etc.}, \scriptsize fontsize \LARGE
changing commands\normalsize\unskip, as well as national symbols such as
\o laf, \ae gis, and \oe dipus.  unfortunately, i could not get it to
work on the \aa~nor the \l~symbols. the method will work with some
things in math mode, capitalizing symbols if there is a leading space,
$x^2$ can become $x^2$, and it can process but it will not capitalize
the greek symbols, such as $\alpha$, and will choke on most macros, if
they are not direct character expansions.  Additionally,
\textsf{titlecaps} also works with font changing declarations, for
example, \bs itshape\bs sffamily. \itshape\sffamily you can see that it
works fine.  likewise, any subsequent \bs textxx command will, upon
completion, return the font to its prior state, such as this
\textbf{textbf of some text}.  you can see that i have returned to the
prior font, which was italic sans-serif. now I will return to upright
roman\upshape\rmfamily.  a condition that will not behave well is inner
braces, such as \ttfamily \bs titlecap\{blah \{inner brace material\}
blah-blah\}. \rmfamily see the section on quirks and limitations for a
workaround involving \texttt{\bs textnc}.  titlecap will always
capitalize the first word of the argument (\textbf{even if it is on the
lower-case word list}), unless \texttt{\bs titlecap} is invoked with an
optional argument that is anything other than a capital p.  in that case,
the first word will be titled \textit{unless} it is on the lowercase
word list.  for example, i will do a \bs titlecap[\relax s]\{\relax
a~big~man\} and get \titlecap[s]\textnc{a big man}'' with the `a''
not titled.  i hope this package is useful to you, but as far as using
\textsf{titlecaps} on such large paragraphs\ldots \textbf{do not try
this at home!}}

\end{document}

can become, in just a few quick seconds of execution time, this:

-
Excellent! I was looking a while ago exactly for this. thank you for creating this package. – Hotschke Jul 1 '13 at 18:32
@Hotschke Happy to help. If, with use, you have suggestions, please don't hesitate to let me know them. – Steven B. Segletes Jul 1 '13 at 18:36