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.

This question already has an answer here:

is there a way to automatically format a text in title-case? Something like typing:

\somemagiccommand{the table, the ass and the stick}

which would yield:

The Table, the Ass and the Stick

I have searched the internet but have found nothing that would make this more efficient than doing the casing manually...

share|improve this question

marked as duplicate by egreg, Peter Grill, mafp, zeroth, Martin Schröder Mar 22 '13 at 22:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Welcome to TeX.sx! –  texenthusiast Mar 22 '13 at 20:06
1  
even a plain uppercase conversion is highly non-trivial in TeX. What you're looking for is going to be even more complex, as, in addition to those fundamental problems, TeX would have to have a way of knowing the difference between a »the« and an »Ass«, which as far as I know it doesn't. There's no such thing as an integrated word list (as hyphenation works without one). A poor man's solution would be to use an editor that, at least, can turn every first letter into uppercase. <alt> + <up> in WinEdt, for example. –  Nils L Mar 22 '13 at 20:15
    
Did you look at Capitalizing strings ignoring closed class words –  egreg Mar 22 '13 at 22:13
add comment

5 Answers

up vote 8 down vote accepted

enter image description here

\documentclass{article}

\makeatletter

\def\somemagiccommand#1{%
\let\tc@w\@empty
\protected@edef\tmp{\noexpand\tc@a#1\relax}\expandafter\tc@uc@\tmp}

\def\tc@a{\futurelet\tmp\tc@aa}

\def\tc@aa{%
\ifcat a\noexpand\tmp\expandafter\tc@ab
\else\expandafter\tc@ac\fi}

\def\tc@ab#1{\edef\tc@w{\tc@w#1}\tc@a}

\def\tc@ac{%
\csname tc@@\tc@w\endcsname\expandafter\tc@uc\tc@w
\let\tc@w\@empty
\ifx\tmp\@sptoken\let\next\tc@sp
\else\ifx\tmp\relax\let\next\relax
\else\let\next\tc@nxt
\fi\fi\next}

\def\tc@sp#1{ \tc@a#1}
\def\tc@nxt#1{#1\tc@a}

\def\tc@uc#1{\uppercase{#1}}
\def\tc@uc@#1#2{\uppercase{#1#2}}

\let\tc@@the\@gobbletwo
\let\tc@@and\@gobbletwo

\makeatother

\begin{document}


\somemagiccommand{the table, the ass and the stick}

\end{document}
share|improve this answer
3  
What kind of voodoo magic is going here? You have to be hiding the words that are not to be upper cased somewhere, but I don't see it?? –  Peter Grill Mar 22 '13 at 20:50
    
@PeterGrill \somemagiccommand was what was asked for. (The list of non uc-words is at the end of the code just before \makeatother) –  David Carlisle Mar 22 '13 at 21:06
    
Oh so obvious now..., Well at least where to add additional words that are not to be upper cased. So then you somehow check for the existence of tc@@<xxx> to keep <xxx> lower case. Good thing I didn't see this question earlier as I would have come up with a much more complicated solution... :-) –  Peter Grill Mar 22 '13 at 21:13
    
No I don't check for that command, I execute it and if it is defined it gobbles the uppercasing macro that follows. –  David Carlisle Mar 22 '13 at 21:15
    
@PeterGrill You would have drawn the uppercase letters illuminated manuscript form, in TikZ. –  David Carlisle Mar 22 '13 at 21:17
show 2 more comments

You might want mfirstuc and its command \capitalisewords{}. In order to keep words like “the” small we must hide it from the mechansim by hiding the space before it. This is done by using \space instead of an actual space.

\documentclass{article}
\usepackage{mfirstuc}

\begin{document}

\capitalisewords{the table,\space the ass\space and\space the stick}

\end{document}

enter image description here

share|improve this answer
add comment

The stringstrings package has a \capitalizetitle macro that does what you want. You need to define words that are not capitalised.

share|improve this answer
add comment

See Headings in uppercase for information about the introduction of the titlecaps package, designed for this task.

share|improve this answer
add comment

for the sake of completeness, here's semi-automatic solution #3:

\documentclass{scrartcl}
\usepackage{biblatex}

\begin{document}
Well {I} Have Searched the {ENTIRE} {I}nternet but Have Found Nothing\par
\MakeSentenceCase{Well {I} Have Searched the {ENTIRE} {I}nternet but Have Found Nothing}
\end{document}

enter image description here

share|improve this answer
    
I don't think this is what the OP asked for. –  StrongBad Mar 22 '13 at 21:01
    
that's why I pointed out it's semi-automatic. Like the one suggested by cgnieder -- which is structurally the same thing -- there's manual work to be done to indicate where to change or not to change case. Defining word lists containing exceptions is, of course, one of the better semi-automatic solutions -- but as I understand it, the OP is looking for something that just »knows« what to capitalize, thus sparing them manual work. InDesign can do that (IIRC), as can, apparently, this thing here –  Nils L Mar 22 '13 at 21:31
add comment

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