Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to convert the fist letter of each word in all my section headings to capitals automatically. Is it possible?

ie

\section{This is my first section}

Section 1. This Is My First Section

share|improve this question

1 Answer 1

up vote 5 down vote accepted

I'm not sure if there are any problems with this approach to making the titlecaps automatic for all sections, but it works for the example given. Check the titlecaps documentation for quirks on how to handle different kinds of non-standard text in its argument.

Note how it is able to handle an "exluded words" list, font styles, fontsize changes, as well as diacritics and national symbols like \ae.

\documentclass{article}
\usepackage{titlecaps}
\let\svsection\section
\def\section#1{\svsection{\titlecap{#1}}}
\begin{document}
\section{This is my first section}

Tah dah  But if you didn't like ``my,'' ``for,'' or ``an'' capitalized, except as the first word:

\Addlcwords{my for an}

\section{for an \ae ncore, my \textit{section} for \small \c consideration}

done.
\end{document}

enter image description here

UPDATE: I did find that the section redefinition above will break \tableofcontents unless care is taken. If that is a necessary ingredient of your work, then this approach below will work. Renewing the \def of \section must occur after the \tableofcontents. Also, the \Addlcwords must occur before the \tableofcontents. Furthermore, fontsize changes in a section heading will also break the \tableofcontents, so I have removed them from this example.

\documentclass{article}
\usepackage{titlecaps}
\let\svsection\section
\Addlcwords{my for an}
\begin{document}
\tableofcontents

\def\section#1{\svsection{\titlecap{#1}}}
\section{This is my first section}

Tah dah  But if you didn't like ``my,'' ``for,'' or ``an'' capitalized, except as the first word:


\section{for an \ae ncore, my \textit{section} for \c consideration}

done.

\end{document}

enter image description here

NOTE: The extra space at the beginning of section 2 is the result of a missing % at the end of line 353 of the sty file. That line should read

            \def\symbol@flag{N}%

I will update the package tomorrow to correct the problem. Current version is 1.0. Look for V1.1 in the days to come at CTAN.

share|improve this answer
    
Nice! How would I change the \section macro in the preamble to include \titlecap for all my section headings. That is to say I have written my entire document but fancy making the first letters of my sections capitalised retrospectively. –  HCAI Jun 23 '13 at 20:59
    
@HCAI Perhaps the revised answer will help. –  Steven B. Segletes Jun 23 '13 at 21:08
    
Superb Thank You! Now I can have a play around with this and see what looks good. –  HCAI Jun 23 '13 at 22:21
1  
@HCAl Please see UPDATE, regarding \tableofcontents –  Steven B. Segletes Jun 23 '13 at 23:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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