summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/mfirstuc/sample-mfirstuc.tex
blob: 7438c770cc934faa33ef241eebd3c72edbaa8026 (plain)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
 % This file is public domain
 % If you want to use arara, you need the following directive:
 % arara: pdflatex: { synctex: on }
 % arara: pdflatex: { synctex: on }
\documentclass{article}

\usepackage[a4paper]{geometry}
\usepackage{color}
\usepackage{mfirstuc-english}% also loads mfirstuc.sty
\usepackage[hidelinks]{hyperref}

\title{Sample Document Illustrating the mfirstuc Package}
\author{Nicola Talbot}

\begin{document}
\maketitle

\tableofcontents

\section{First Letter Upper Case}

\verb|\makefirstuc{abc}.|
\makefirstuc{abc}.

\verb|\makefirstuc{{\em abc}}.|
\makefirstuc{{\em abc}}.

\verb|\makefirstuc{\emph{abc}}.|
\makefirstuc{\emph{abc}}.

\verb|\makefirstuc{\ae bc}.|
\makefirstuc{\ae bc}.

\verb|\makefirstuc{{\ae}bc}.|
\makefirstuc{{\ae}bc}.

\verb|\newcommand{\abc}{abc}\xmakefirstuc{\abc}.|
\newcommand{\abc}{abc}%
\xmakefirstuc{\abc}.

\newcommand*{\mytext}{\protect\textbf{some text}}
Protected formatting: \xmakefirstuc{\mytext}.

\renewcommand*{\mytext}{\ae\oe{some text}}
Sequential commands: \xmakefirstuc{\mytext}.

\verb|\makefirstuc{\MFUskippunc{?`}c\'omo est\'as?}|
\makefirstuc{\MFUskippunc{?`}c\'omo est\'as?}

\renewcommand{\mytext}{\MFUskippunc{?`}c\'omo est\'as?}
Fully expanded:
\emakefirstuc{\mytext}

\section{Title Case (No Formatting Commands)}

\bgroup

\verb|\capitalisewords{the wind in the willows}|
\capitalisewords{the wind in the willows}

\verb|\capitalisewords{a small book of rhyme.}|
\capitalisewords{a small book of rhyme.}

\medskip

\verb|\space| isn't considered a word boundary for
\verb|\capitalisewords| as shown below:

\begin{verbatim}
\capitalisewords{a small\space book of rhyme.}
\end{verbatim}
\capitalisewords{a small\space book of rhyme.}

\medskip
No expansion is performed on the argument of
\verb|\capitalisewords|:

\verb|\newcommand{\mytitle}{a small book of rhyme.}|
\newcommand{\mytitle}{a small book of rhyme.}

\verb|\capitalisewords{\mytitle}|
\capitalisewords{\mytitle}

\verb|\xcapitalisewords{\mytitle}|
\xcapitalisewords{\mytitle}

\egroup

Formatting for the entire phrase must go outside
\verb|\capitalisewords| (unlike \verb|\makefirstuc|). Compare:

\begin{verbatim}
\capitalisewords{\textbf{a small book of rhyme.}}
\end{verbatim}
\capitalisewords{\textbf{a small book of rhyme.}}

\begin{verbatim}
\textbf{\capitalisewords{a small book of rhyme.}}
\end{verbatim}
\textbf{\capitalisewords{a small book of rhyme.}}

\medskip

Use \verb|\capitalisefmtwords| instead. The starred form
is limited to one text-block command at the start of the argument.

\begin{verbatim}
\capitalisefmtwords*{\emph{a small book of rhyme}}
\end{verbatim}
\capitalisefmtwords*{\emph{a small book of rhyme}}

Additional text-block commands can cause unexpected results.

\begin{verbatim}
\capitalisefmtwords*{\emph{a small} book \textbf{of rhyme}}
\end{verbatim}
\capitalisefmtwords*{\emph{a small} book \textbf{of rhyme}}

\section{Title Case (Contains Text-Block Formatting Commands)}

The unstarred form of \verb|\capitalisefmtwords| is still a bit
experimental and is only designed
for phrases that contain text-block commands with a single
argument, which should be a word or sub-phrase.

\verb|\capitalisefmtwords{\textbf{a small book of rhyme}}.|
\capitalisefmtwords{\textbf{a small book of rhyme}}.

\verb|\capitalisefmtwords{\textbf{a small book} of rhyme}.|
\capitalisefmtwords{\textbf{a small book} of rhyme}.

\verb|\capitalisefmtwords{a \textbf{small book} of rhyme}.|
\capitalisefmtwords{a \textbf{small book} of rhyme}.

\verb|\capitalisefmtwords{\textbf{a} small book of rhyme}.|
\capitalisefmtwords{\textbf{a} small book of rhyme}.

\verb|\capitalisefmtwords{a small book \textbf{of rhyme}}.|
\capitalisefmtwords{a small book \textbf{of rhyme}}.

\medskip

Be careful of trailing spaces at the end a group. They can confuse
things.

\verb|\capitalisefmtwords{\textbf{a small }book of rhyme}.|
\capitalisefmtwords{\textbf{a small }book of rhyme}.

\verb|\capitalisefmtwords{\textbf{a small book }of rhyme}.|
\capitalisefmtwords{\textbf{a small book }of rhyme}.

\verb|\capitalisefmtwords{\textbf{a small book of }rhyme}.|
\capitalisefmtwords{\textbf{a small book of }rhyme}.

\medskip

Use semantic commands for things like quotations:

\begin{verbatim}
\newcommand*{\qt}[1]{``#1''}
\capitalisefmtwords{\qt{a small book of rhyme.}}
\end{verbatim}
\newcommand*{\qt}[1]{``#1''}
\capitalisefmtwords{\qt{a small book of rhyme.}}

\smallskip

(But make them robust if you intend using commands like
\verb|\ecapitalisefmtwords|.)
Similarly for other types of punctuation:
\begin{verbatim}
\newcommand*{\esq}[1]{'?#1?}
\capitalisefmtwords{\esq{D\'onde est\'a libro}}
\end{verbatim}
\newcommand*{\esq}[1]{?`#1?}
\capitalisefmtwords{\esq{D\'onde est\'a libro}}

\medskip

Anything more complicated than a simple one-argument text-block
command requires the starred version.

\begin{verbatim}
\newcommand*{\swap}[2]{{#2}{#1}}
\capitalisefmtwords*{\textbf{an \swap{un}{usually} small book of} rhyme}.
\end{verbatim}
\newcommand*{\swap}[2]{{#2}{#1}}
\capitalisefmtwords*{\textbf{an \swap{un}{usually} small book of} rhyme}.

\medskip

Nested text-block commands:

\begin{verbatim}
\capitalisefmtwords{\textbf{a \emph{small book} of} rhyme}.
\end{verbatim}
\capitalisefmtwords{\textbf{a \emph{small book} of} rhyme}.

\begin{verbatim}
\capitalisefmtwords{\textbf{a \emph{small book}} of rhyme}.
\end{verbatim}
\capitalisefmtwords{\textbf{a \emph{small book}} of rhyme}.

\begin{verbatim}
\capitalisefmtwords{\textbf{\emph{a small} book of} rhyme}.
\end{verbatim}
\capitalisefmtwords{\textbf{\emph{a small} book of} rhyme}.

\medskip

An empty brace at the start of a word will suppress the
case-changing.

\begin{verbatim}
\capitalisefmtwords{\textbf{a small {}book of} rhyme}.
\end{verbatim}
\capitalisefmtwords{\textbf{a small {}book of} rhyme}.

\medskip

Suppress case-changing for problematic commands by inserting
an empty group in front:

\begin{verbatim}
\capitalisefmtwords{{}\textcolor{red}{a} small book of
{}\textcolor{red}{rhyme}}.
\end{verbatim}
\capitalisefmtwords{{}\textcolor{red}{a} small book of
{}\textcolor{red}{rhyme}}.

\medskip

If possible provide semantic command instead.

\begin{verbatim}
\newcommand*{\alert}[1]{\textcolor{red}{#1}}
\capitalisefmtwords{\alert{a} small book of \alert{rhyme}}.
\end{verbatim}
\newcommand*{\alert}[1]{\textcolor{red}{#1}}
\capitalisefmtwords{\alert{a} small book of \alert{rhyme}}.

\medskip

No formatting commands in the following example:

\verb|\capitalisefmtwords{a small book of rhyme}.|
\capitalisefmtwords{a small book of rhyme}.

\medskip

Avoid scoped declarations. The next example doesn't work.

\begin{verbatim}
\capitalisefmtwords{{\bfseries a \emph{small book} of} rhyme.}
\end{verbatim}
\capitalisefmtwords{{\bfseries a \emph{small book} of} rhyme.}

\medskip

If a command isn't followed by a grouped argument, the
case-change is applied to the command (on the assumption
that it's a character command, such as \verb|\ae|). This can
have an odd effect if case-changing has no meaning for that command.
As illustrated next:

\verb|\capitalisefmtwords{\relax a book of rhyme.}|
\capitalisefmtwords{\relax a book of rhyme.}

\section{Compound Words}

Use \verb|\MFUhyphentrue| to title case each part of
a compound word.

Default:
\begin{verbatim}
\capitalisewords{a fast-paced book of rhyme}.
\capitalisefmtwords{a \textbf{fast-paced} book of rhyme}.
\end{verbatim}
\capitalisewords{a fast-paced book of rhyme}.
\capitalisefmtwords{a \textbf{fast-paced} book of rhyme}.

Compare with
\begin{verbatim}
\MFUhyphentrue
\capitalisewords{a fast-paced book of rhyme}.
\capitalisefmtwords{a \textbf{fast-paced} book of rhyme}.
\end{verbatim}
\MFUhyphentrue
\capitalisewords{a fast-paced book of rhyme}.
\capitalisefmtwords{a \textbf{fast-paced} book of rhyme}.

\end{document}