GeneralCapitalizing the first letter of each word

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Gorecki83
Posts: 4
Joined: Sat Aug 11, 2007 1:39 am

Capitalizing the first letter of each word

Post by Gorecki83 »

Hi everyone,

Does anyone know if there is a package that allows you the capitalize the first letter of each word in a sentence?
For example:
\Capitalize{hello world} would yield: "Hello World"

I've searched CTAN and the rest of the web but I couldn't find anything.
Maybe someone could write a macro that does this?

Thanks in advance!
Regards,

-Gorecki

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Gorecki83
Posts: 4
Joined: Sat Aug 11, 2007 1:39 am

Re: Capitalizing the first letter of each word

Post by Gorecki83 »

No ideas? :cry:
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Capitalizing the first letter of each word

Post by localghost »

Where is the sense behind this? Are the text passages so long that you can't do that by hand? I know you expected answers, but i'm afraid there is no such automatism.
Gorecki83
Posts: 4
Joined: Sat Aug 11, 2007 1:39 am

Re: Capitalizing the first letter of each word

Post by Gorecki83 »

The idea was to combine this with hyperref's \autoref.
I want to define something like:

\newcommand{\Autoref}[1]{\Capitalize{\autoref{#1}}}}

And then I could use \Autoref at the beginning of sentences and \autoref elsewhere.

Is there really no way to do this?
Possibly using some kind of subspring functions?
eg:

\Uppercase{\left{1}{string}} ---> "String"

Any ideas?
Gorecki83
Posts: 4
Joined: Sat Aug 11, 2007 1:39 am

Re: Capitalizing the first letter of each word

Post by Gorecki83 »

Anyone?
sschuberth
Posts: 2
Joined: Fri May 07, 2010 12:15 pm

Capitalizing the first letter of each word

Post by sschuberth »

Although this thread is pretty old, a solution would be to use the mfirstuc package.
mychi
Posts: 7
Joined: Tue Mar 02, 2010 4:54 am

Capitalizing the first letter of each word

Post by mychi »

Thanks sschuberth! It was worth posting an answer even 3 years later since there could always be people asking themselves the same question 3 years later, like me :D

Unfortunately I didn't manage to get it working in connection with \autoref. Here is a minimal example:

Code: Select all

\documentclass{article}
\usepackage{mfirstuc}
\usepackage{hyperref}

\newcommand{\wa}{world}
\newcommand{\wb}{\wc}
\newcommand{\wc}{\wb}

\newcommand{\xxmakefirstuc}[1]{\expandafter\xmakefirstuc\expandafter{#1}}
\newcommand{\xxxmakefirstuc}[1]{\expandafter\xxmakefirstuc\expandafter{#1}}

\begin{document}

\section{Introduction}\label{sec:intro}
Try to force capitalized autoref.

\section{Example}
An example referring to \autoref{sec:intro}. Hello \xxxmakefirstuc{\wa}.
\xxxmakefirstuc{\autoref{sec:intro}} references should sometimes be capitalized.

\end{document}
mfirstuc provides xmakefirstuc which is equivalent to \expandafter\makefirstuc\expandafter{...}. In the "Hello World" example sentence you can see that this doesn't work anymore if the expanded command is again a command. That's why I defined further commands xxmakefirstuc and xxxmakefirstuc.

I assumed that the reason why it doesn't work with \autoref is the same. But apparently it doesn't work with xmakefirstuc nor with xxmakefirstuc nor with xxxmakefirstuc :(

Does someone have any idea what could be the problem with autoref? Why does it work with the \wa etc. commands but not with \autoref?
Post Reply