1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
\documentclass{nlctdoc}
\usepackage{alltt}
\usepackage{mfirstuc}
\usepackage{pifont}
\usepackage[utf8]{inputenc}
\ifpdf
\usepackage[T1]{fontenc}
\fi
\usepackage{cmap}
\usepackage[colorlinks,
bookmarks,
hyperindex=false,
pdfauthor={Nicola L.C. Talbot},
pdftitle={mfirstuc.sty: uppercasing first letter},
pdfkeywords={LaTeX,package,uppercase}]{hyperref}
\begin{document}
\title{mfirstuc.sty v1.08: uppercasing first letter}
\author{Nicola L.C. Talbot\\[10pt]
Dickimaw Books\\
\url{http://www.dickimaw-books.com/}}
\date{2013-11-04}
\maketitle
The \styfmt{glossaries} bundle is supplied with the package
\sty{mfirstuc} which provides the command:
\begin{definition}[\DescribeMacro{\makefirstuc}]
\cs{makefirstuc}\marg{stuff}
\end{definition}
This makes the first object of
\meta{stuff} uppercase unless \meta{stuff} starts with a control
sequence followed by a non-empty group, in which case the first
object in the group is converted to uppercase. Examples:
\begin{itemize}
\item |\makefirstuc{abc}| produces \makefirstuc{abc}.
\item |\makefirstuc{\emph{abc}}| produces \makefirstuc{\emph{abc}}
(\ics{MakeUppercase} has been applied to the letter \qt{a} rather
than \cs{emph}). Note however that
\begin{verbatim}
\makefirstuc{{\em abc}}
\end{verbatim}
produces \makefirstuc{{\em abc}} (first object is |{\em abc}| so
equivalent to |\MakeUppercase{\em abc}|), and
\begin{verbatim}
{\makefirstuc{\em abc}}
\end{verbatim}
produces {\makefirstuc{\em abc}} (|\em| doesn't have an argument
therefore first object is |\em| so equivalent to
|{\MakeUppercase{\em}abc}|).
\item |\makefirstuc{{\'a}bc}| produces \makefirstuc{{\'a}bc}.
\item |\makefirstuc{\ae bc}| produces \makefirstuc{\ae bc}.
\item |\makefirstuc{{\ae}bc}| produces \makefirstuc{{\ae}bc}.
\item |\makefirstuc{{ä}bc}| produces \makefirstuc{{ä}bc}.
\end{itemize}
Note that non-Latin or accented characters appearing at the
start of the text must be placed in a group (even if you are
using the \sty{inputenc} package) due to expansion issues.
\begin{important}
In version 1.02 of \styfmt{mfirstuc}, a bug fix resulted in a change
in output if the first object is a control sequence followed by
an empty group. Prior to version 1.02, |\makefirstuc{\ae{}bc}|
produced \ae Bc. However as from version 1.02, it now produces
\AE bc.
\end{important}
Note also that
\begin{verbatim}
\newcommand{\abc}{abc}
\makefirstuc{\abc}
\end{verbatim}
produces: ABC. This is because the first object in the argument of
\cs{makefirstuc} is \cs{abc}, so it does |\MakeUppercase{\abc}|.
Whereas:
\begin{verbatim}
\newcommand{\abc}{abc}
\expandafter\makefirstuc\expandafter{\abc}
\end{verbatim}
produces: Abc. There is a short cut command which will do this:
\begin{definition}[\DescribeMacro{\xmakefirstuc}]
\cs{xmakefirstuc}\marg{stuff}
\end{definition}
This is equivalent to \cs{expandafter}\cs{makefirstuc}\cs{expandafter}\marg{stuff}. So
\begin{verbatim}
\newcommand{\abc}{abc}
\xmakefirstuc{\abc}
\end{verbatim}
produces:
\newcommand{\abc}{abc}%
\xmakefirstuc{\abc}.
\begin{important}
\cs{xmakefirstuc} only performs one level expansion on the first
object in its argument. It does not fully expand the entire
argument.
\end{important}
If you use \styfmt{mfirstuc} without the \sty{glossaries} package,
the standard \cs{MakeUppercase} command is used. If used with
\sty{glossaries}, \ics{MakeTextUppercase} (defined by \sty{textcase}
the package) is used instead. If you are using \styfmt{mfirstuc}
without the \styfmt{glossaries} package and want to use
\ics{MakeTextUppercase} instead, you can redefine
\begin{definition}[\DescribeMacro\glsmakefirstuc]
\cs{glsmakefirstuc}\marg{text}
\end{definition}
For example:
\begin{verbatim}
\renewcommand{\glsmakefirstuc}[1]{\MakeTextUppercase #1}
\end{verbatim}
Remember to also load \sty{textcase} (\styfmt{glossaries} loads this
automatically).
New to mfirstuc v1.06:
\begin{definition}[\DescribeMacro{\capitalisewords}]
\cs{capitalisewords}\marg{text}
\end{definition}
This command apply \ics{makefirstuc} to each word in \meta{text}
where the space character is used as the word separator. Note that
it has to be a plain space character, not another form of space,
such as \verb|~| or \cs{space}. Note that no expansion is performed
on \meta{text}.
\begin{definition}[\DescribeMacro{\xcapitalisewords}]
\cs{xcapitalisewords}\marg{text}
\end{definition}
This is a short cut for
\cs{expandafter}\cs{capitalisewords}\cs{expandafter}\marg{text}.
\begin{important}
If you are using \sty{hyperref} and want to use \cs{capitalisewords}
or \ics{makefirstuc} (or \cs{xcapitalisewords}\slash\cs{xmakefirstuc})
in a section heading, the PDF bookmarks won't be able to use the command
as it's not expandable, so you will get a warning that looks like:
\begin{verbatim}
Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref) removing `\capitalisewords'
\end{verbatim}
If you want to provide an alternative for the PDF bookmark, you can
use \sty{hyperref}'s \ics{texorpdfstring} command. See the
\sty{hyperref} manual for further details.
\end{important}
Examples:
\begin{enumerate}
\item
\begin{verbatim}
\capitalisewords{a book of rhyme.}
\end{verbatim}
produces:
\capitalisewords{a book of rhyme.}
\item
\begin{verbatim}
\capitalisewords{a book\space of rhyme.}
\end{verbatim}
produces:
\capitalisewords{a book\space of rhyme.}
\item
\begin{verbatim}
\newcommand{\mytitle}{a book\space of rhyme.}
\capitalisewords{\mytitle}
\end{verbatim}
produces:
\newcommand{\mytitle}{a book\space of rhyme.}
\capitalisewords{\mytitle}
(No expansion is performed on \cs{mytitle}, so \meta{text}
consists of just one ``word''.) Compare with next example:
\item
\begin{verbatim}
\newcommand{\mytitle}{a book\space of rhyme.}
\xcapitalisewords{\mytitle}
\end{verbatim}
produces:
\xcapitalisewords{\mytitle}
\end{enumerate}
\end{document}
|