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.

How can I write in capitals the first letter of each word in a title?

In other words, I want to write the title normally

\chapter{Title of my chapter}

and to have the heading in this way

Title Of My Chapter

I have read this discussion but I cannot modify that solution for my case.

share|improve this question

2 Answers 2

There is a wonderful package called inicap by the late Michael J Downes of AMS. It was part of the amsrefs package but is unfortunately not distributed any more. You can download inicap.dtx from the AMS FTP server for obsolete software or you can do a Google search with latex inicap.sty to obtain it.

inicap does not capitalize all the words. Words like "a", "an", "the", "and", etc. are not capitalized; this is in fact the right way to do it. From the Chicago Manual of Style for capitalizing titles of written works in English:

Capitalize each word, including pronouns and subordinate conjunctions, except for articles, coordinate conjunctions, and prepositions, or the word to in infinitives. Always capitalize the first and last word of the title and the first and last word of any subtitles that it may contain. Don’t capitalize the second or later word in a hyphenated compound unless it is a noun or proper adjective, or it has equal force with the first word.

Note that inicap do not change inline math or inserted macros

\inicap{title of my chapter}

will be typeset as

Title of My Chapter

EDIT: To change all chapters you can redefine the chapter command:

\usepackage{inicap}
\let\oldchap=\chapter
\renewcommand\chapter{\secdef\mychap\myschap}
\def\myschap#1{\oldchap*{\inicap{#1}}}
\def\mychap[#1]#2{%
    \oldchap[\inicap{#1}]{\inicap{#2}}}
share|improve this answer
    
I want to "capitalize" the letters in the headings only. –  user11960 Feb 22 '12 at 6:55
    
@Jack TeX: I have edited my answer –  Danie Els Feb 22 '12 at 8:15

I don't know if you are using LuaLaTeX, but here is an approach to do it with LuaLaTeX:

It is good practice to write the lua functions in a separate file with the extension .lua. For this MWE I use the filecontents environment instead to provide an extra file for the lua script.

\documentclass{book}
\usepackage{filecontents}

\begin{filecontents*}{luaFunctions.lua}
function capitalize(input)
    --separate given string in words (separated by space)
    local split = string.explode(input, " ")

    for i,p in ipairs(split) do
        --make the first letter upper-case
        output, count = string.gsub(p, '^%l', string.upper)
        --print the word to TeX
        tex.print(output)
    end
end
\end{filecontents*}

% read the external lua file to declare the defined function,
% but without execute the Lua function
\directlua{dofile("luaFunctions.lua")}

% latex command to execute the lua function
\def\caps#1{\directlua{capitalize("#1")}}

\begin{document}
\noindent
\caps{Title of my chapter}\\
\caps{read the external lua file to declare the defined function}
\end{document} 
share|improve this answer
    
thank you so much for the lua code, but I have to use pdflatex. –  user11960 Feb 22 '12 at 6:47
    
I want to "capitalize" the letter in the headings only. –  user11960 Feb 22 '12 at 6:55

Your Answer

 
discard

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