Debian Codegraph @

texmf-dist/doc/latex/mfirstuc/mfirstuc-manual.tex

raw
1 % arara: lualatex
2 % arara: bib2gls: { group: on, options: [ "--replace-quotes" ] }
3 % arara: lualatex
4 % arara: bib2gls: { group: on, options: [ "--replace-quotes" ] } if found ("log", "Glossary entry `sym.")
5 % arara: lualatex
6 % arara: lualatex if found ("log", "Rerun to")
7
8 % This document requires glossaries-extra v1.49, bib2gls v3.0
9 % and nlctuserguide.sty.
10
11 \documentclass[titlepage=false,oneside,
12 fontsize=12pt,captions=tableheading]{scrbook}
13
14 \usepackage
15 %[debug=showwrgloss]
16 {nlctuserguide}
17
18 \nlctuserguidegls
19 {
20 % \MFUsentencecase
21 \gcmd{MFU\-sen\-tence\-case}
22 {
23 \providedby{\sty{mfirstuc} v2.08+}
24 \syntax{\margm{text}}%
25 \desc{converts \meta{text} to \idx+{sentence-case} with expansion}
26 }
27 % \MFUexcl
28 \gcmd{MFU\-excl}
29 {
30 \providedby{\sty{mfirstuc} v2.08+}
31 \syntax{\margm{cs}}%
32 \desc{locally identifies \meta{cs} as an \idx{exclusion} command}
33 \field{seealso}{MFUblocker,MFUaddmap}
34 }
35 % \MFUblocker
36 \gcmd{MFU\-blocker}
37 {
38 \providedby{\sty{mfirstuc} v2.08+}
39 \syntax{\margm{cs}}%
40 \desc{locally identifies \meta{cs} as a \idx{blocker} command}
41 \field{seealso}{MFUexcl,MFUaddmap}
42 }
43 % \MFUaddmap
44 \gcmd{MFU\-add\-map}
45 {
46 \providedby{\sty{mfirstuc} v2.08+}
47 \syntax{\margm{cs1}\margm{cs2}}%
48 \desc{identifies a \idx{mapping} from the command \meta{cs1} to
49 command \meta{cs2}}
50 \field{seealso}{MFUexcl,MFUblocker}
51 }
52 % \MFUsaveatend
53 \gcmd{MFU\-save\-at\-end}
54 {
55 \providedby{\sty{mfirstuc} v2.08+}
56 \desc{saves the list of \idxpl{exclusion}, \idxpl{blocker}
57 and \idxpl{mapping} to the \ext{aux} file (if required by some
58 external tool) at the end of the document.
59 This command sets itself to \cmd{relax} so it
60 doesn't repeat the action if used multiple times, but it can
61 be overridden by \gls{MFUsave}}
62 }
63 % \MFUsave
64 \gcmd{MFU\-save}
65 {
66 \providedby{\sty{mfirstuc} v2.08+}
67 \desc{saves the list of \idxpl{exclusion}, \idxpl{blocker}
68 and \idxpl{mapping} to the \ext{aux} file (if required by some
69 external tool).
70 This command sets itself to \cmd{relax} so it
71 doesn't repeat the action if used multiple times, and
72 counteracts any use of \gls{MFUsaveatend}}
73 }
74 % \@mfu@excls
75 \gcmd{@mfu\-@\-excls}
76 {
77 \providedby{\sty{mfirstuc} v2.08+}
78 \syntax{\margm{exclusions}}
79 \desc{an \ext{aux} file command that lists all the identified
80 \idxpl{exclusion}}
81 \field{seealso}{MFUsave,MFUsaveatend}
82 }
83 % \@mfu@blockers
84 \gcmd{@mfu\-@\-blockers}
85 {
86 \providedby{\sty{mfirstuc} v2.08+}
87 \syntax{\margm{blockers}}
88 \desc{an \ext{aux} file command that lists all the identified
89 \idxpl{blocker}}
90 \field{seealso}{MFUsave,MFUsaveatend}
91 }
92 % \@mfu@mappings
93 \gcmd{@mfu\-@\-mappings}
94 {
95 \providedby{\sty{mfirstuc} v2.08+}
96 \syntax{\margm{mappings}}
97 \desc{an \ext{aux} file command that lists all the identified
98 \idxpl{mapping} as a \keyval\ list}
99 \field{seealso}{MFUsave,MFUsaveatend}
100 }
101 % \mfirstucMakeUppercase
102 \gcmd{mfirst\-uc\-Make\-Up\-per\-case}
103 {
104 \providedby{\sty{mfirstuc} v1.07+}
105 \syntax{\margm{text}}%
106 \desc{converts \meta{text} to \idx{uppercase}.
107 Now only used in \gls{mfugrabfirstuc}}
108 }
109 % \emakefirstuc
110 \gcmd{e\-make\-first\-uc}
111 {
112 \providedby{\sty{mfirstuc} v1.10+}
113 \syntax{\margm{text}}%
114 \desc{fully expands \meta{text} before passing it to
115 \gls{makefirstuc}}
116 }
117 % \xmakefirstuc
118 \gcmd{x\-make\-first\-uc}
119 {
120 \providedby{\sty{mfirstuc} v1.01+}
121 \syntax{\margm{text}}%
122 \desc{shortcut for
123 \code{\cmd{expandafter}\gls{makefirstuc}\cmd{expandafter}\margm{text}}}
124 }
125 % \makefirstuc
126 \gcmd{make\-first\-uc}
127 {
128 \providedby{\sty{mfirstuc} v1.0+}
129 \syntax{\margm{text}}%
130 \desc{converts \meta{text} to \idx+{sentence-case} internally using
131 \gls{glsmakefirstuc} to perform the case-change, but first parses
132 \meta{text} to deal with special cases}
133 }
134 % \glsmakefirstuc
135 \gcmd{gls\-make\-first\-uc}
136 {
137 \providedby{\sty{mfirstuc} v1.05+}
138 \syntax{\margm{text}}%
139 \desc{used by \gls{makefirstuc} to perform the case-change. This
140 uses \code{\gls{MFUsentencecase}\margm{text}} but by default
141 will prevent its argument from being expanded}
142 }
143 % \mfugrabfirstuc
144 \gcmd{mfu\-grab\-first\-uc}
145 {
146 \providedby{\sty{mfirstuc} v2.08+}
147 \syntax{\margm{text}}
148 \note{avoid where possible}
149 \desc{provide to emulate \gls{glsmakefirstuc} in v2.07 and
150 below, but can still produce different results to v2.07.
151 This will attempt to grab only the first character of
152 \meta{text} and convert it to \idx{uppercase}, leaving the rest of
153 \meta{text} unchanged. This won't work if \meta{text} starts
154 with a \gls{utf8} character, unless you are using \XeLaTeX\ or
155 \LuaLaTeX}
156 }
157 % \MFUskippunc
158 \gcmd{MFU\-skip\-punc}
159 {
160 \providedby{\sty{mfirstuc} v2.07+}
161 \syntax{\margm{content}}%
162 \desc{an \idx{exclusion} command}
163 }
164 % \capitalisewords
165 \gcmd{cap\-i\-talise\-words}
166 {
167 \providedby{\sty{mfirstuc} v1.06+}
168 \syntax{\margm{text}}%
169 \desc{applies \idx+{title-case} to \meta{text}. This will apply
170 \gls{MFUcapword} to each word in \meta{text} (unless the word has been
171 identified as an \idx{exclusion-word} and doesn't occur at the start of
172 \meta{text})}
173 \field{seealso}{capitalisefmtwords,MFUnocap,gMFUnocap,ifMFUhyphen}
174 }
175 % \xcapitalisewords
176 \gcmd{x\-cap\-i\-talise\-words}
177 {
178 \providedby{\sty{mfirstuc} v1.06+}
179 \syntax{\margm{text}}%
180 \desc{shortcut for
181 \code{\cmd{expandafter}\gls{capitalisewords}\cmd{expandafter}\margm{text}}}
182 }
183 % \ecapitalisewords
184 \gcmd{e\-cap\-i\-talise\-words}
185 {
186 \providedby{\sty{mfirstuc} v1.10+}
187 \syntax{\margm{text}}%
188 \desc{fully expands \meta{text} before passing it to \gls{capitalisewords}}
189 }
190 % \capitalisefmtwords
191 \gcmd{cap\-i\-talise\-fmt\-words}
192 {
193 \providedby{\sty{mfirstuc} v2.03+}
194 \syntax{\margm{text}}%
195 \desc{similar to \gls{capitalisewords} but for content that may
196 contain formatting commands}
197 \field{modifiers}{*}
198 \field{seealso}{capitalisewords,MFUnocap,gMFUnocap,ifMFUhyphen}
199 }
200 % \xcapitalisefmtwords
201 \gcmd{x\-cap\-i\-talise\-fmt\-words}
202 {
203 \providedby{\sty{mfirstuc} v2.03+}
204 \syntax{\margm{text}}%
205 \desc{shortcut for
206 \code{\cmd{expandafter}\gls{capitalisefmtwords}\cmd{expandafter}\margm{text}}
207 including the \code{*} modifier, if provided}
208 \field{modifiers}{*}
209 }
210 % \ecapitalisefmtwords
211 \gcmd{e\-cap\-i\-talise\-fmt\-words}
212 {
213 \providedby{\sty{mfirstuc} v2.03+}
214 \syntax{\margm{text}}%
215 \desc{fully expands \meta{text} and passes it to
216 \gls{capitalisefmtwords} including the \code{*} modifier, if provided}
217 \field{modifiers}{*}
218 }
219 % \ifMFUhyphen
220 \gcond{if\-MFU\-hyphen}
221 {
222 \initval{\cmd{iffalse}}
223 \providedby{\sty{mfirstuc} v2.03+}
224 \desc{conditional that determines whether or not hyphens should
225 be considered word boundaries by the \idx{title-case} commands}
226 }
227 % \MFUhyphentrue
228 \gcmd{MFU\-hyphen\-true}
229 {
230 \providedby{\sty{mfirstuc} v2.03+}
231 \desc{sets \gls{ifMFUhyphen} to true}
232 }
233 % \MFUhyphenfalse
234 \gcmd{MFU\-hyphen\-false}
235 {
236 \providedby{\sty{mfirstuc} v2.03+}
237 \desc{sets \gls{ifMFUhyphen} to false}
238 }
239 % \MFUwordbreak
240 \gcmd{MFU\-word\-break}
241 {
242 \providedby{\sty{mfirstuc} v2.07+}
243 \syntax{\margm{text}}%
244 \desc{used to markup a character or command that should be
245 treated as a word break by the \idx{title-case} commands}
246 }
247 % \MFUcapword
248 \gcmd{MFU\-cap\-word}
249 {
250 \providedby{\sty{mfirstuc} v2.03+}
251 \syntax{\margm{text}}%
252 \desc{uses either \gls{MFUhyphencapword} or \gls{MFUcapwordfirstuc}
253 depending on \gls{ifMFUhyphen}}
254 }
255 % \MFUcapwordfirstuc
256 \gcmd{MFU\-cap\-word\-first\-uc}
257 {
258 \providedby{\sty{mfirstuc} v2.07+}
259 \syntax{\margm{word}}%
260 \desc{used by \gls{MFUcapword} and \gls{MFUhyphencapword} to
261 apply the case-change to the given word. This just does
262 \code{\gls{makefirstuc}\margm{text}} by default}
263 \field{seealso}{MFUcapword,MFUhyphencapword}
264 }
265 % \MFUhyphencapword
266 \gcmd{MFU\-hyphen\-cap\-word}
267 {
268 \providedby{\sty{mfirstuc} v2.07+}
269 \syntax{\margm{text}}%
270 \desc{used by \gls{MFUcapword} to apply \gls{MFUcapwordfirstuc} to
271 each hyphen-separated word in \meta{text}, if hyphens should
272 indicate a word-break}
273 \field{seealso}{ifMFUhyphen,MFUcapword}
274 }
275 % \MFUnocap
276 \gcmd{MFU\-no\-cap}
277 {
278 \providedby{\sty{mfirstuc} v1.09+}
279 \syntax{\margm{word}}%
280 \desc{locally adds \meta{word} to the \idx{exclusion-word} list for
281 \gls{capitalisewords}}
282 \field{seealso}{gMFUnocap,MFUclear}
283 }
284 % \gMFUnocap
285 \gcmd{gMFU\-no\-cap}
286 {
287 \providedby{\sty{mfirstuc} v1.09+}
288 \syntax{\margm{word}}%
289 \desc{globally adds \meta{word} to the \idx{exclusion-word} list for
290 \gls{capitalisewords}}
291 \field{seealso}{MFUnocap,MFUclear}
292 }
293 % \MFUclear
294 \gcmd{MFU\-clear}
295 {
296 \providedby{\sty{mfirstuc} v1.09+}
297 \desc{locally clears the \idx{exclusion-word} list for \gls{capitalisewords}}
298 \field{seealso}{gMFUnocap,MFUnocap}
299 }
300 % PACKAGE OPTIONS
301 % option grabfirst
302 \gopt{grab\-first}
303 {%
304 \providedby{\sty{mfirstuc} v2.08+}
305 \note{avoid where possible}
306 \desc{redefines \gls{glsmakefirstuc} to use \gls{mfugrabfirstuc}
307 and \gls{mfirstucMakeUppercase} to use \gls{MakeUppercase}}
308 }
309 % option expanded
310 \gopt{expanded}
311 {%
312 \providedby{\sty{mfirstuc} v2.08+}
313 \desc{redefines \gls{glsmakefirstuc} to use \gls{MFUsentencecase}
314 without inhibiting the expansion of its argument}
315 }
316 % option unexpanded
317 \gopt{unexpanded}
318 {%
319 \providedby{\sty{mfirstuc} v2.08+}
320 \desc{redefines \gls{glsmakefirstuc} to use \gls{MFUsentencecase}
321 but inhibits expansion of its argument}
322 }
323 % COMMANDS: index only
324 \gcmd{text\dsb title\-case\dsb first:n}{}
325 \gcmd{text\dsb title\-case:n}{}
326 \gcmd{text\dsb upper\-case:n}{}
327 \gcmd{l\dsb text\dsb case\dsb ex\-clude\dsb arg\dsb tl}{}
328 \gcmd{protect}{}
329 \gcmd{unexpanded}{}
330 \gcmd{glsadd}{}
331 \gcmd{gls}{}
332 \gcmd{Gls}{}
333 \gcmd{GLS}{}
334 \gcmd{glspl}{}
335 \gcmd{Glspl}{}
336 \gcmd{GLSpl}{}
337 \gcmd{Make\-Upper\-case}{}% \MakeUppercase
338 \gcmd{Make\-Text\-Upper\-case}{}% \MakeTextUppercase
339 \gcmd{No\-Case\-Change}{}% \NoCaseChange
340 \gcmd{ensure\-math}{}
341 \gcmd{begin}{}
342 \gcmd{end}{}
343 \gcmd{cite}{}
344 \gcmd{label}{}
345 \gcmd{ref}{}
346 \gcmd{index}{}
347 \gcmd{space}{}
348 \gcmd{name\-ref}{}% \nameref
349 \gcmd{tex\-or\-pdf\-string}{}% \texorpdfstring
350 \gcmd{pdf\-string\-def\-Dis\-able\-Commands}{}% \pdfstringdefDisableCommands
351 \gpunc{nbsp}{\name{\code{\textasciitilde}}}% ~
352 % packages
353 \gpkg{mfirst\-uc}{\common}
354 \gpkg{mfirstuc\dhyphen english}{}
355 \gpkg{glossaries}{}
356 \gpkg{glossaries\dhyphen extra}{}
357 \gpkg{text\-case}{}% textcase
358 \gpkg{cs\-quotes}{}% csquotes
359 \gpkg{hyper\-ref}{}% hyperref
360 % file extensions
361 \gext{aux}{}
362 % terms
363 \gterm{exclusion}{\name{exclusion command}\field{text}{exclusion}
364 \desc{a command whose argument should be skipped
365 by the case-changer. The content that follows the command should
366 have its case-changed instead. See \sectionref{sec:exclusions}}}
367 \gterm{blocker}{\desc{a command that prohibits case-changing. If
368 encountered by \gls{makefirstuc}, it won't attempt to apply any
369 case-changing. See \sectionref{sec:blockers}}}
370 \gterm{mapping}{\desc{a command that should be substituted by
371 another, if encountered by \gls{makefirstuc}, instead of applying
372 a case-change. See \sectionref{sec:mappings}}}
373 \gterm{sentence-case}{\desc{content that should appear at the
374 start of a sentence that needs to have its first significant
375 character converted to \idx{uppercase}. See \sectionref{sec:sentencecase}}}
376 \gterm{title-case}{\desc{content that needs to appear in a title
377 that should have each significant word converted to
378 \idx{sentence-case}. See \sectionref{sec:capitalisewords}}}
379 \gterm{exclusion-word}{\name{exclusion word}
380 \desc{a word that shouldn't have its case changed by
381 \idx{title-case} commands, unless the word occurs at the start}}
382 \gtermacr{utf8}{UTF-8}{Unicode Transformation Format (8-bit)}
383 {%
384 \desc{a variable-width encoding that uses 8-bit code units. This
385 means that some characters are represented by more that one byte.
386 \XeLaTeX\ and \LuaLaTeX\ treat the multi-byte sequence as a single
387 token, but the older \LaTeX\ formats have single-byte tokens, which
388 can cause complications, although these have mostly been addressed with
389 the newer kernels introduced over the past few years. Related blog article:
390 \blog{binary-files-text-files-and-file-encodings/}{Binary Files,
391 Text Files and File Encodings}}
392 }
393 \gterm{semanticcommand}{\name{semantic command}
394 \desc{essentially, this is a command associated with a
395 particular element, idea or topic that hides the font
396 and other stylistic formatting inside its definition. For
397 example, Latin taxonomy is usually displayed in italic.
398 Explicitly using font commands, for example
399 \begin{compactcodebox}\cmd{textit}\marg{Clostridium}\end{compactcodebox}
400 is syntactic markup.
401 Whereas defining a command called, say, \cmd{bacteria} that
402 displays its argument in italics is a semantic command. The
403 actual styling is hidden and the command relates specifically to
404 a particular concept.
405 \begin{codebox}
406 Syntactic: \cmd{textit}\marg{Clostridium}^^J\codepar
407 \cmd{newrobustcmd}*\marg{\cmd{bacteria}}[1]{\cmd{emph}\marg{\#1}}\%\newline
408 Semantic: \cmd{bacteria}\marg{Clostridium}
409 \end{codebox}
410 The end result is the same:
411 \begin{resultbox}
412 Syntactic: \textit{Clostridium}\glspar
413 Semantic: \emph{Clostridium}
414 \end{resultbox}
415 The advantage with semantic commands is that it's much easier to
416 change the style, simply by adjusting the command definition.
417 Note that I've used \cmd{newrobustcmd} to make the semantic
418 command robust as the style commands can cause a problem if they
419 expand too soon}
420 }
421 % index only
422 \gidx{punctuation}{}
423 \gpunc{sym.dollar}{\name{\code{\$}}}% $
424 \gidx{uppercase}{}
425 \gidx{lowercase}{}
426 }
427
428 \title{mfirstuc.sty v2.09:
429 sentence and title casing}
430 \author{Nicola L.C. Talbot\\[10pt]
431 Dickimaw Books\\
432 \href{https://www.dickimaw-books.com/}{\nolinkurl{dickimaw-books.com}}}
433 \date{2025-04-03
434 }
435
436 \begin{document}
437 \maketitle
438
439 \htmlavailable
440
441 \begin{information}
442 The \sty{mfirstuc} package was originally part of the
443 \sty{glossaries} bundle (added to \sty{glossaries} v1.12
444 in 2008) for use with commands like \gls{Gls},
445 which need to have the first letter converted to uppercase
446 (\idx{sentence-case}), but as the commands provided by
447 \sty{mfirstuc} may be used without \sty{glossaries}, the two
448 were split into separately maintained packages in 2015
449 (\sty{mfirstuc} v2.0 and \sty{glossaries} v4.18).
450 \end{information}
451
452 Version 2.08 has reimplemented \gls{makefirstuc} using \LaTeX3
453 commands. If there are any compatibility issues, you can rollback to
454 v2.07:
455 \begin{codebox}
456 \cmd{usepackage}\marg{mfirstuc}[=2.07]
457 \end{codebox}
458
459 \frontmatter
460 \tableofcontents
461
462 \mainmatter
463 \chapter{Sentence-Case}
464 \label{sec:sentencecase}
465
466 There are two \idx{sentence-case} commands provided: \gls{MFUsentencecase}
467 and \gls{makefirstuc}. A summary of the principle features of
468 the two commands is given in
469 \tableref{tab:sentencecasesummary}.
470
471 \begin{table}[htbp]
472 \caption{Principle features of
473 \glsfmttext{MFUsentencecase} and \glsfmttext{makefirstuc}}
474 \label{tab:sentencecasesummary}
475 \centering
476 \begin{tabular}{lcc}
477 \bfseries Feature & \bfseries \gls{MFUsentencecase}[]
478 & \bfseries \gls{makefirstuc}[]\\
479 Can expand? & \proyes & \prono\\
480 Supports \idxpl{exclusion}? & \proyes & \proyes\\
481 Supports \idxpl{blocker}? & \prono & \proyes\\
482 Supports \idxpl{mapping}? & \prono & \proyes\\
483 Semantic commands must be robust? & \conyes & \conno
484 \end{tabular}
485 \end{table}
486
487 \section{Examples}
488 \label{sec:sentencecaseex}
489
490 Text only (leading \idx{utf8} now supported):
491 \begin{coderesult}
492 \gls{makefirstuc}\marg{élite} /
493 \gls{MFUsentencecase}\marg{élite}
494 \tcblower
495 \makefirstuc{élite} /
496 \MFUsentencecase{élite}
497 \end{coderesult}
498
499 Leading \idx{punctuation} is ignored:
500 \begin{coderesult}
501 \gls{makefirstuc}\marg{`word'} /
502 \gls{MFUsentencecase}\marg{`word'}
503 \tcblower
504 \makefirstuc{`word'} /
505 \MFUsentencecase{`word'}
506 \end{coderesult}
507 However, if the \idx{punctuation} character is followed by a
508 \idx{blocker} or \idx{mapping} command, the \idx{punctuation} will
509 need to be excluded otherwise the command will be treated as an
510 \idx{exclusion}. If possible, use \idxc{semanticcommand}{semantic
511 markup} instead of directly including the \idx{punctuation}.
512
513 Fragile commands need to be protected with
514 \gls{MFUsentencecase}:
515 \begin{codebox}
516 \cmd{newcommand}\marg{\cmd{alert}}[1]\marg{\cmd{textcolor}\marg{red}\marg{\cmd{textbf}\marg{\#1}}}
517 \gls{makefirstuc}\marg{\cmd{alert}\marg{élite}} /
518 \gls{MFUsentencecase}\marg{\strong{\cmd{protect}}\cmd{alert}\marg{élite}}
519 \end{codebox}
520 \begin{resultbox}
521 \newcommand{\alert}[1]{\textcolor{red}{\textbf{#1}}}
522 \makefirstuc{\alert{élite}} /
523 \MFUsentencecase{\protect\alert{élite}}
524 \end{resultbox}
525
526 \Idxpl{exclusion} are supported by both \gls{makefirstuc} and
527 \gls{MFUsentencecase}:
528 \begin{codebox}
529 \gls{MFUexcl}\marg{\gls+{index}}
530 \gls{makefirstuc}\marg{\gls{index}\marg{word}example} /
531 \gls{MFUsentencecase}\marg{\gls{index}\marg{word}example}
532 \end{codebox}
533 \begin{resultbox}
534 \MFUexcl{\index}
535 \makefirstuc{\index{example}example} /
536 \MFUsentencecase{\index{example}example}
537 \end{resultbox}
538
539 \Idxpl{blocker} are only supported by \gls{makefirstuc}.
540 They are treated as \idxpl{exclusion} with
541 \gls{MFUsentencecase}, which produces a different result:
542 \begin{codebox}
543 \gls{MFUblocker}\marg{\gls+{nameref}}
544 \gls{makefirstuc}\marg{\gls{nameref}\marg{sec:sentencecase} section} /
545 \gls{MFUsentencecase}\marg{\gls{nameref}\marg{sec:sentencecase} section}
546 \end{codebox}
547 \begin{resultbox}
548 \MFUblocker{\nameref}
549 \makefirstuc{\nameref{sec:sentencecase} section} /
550 \MFUsentencecase{\nameref{sec:sentencecase} section}
551 \end{resultbox}
552
553 \Idxpl{mapping} are only supported by \gls{makefirstuc}.
554 They are treated as \idxpl{exclusion} with
555 \gls{MFUsentencecase}, which produces a different result:
556 \begin{codebox}
557 \cmd{newrobustcmd}\marg{\cmd{secref}}[1]\marg{section\glstildechar\cmd{ref}\marg{\#1}}
558 \cmd{newrobustcmd}\marg{\cmd{Secref}}[1]\marg{Section\glstildechar\cmd{ref}\marg{\#1}}
559 \gls{MFUaddmap}\marg{\cmd{secref}}\marg{\cmd{Secref}}
560 \gls{makefirstuc}\marg{\cmd{secref}\marg{sec:sentencecase} example} /
561 \gls{MFUsentencecase}\marg{\cmd{secref}\marg{sec:sentencecase} example}
562 \end{codebox}
563 \begin{resultbox}
564 \newrobustcmd{\secref}[1]{section~\ref{#1}}
565 \newrobustcmd{\Secref}[1]{Section~\ref{#1}}
566 \MFUaddmap{\secref}{\Secref}
567 \makefirstuc{\secref{sec:sentencecase} example} /
568 \MFUsentencecase{\secref{sec:sentencecase} example}
569 \end{resultbox}
570
571 Argument expansion: \gls{MFUsentencecase} expands its argument
572 and then skips exclusions whereas \gls{makefirstuc} parses its
573 argument without expansion and then passes the relevant content to
574 \gls{glsmakefirstuc}. Note that different results will occur with
575 the \opt{expanded} and \opt{unexpanded} package options.
576 For example:
577 \begin{codebox}
578 \cmd{usepackage}[\opt{expanded}]\marg{mfirstuc}
579 \cmd{newcommand}\marg{\cmd{testa}}\marg{sample}
580 \cmd{newcommand}\marg{\cmd{testb}}\marg{\cmd{testa}\cmd{ }test}
581 \cbeg{document}
582 \gls{makefirstuc}\marg{\cmd{testb}} / \gls{xmakefirstuc}\marg{\cmd{testb}} /
583 \gls{emakefirstuc}\marg{\cmd{testb}} / \gls{MFUsentencecase}\marg{\cmd{testb}}
584 \cend{document}
585 \end{codebox}
586 \begin{resultbox}
587 \newcommand{\testa}{sample}%
588 \newcommand{\testb}{\testa\ test}%
589 \renewcommand*{\glsmakefirstuc}[1]{\MFUsentencecase{#1}}%
590 \makefirstuc{\testb} / \xmakefirstuc{\testb} /
591 \emakefirstuc{\testb} / \MFUsentencecase{\testb}
592 \end{resultbox}
593 With the default \opt{unexpanded} option the result is:
594 \begin{resultbox}
595 \newcommand{\testa}{sample}
596 \newcommand{\testb}{\testa\ test}
597 \makefirstuc{\testb} / \xmakefirstuc{\testb} /
598 \emakefirstuc{\testb} / \MFUsentencecase{\testb}
599 \end{resultbox}
600 Note that this is different from the result in earlier versions of
601 \sty{mfirstuc}.
602 \begin{codebox}
603 \cmd{usepackage}\marg{mfirstuc}[=v2.07]
604 \cmd{newcommand}\marg{\cmd{testa}}\marg{sample}
605 \cmd{newcommand}\marg{\cmd{testb}}\marg{\cmd{testa}\cmd{ }test}
606 \cbeg{document}
607 \gls{makefirstuc}\marg{\cmd{testb}} / \gls{xmakefirstuc}\marg{\cmd{testb}} /
608 \gls{emakefirstuc}\marg{\cmd{testb}}
609 \cend{document}
610 \end{codebox}
611 This produces:
612 \begin{resultbox}
613 SAMPLE TEST / SAMPLE test / Sample test
614 \end{resultbox}
615 If this old result is required, either use rollback or try
616 the \opt{grabfirst} option.
617
618 Argument expansion with \idxpl{mapping} (and the default
619 \opt{unexpanded} option):
620 \begin{codebox}
621 \cmd{newrobustcmd}\marg{\cmd{secref}}[1]\marg{section\glstildechar\cmd{ref}\marg{\#1}}
622 \cmd{newrobustcmd}\marg{\cmd{Secref}}[1]\marg{Section\glstildechar\cmd{ref}\marg{\#1}}
623 \gls{MFUaddmap}\marg{\cmd{secref}}\marg{\cmd{Secref}}
624 \cmd{newcommand}\marg{\cmd{testa}}\marg{\cmd{secref}\marg{sec:sentencecase}}
625 \cmd{newcommand}\marg{\cmd{testb}}\marg{\cmd{testa}\cmd{ }example}
626 \gls{makefirstuc}\marg{\cmd{testb}} / \gls{xmakefirstuc}\marg{\cmd{testb}} /
627 \gls{emakefirstuc}\marg{\cmd{testb}} / \gls{MFUsentencecase}\marg{\cmd{testb}}
628 \end{codebox}
629 \begin{resultbox}
630 \newrobustcmd{\secref}[1]{section~\ref{#1}}
631 \newrobustcmd{\Secref}[1]{Section~\ref{#1}}
632 \MFUaddmap{\secref}{\Secref}
633 \newcommand{\testa}{\secref{sec:sentencecase}}
634 \newcommand{\testb}{\testa\ example}
635 \makefirstuc{\testb} / \xmakefirstuc{\testb} /
636 \emakefirstuc{\testb} / \MFUsentencecase{\testb}
637 \end{resultbox}
638
639 \section{Sentence Case Commands}
640 \label{sec:sentencecasecmds}
641
642 \cmddef{MFUsentencecase}
643 This simply uses \gls{texttitlecasefirst:n}, which is provided by
644 the \LaTeX3 kernel. Note that this fully expands the argument.
645 If you use this command, ensure that your \idxpl{semanticcommand} are
646 robust. For example:
647 \begin{codebox}
648 \cmd{newrobustcmd}\marg{\cmd{alert}}[1]\marg{\cmd{textcolor}\marg{red}\marg{\cmd{textbf}\marg{\#1}}}
649 \gls{MFUsentencecase}\marg{\cmd{alert}\marg{sample} text}
650 \end{codebox}
651 \begin{resultbox}
652 \newrobustcmd{\alert}[1]{\textcolor{red}{\textbf{#1}}}
653 \MFUsentencecase{\alert{sample} text}
654 \end{resultbox}
655 Note that the following will fail:
656 \begin{badcodebox}
657 \cmd{newcommand}\marg{\cmd{alert}}[1]\marg{\cmd{textcolor}\marg{red}\marg{\cmd{textbf}\marg{\#1}}}
658 \gls{MFUsentencecase}\marg{\cmd{alert}\marg{sample} text}
659 \end{badcodebox}
660 This is because the expansion that's performed before the case-change will result in:
661 \begin{badcodebox}
662 \cmd{textcolor}\marg{Red}\marg{\cmd{textbf}\marg{sample}} text
663 \end{badcodebox}
664 This triggers an error since \code{Red} isn't a recognised colour
665 name.
666
667 \cmddef{makefirstuc}
668 This is the original command provided by \sty+{mfirstuc}, which was
669 written to assist sentence-casing in the \sty{glossaries} package
670 and had to take markup into account. It parses its argument to try
671 to determine which part needs the case-change. The actual
672 case-change is performed by \gls{glsmakefirstuc}.
673
674 As from v2.08, the definition of \gls{makefirstuc} has been updated to use \LaTeX3
675 code, but the argument is still parsed, which allows for non-robust
676 \idxpl{semanticcommand}, and now also takes \idxpl{blocker} and \idxpl{mapping} into
677 account. For example:
678 \begin{codebox}
679 \cmd{newcommand}\marg{\cmd{alert}}[1]\marg{\cmd{textcolor}\marg{red}\marg{\cmd{textbf}\marg{\#1}}}
680 \gls{makefirstuc}\marg{\cmd{alert}\marg{sample} text}
681 \end{codebox}
682 \begin{resultbox}
683 \newcommand{\alert}[1]{\textcolor{red}{\textbf{#1}}}
684 \makefirstuc{\alert{sample} text}
685 \end{resultbox}
686
687 The rules used when parsing \code{\gls{makefirstuc}\margm{text}} are as follows:
688 \begin{enumerate}
689 \item if \meta{text} is empty do nothing;
690
691 \item if \meta{text} consists of a single item or starts
692 with a group do \code{\gls{glsmakefirstuc}\margm{text}};
693
694 \item if \meta{text} starts with a command \meta{cs}:
695
696 \begin{enumerate}
697 \item if \meta{cs} is \gls{protect}, skip it and continue to
698 the next step where the command \meta{cs} under inspection
699 is now the one that follows \gls{protect}:
700
701 \item if \meta{cs} has been identified as a \idx{blocker}, just do
702 \meta{text} (that is, no case-change is applied);
703
704 \item if \meta{cs} isn't followed by a group then do
705 \code{\gls{glsmakefirstuc}\margm{text}};
706
707 \item otherwise assume the format is \code{\meta{cs}\margm{arg}\meta{following}}
708 (where \meta{following} may be empty) and then:
709
710 \begin{enumerate}
711 \item if \meta{cs} has been \idxc{mapping}{mapped} to
712 \meta{Cs} then do \code{\meta{Cs}\margm{arg}\meta{following}};
713
714 \item if \meta{cs} has been identified as an \idx{exclusion},
715 do \code{\meta{cs}\margm{arg}\gls{makefirstuc}\margm{following}};
716
717 \item otherwise do \code{\meta{cs}\marg{\gls{makefirstuc}\margm{arg}}\meta{following}}.
718 \end{enumerate}
719
720 \end{enumerate}
721
722 \item otherwise do \code{\gls{glsmakefirstuc}\margm{text}}.
723 \end{enumerate}
724
725 Note that the above algorithm uses recursion. The termination points
726 are: don't implement a change, replace a command with another
727 command, or apply the case-change via \gls{glsmakefirstuc}.
728
729 For convenience, the following commands are also provided:
730 \cmddef{xmakefirstuc}
731 This is simply a shortcut for:
732 \begin{compactcodebox}
733 \cmd{expandafter}\gls{makefirstuc}\cmd{expandafter}\margm{text}
734 \end{compactcodebox}
735 This ensures the first token in \meta{text} is expanded before being
736 passed to \gls{makefirstuc}.
737
738 \cmddef{emakefirstuc}
739 This fully expands its argument before passing it to
740 \gls{makefirstuc}. For example:
741 \begin{codebox}
742 \cmd{newcommand}\marg{\cmd{test}}[1]\marg{sample \#1}
743 \cmd{newcommand}\marg{\cmd{tmp}}\marg{\cmd{test}\marg{text}}
744 \gls{makefirstuc}\marg{\cmd{tmp}} /
745 \gls{xmakefirstuc}\marg{\cmd{tmp}} /
746 \gls{emakefirstuc}\marg{\cmd{tmp}}
747 \end{codebox}
748 \begin{resultbox}
749 \newcommand{\test}[1]{sample #1}
750 \newcommand{\tmp}{\test{text}}
751 \makefirstuc{\tmp} /
752 \xmakefirstuc{\tmp} /
753 \emakefirstuc{\tmp}
754 \end{resultbox}
755 If you don't have any mappings or blockers set up, it's simpler to
756 use \gls{MFUsentencecase} instead of \gls{emakefirstuc}.
757
758 \begin{important}
759 With \gls{emakefirstuc}, mappings and blockers will only be
760 detected if they are robust or protected, otherwise they will expand too soon to
761 be detected.
762 \end{important}
763
764 \cmddef{glsmakefirstuc}
765 This command is used by \gls{makefirstuc} to perform the
766 case-change. The \qt{gls} prefix is for historical reasons as the original code
767 was part of the \sty{glossaries} package. With the default
768 \opt{unexpanded} option, this command is defined as:
769 \begin{compactcodebox}
770 \gls{MFUsentencecase}\marg{\gls+{unexpanded}\margm{text}}
771 \end{compactcodebox}
772 The use of \gls{unexpanded} inhibits the expansion of \meta{text}
773 that would otherwise occur. This allows \gls{makefirstuc} to
774 maintain as much backward-compatibility with version 2.07 as
775 possible. This is particularly important when using the
776 \sty{glossaries} package with a style that automatically converts
777 the description to \idx{sentence-case}, as there may well be
778 documents with complex descriptions that contain fragile commands.
779
780 The \opt{expanded} package option will redefine \gls{glsmakefirstuc}
781 to use \gls{MFUsentencecase} without \gls{unexpanded}. The
782 \opt{grabfirst} package option will redefine \gls{glsmakefirstuc}
783 to use \gls{mfugrabfirstuc} to emulates the behaviour of
784 \gls{glsmakefirstuc} in v2.07 and below without using rollback.
785
786 \cmddef{mfugrabfirstuc}
787 This robust command is provided to emulate v2.07 and its use is discouraged.
788 Note that you may still have different results compared to v2.07, so
789 you may need to use rollback instead. (Note that the \opt{grabfirst} option
790 additionally redefines \gls{mfirstucMakeUppercase} to
791 \gls{MakeUppercase}, which you will also need.)
792
793 This applies \gls{mfirstucMakeUppercase} to the first token in \meta{text}
794 and leaves the remainder unchanged. This won't work if \meta{text}
795 starts with a \gls{utf8} character unless you use \XeLaTeX\ or
796 \LuaLaTeX, so avoid using this method where possible. For example:
797 \begin{codebox}
798 \cmd{renewcommand}\marg{\gls{mfirstucMakeUppercase}}[1]\marg{\comment{}
799 \gls{MakeUppercase}\marg{\#1}\comment{}
800 }
801 \gls{mfugrabfirstuc}\marg{sample}
802 \end{codebox}
803 This is equivalent to:
804 \begin{codebox}
805 \gls{mfirstucMakeUppercase}\marg{s}ample
806 \end{codebox}
807 Whereas
808 \begin{unicodebox}
809 \cmd{renewcommand}\marg{\gls{mfirstucMakeUppercase}}[1]\marg{\comment{}
810 \gls{MakeUppercase}\marg{\#1}\comment{}
811 }
812 \gls{mfugrabfirstuc}\marg{\'elite}
813 \end{unicodebox}
814 only works with \XeLaTeX\ or \LuaLaTeX.
815
816 \begin{warning}
817 As with earlier implementations of \gls{makefirstuc} that
818 tried to only apply the case-change to the first token,
819 this won't produce the desired result if the argument starts with a
820 punctuation character.
821 \end{warning}
822
823 For example:
824 \begin{codebox}
825 \gls{mfugrabfirstuc}\marg{`sample'}
826 \end{codebox}
827 This is equivalent to:
828 \begin{compactcodebox}
829 \gls{mfirstucMakeUppercase}\marg{`}sample'
830 \end{compactcodebox}
831 so no case-change is applied.
832
833 \section{Exclusions}
834 \label{sec:exclusions}
835
836 \begin{information}
837 Exclusions will apply to all \LaTeX3 case-changing commands, so will
838 also affect \gls{mfirstucMakeUppercase}, but this is generally
839 desirable.
840 \end{information}
841
842 \cmddef{MFUexcl}
843 Identifies the text-block command \code{\meta{cs}\margm{arg}} as
844 an \idx{exclusion}. That is, one that should have its argument
845 excluded from a case-change.
846
847 Internally, \gls{MFUexcl} adds \meta{cs} to \LaTeX3's exclusion list
848 \gls{ltextcaseexcludeargtl}, which means that \gls{MFUsentencecase}
849 will skip the command and its argument and apply the case-change to
850 the following content. Some common commands (\gls{begin} \gls{cite}
851 \gls{end} \gls{label} and \gls{ref}) are automatically added by the
852 \LaTeX3 kernel.
853 The exclusions are also recognised by \gls{makefirstuc} when it
854 parses its argument.
855
856 \begin{information}
857 The command \gls{NoCaseChange} is automatically treated as an
858 exclusion by the \LaTeX3 case-changing commands with recent \LaTeX\
859 kernels. You may want to add it as a blocker for \gls{makefirstuc}
860 and keep \gls{MFUskippunc} for exclusions.
861
862 Note that \gls{ensuremath} is added as an exclusion by \sty{mfirstuc} otherwise
863 \gls{makefirstuc} will pass its argument to \gls{MFUsentencecase},
864 which will cause a problem.
865 \end{information}
866
867 Another way of identifying content that should be excluded with
868 \gls{makefirstuc} is to encapsulate it with:
869 \cmddef{MFUskippunc}
870 This is a robust command that simply does its argument and is
871 automatically added to the exclusion list. This may be used for
872 cases where the excluded command isn't a simple text-block command
873 that only has one mandatory argument or where leading punctuation is
874 followed by a \idx{blocker} or \idx{mapping}.
875
876 The command name stems from earlier versions where leading
877 \idx{punctuation} needed to be skipped. This is no longer necessary,
878 but the command remains as a general purpose robust exclusion command.
879
880 For example, \gls{glsadd} (provided by \sty{glossaries}) should have
881 its argument skipped, since its argument is a label, so the
882 following will ensure that \code{\gls{glsadd}\margm{label}} will be
883 skipped, and the case-change will be applied to the following text
884 for both \gls{MFUsentencecase} and \gls{makefirstuc}.
885 \begin{codebox}
886 \gls{MFUexcl}\marg{\gls{glsadd}}
887 \gls{makefirstuc}\marg{\gls{glsadd}\marg{ex}some text}
888 \gls{MFUsentencecase}\marg{\gls{glsadd}\marg{ex}some text}
889 \end{codebox}
890 This will be equivalent to:
891 \begin{compactcodebox}
892 \gls{glsadd}\marg{ex}Some text
893 \end{compactcodebox}
894 However, \gls{glsadd} can take an optional argument which, if
895 present, will cause a problem. For example:
896 \begin{badcodebox}
897 \gls{MFUexcl}\marg{\gls{glsadd}}
898 \gls{makefirstuc}\marg{\gls{glsadd}\oarg{counter=section}\marg{ex}some text}
899 \gls{MFUsentencecase}\marg{\gls{glsadd}\oarg{counter=section}\marg{ex}some text}
900 \end{badcodebox}
901 Both commands will cause the following error:
902 \begin{transcript}
903 ! Package glossaries Error: Glossary entry `\nlctopensqbracket' has not been defined.
904 \end{transcript}
905 This is because the open square bracket is assumed to be the
906 argument of \gls{glsadd}, so this effectively becomes:
907 \begin{compactcodebox}
908 \gls{glsadd}\marg{\nlctopensqbracket}Counter=section\nlctclosesqbracket exsome text
909 \gls{glsadd}\marg{\nlctopensqbracket}Counter=section\nlctclosesqbracket exsome text
910 \end{compactcodebox}
911 which means that now \code{\nlctopensqbracket} is considered the label and everything
912 that follows is just text.
913
914 For this situation to work, you need to encapsulate the problematic
915 content with an exclusion command, such as \gls{NoCaseChange} or \gls{MFUskippunc}:
916 \begin{codebox}
917 \gls{makefirstuc}\marg{\gls{MFUskippunc}\marg{\gls{glsadd}\oarg{counter=section}\marg{ex}}some text}
918 \end{codebox}
919 This will also work with \gls{MFUsentencecase} because
920 \sty{mfirstuc} automatically adds \gls{MFUskippunc} to the exclusion
921 list.
922
923 \begin{information}
924 As from \sty{glossaries} v4.50, \gls{glsadd} is automatically added
925 as an exclusion, but be aware of the problem with using the optional
926 argument, as described above.
927 \end{information}
928
929 \Idx{punctuation} characters are skipped by \gls{MFUsentencecase}.
930 For example:
931 \begin{coderesult}
932 \gls{MFUsentencecase}\marg{`word'}
933 \tcblower
934 \MFUsentencecase{`word'}
935 \end{coderesult}
936 However, leading \idx{punctuation} will result in \gls{makefirstuc}
937 passing its entire argument to \gls{MFUsentencecase} (since the
938 argument doesn't start with \code{\meta{cs}\margm{arg}}), which
939 means that \gls{makefirstuc} won't detect any \idx{blocker} or
940 \idx{mapping}.
941
942 For example:
943 \begin{codebox}
944 \gls{MFUblocker}\marg{\gls+{nameref}}
945 \cmd{newcommand}*\marg{\cmd{qt}}[1]\marg{``\#1''}
946 \gls{makefirstuc}\marg{``\gls{nameref}\marg{sec:sentencecase} section''} /
947 \gls{makefirstuc}\marg{\gls{MFUskippunc}\marg{``}\gls{nameref}\marg{sec:sentencecase} section''} /
948 \gls{makefirstuc}\marg{\cmd{qt}\marg{\gls{nameref}\marg{sec:sentencecase} section}}
949 \end{codebox}
950 \begin{resultbox}
951 \MFUblocker{\nameref}
952 \makefirstuc{``\nameref{sec:sentencecase} section''} /
953 \makefirstuc{\MFUskippunc{``}\nameref{sec:sentencecase} section''} /
954 \makefirstuc{\qt{\nameref{sec:sentencecase} section}}
955 \end{resultbox}
956 If you are using a package such as \sty{csquotes}, bear in mind that
957 if the command is followed by an asterisk (a \qt{starred command})
958 or an optional argument then it won't fit the expected
959 \code{\meta{cs}\margm{arg}} format and unexpected results will occur.
960
961 \section{Blockers}
962 \label{sec:blockers}
963
964 A \idx{blocker} is a command that prevents any case-change if it occurs at
965 the start of \gls{makefirstuc} or after the argument of an
966 \idx{exclusion}. Blockers are not supported by
967 \gls{MFUsentencecase} but are instead treated as exclusions.
968
969 \cmddef{MFUblocker}
970 Identifies \meta{cs} as a \idx{blocker}. Since \idxpl{blocker}
971 aren't supported by \gls{MFUsentencecase}, this automatically
972 implements \code{\gls{MFUexcl}\margm{cs}} to protect its argument
973 from \gls{MFUsentencecase}, but it won't prevent subsequent content
974 from being changed.
975
976 For example:
977 \begin{codebox}
978 \gls{MFUblocker}\marg{\gls+{nameref}}
979 \gls{makefirstuc}\marg{\gls{nameref}\marg{sec:sentencecase} section}
980 \end{codebox}
981 \begin{resultbox}
982 \MFUblocker{\nameref}
983 \makefirstuc{\nameref{sec:sentencecase} section}
984 \end{resultbox}
985
986 In the following, the \idx{blocker} isn't detected by
987 \gls{makefirstuc} because the content doesn't start with
988 \code{\meta{cs}\margm{arg}} or
989 \code{\cmd{protect}\meta{cs}\margm{arg}}. This means that the entire
990 content is passed to \gls{MFUsentencecase} which treats
991 \gls{nameref} as an \idx{exclusion}:
992 \begin{codebox}
993 \gls{MFUblocker}\marg{\gls{nameref}}
994 \gls{makefirstuc}\marg{\cmd{relax}\gls{nameref}\marg{sec:sentencecase} section}
995 \end{codebox}
996 \begin{resultbox}
997 \MFUblocker{\nameref}
998 \makefirstuc{\relax\nameref{sec:sentencecase} section}
999 \end{resultbox}
1000
1001 \begin{important}
1002 If a \idxc{blocker}{blocking command} is inside the definition of
1003 another command, it won't be visible to \gls{makefirstuc} unless
1004 the other command is expanded before applying \gls{makefirstuc}.
1005 For example, by using \gls{xmakefirstuc} or \gls{emakefirstuc}.
1006 If it doesn't get expanded until after it has been passed to
1007 \gls{MFUsentencecase}, then it will be treated as an \idx{exclusion}
1008 instead.
1009 \end{important}
1010
1011 Recent \LaTeX\ kernels provide \gls{NoCaseChange} and automatically
1012 add it as an \idx{exclusion}. You may want to add it as a
1013 \idx{blocker} for \gls{makefirstuc}. For example:
1014 \begin{codebox}
1015 \gls{makefirstuc}\marg{\gls{ensuremath}\marg{\cmd{alpha}}-particle} /
1016 \gls{makefirstuc}\marg{\idx{dollar}\cmd{alpha}\idx{dollar}-particle} /
1017 \gls{MFUsentencecase}\marg{\gls{ensuremath}\marg{\cmd{alpha}}-particle} /
1018 \gls{MFUsentencecase}\marg{\idx{dollar}\cmd{alpha}\idx{dollar}-particle}
1019 \codepar
1020 \gls{MFUblocker}\marg{\gls{NoCaseChange}}\comment{}
1021 \gls{makefirstuc}\marg{\gls{ensuremath}\marg{\cmd{alpha}}-particle} /
1022 \gls{makefirstuc}\marg{\gls{NoCaseChange}\marg{\idx{dollar}\cmd{alpha}\idx{dollar}}-particle} /
1023 \gls{MFUsentencecase}\marg{\gls{ensuremath}\marg{\cmd{alpha}}-particle} /
1024 \gls{MFUsentencecase}\marg{\gls{NoCaseChange}\marg{\idx{dollar}\cmd{alpha}\idx{dollar}}-particle}
1025 \end{codebox}
1026 Note that \sty{mfirstuc} adds \gls{ensuremath} as an exclusion so
1027 \gls{makefirstuc} will skip it. Whereas the example above that
1028 starts with \idx{dollar} will have the entire argument passed to
1029 \gls{MFUsentencecase}, which skips the maths content.
1030 In the first paragraph, \gls{NoCaseChange} is only an
1031 \idx{exclusion}, but in the second paragraph it's also a
1032 \idx{blocker}.
1033 \begin{resultbox}
1034 Exclusion:
1035 \makefirstuc{\ensuremath{\alpha}-particle} /
1036 \makefirstuc{$\alpha$-particle} /
1037 \MFUsentencecase{\ensuremath{\alpha}-particle} /
1038 \MFUsentencecase{$\alpha$-particle}
1039
1040 Blocker:
1041 \MFUblocker{\NoCaseChange}%
1042 \makefirstuc{\ensuremath{\alpha}-particle} /
1043 \makefirstuc{\NoCaseChange{$\alpha$}-particle} /
1044 \MFUsentencecase{\ensuremath{\alpha}-particle} /
1045 \MFUsentencecase{\NoCaseChange{$\alpha$}-particle}
1046 \end{resultbox}
1047
1048 \section{Mappings}
1049 \label{sec:mappings}
1050
1051 A \idx{mapping} indicates that one command should be substituted for
1052 another, instead of applying a case-change. The assumption is that
1053 the substituted command should perform the case-change instead.
1054 \Idxpl{mapping} are not supported by \gls{MFUsentencecase}
1055 but are instead treated as exclusions.
1056
1057 \cmddef{MFUaddmap}
1058 Identifies a mapping which indicates that \gls{makefirstuc} should
1059 replace \meta{cs1} with \meta{cs2} and not apply a case-change.
1060 This automatically implements:
1061 \begin{compactcodebox}
1062 \gls{MFUexcl}\margm{cs1}\gls{MFUblocker}\margm{cs2}
1063 \end{compactcodebox}
1064 This means that \meta{cs2} is identified as a \idx{blocker} (since
1065 it's assumed to already be a \idx{sentence-case} command) and
1066 \meta{cs1} is identified as an \idx{exclusion} to protect its
1067 argument from \gls{MFUsentencecase}, which doesn't support
1068 \idxpl{mapping}.
1069
1070 \begin{information}
1071 If either \meta{cs1} or \meta{cs2} is empty, no mapping is established, but an
1072 \idx{exclusion} or \idx{blocker} will be set for the non-empty argument.
1073 \end{information}
1074
1075 For example (with \sty{glossaries}):
1076 \begin{codebox}
1077 \gls{MFUaddmap}\marg{\gls+{gls}}\marg{\gls+{Gls}}
1078 \gls{makefirstuc}\marg{\gls{gls}\marg{ex} some text}
1079 \end{codebox}
1080 This will be converted to:
1081 \begin{compactcodebox}
1082 \gls{Gls}\marg{ex} some text
1083 \end{compactcodebox}
1084 Note that this and similar \idxpl{mapping} are automatically added
1085 in \sty{glossaries} v4.50+ and \sty{glossaries-extra} v1.49+.
1086
1087 \begin{important}
1088 If a \idxc{mapping}{mapped command} is inside the definition of
1089 another command, it won't be visible to \gls{makefirstuc} unless
1090 the other command is expanded before applying \gls{makefirstuc}.
1091 For example, by using \gls{xmakefirstuc} or \gls{emakefirstuc}.
1092 If it doesn't get expanded until after it has been passed to
1093 \gls{MFUsentencecase}, then it will be treated as an \idx{exclusion}
1094 instead.
1095 \end{important}
1096
1097 \section{Package Options}
1098 \label{sec:pkgoptions}
1099
1100 \optiondef{expanded}
1101 Redefines \gls{glsmakefirstuc} to simply use \gls{MFUsentencecase}.
1102
1103 \optiondef{unexpanded}
1104 Redefines \gls{glsmakefirstuc} to use \gls{MFUsentencecase}
1105 without expanding its argument.
1106
1107 \optiondef{grabfirst}
1108 Redefines \gls{glsmakefirstuc} to use \gls{mfugrabfirstuc} and also
1109 redefines \gls{mfirstucMakeUppercase} to use \gls{MakeUppercase}.
1110
1111 This option is best avoided and is only provided to emulate the v2.07
1112 behaviour of \gls{glsmakefirstuc}. However, you may still have
1113 different results compared to v2.07, so you may need to use rollback
1114 instead.
1115
1116 \chapter{Title-Case}
1117 \label{sec:capitalisewords}
1118
1119 The \idx{title-case} commands are designed to convert the first letter of each
1120 word in a phrase to uppercase. These commands are robust.
1121 \cmddef{capitalisewords}
1122 This command applies a \idx{sentence-case} command to each word in \meta{text}
1123 where the space character is used as the word separator. Note that
1124 it has to be an ordinary space character, not another form of space,
1125 such as \idx{nbsp} or \gls{space}. Note that no expansion is performed
1126 on \meta{text}.
1127 For example:
1128 \begin{coderesult}
1129 \gls{capitalisewords}\marg{a sample phrase}
1130 \tcblower
1131 \capitalisewords{a sample phrase}
1132 \end{coderesult}
1133 See \sectionref{sec:nocap} for excluding words (such as \qt{of})
1134 from the case-changing.
1135
1136 \begin{information}
1137 This isn't the same as the \LaTeX3 command \gls{texttitlecase:n},
1138 which converts the first letter to \idx{uppercase} and all other
1139 letters to \idx{lowercase}.
1140 \end{information}
1141
1142 For convenience, there are shortcut commands if expansion is
1143 required before parsing the argument:
1144 \cmddef{xcapitalisewords}
1145 This is a shortcut for:
1146 \begin{compactcodebox}
1147 \cmd{expandafter}\gls{capitalisewords}\cmd{expandafter}\margm{text}
1148 \end{compactcodebox}
1149 \cmddef{ecapitalisewords}
1150 This fully expands \meta{text} before passing it to
1151 \gls{capitalisewords}.
1152
1153 The parser used by \gls{capitalisewords} first splits up the text on
1154 each space character. Each of these space-separated words may
1155 actually be a compound, so further parsing is performed on each
1156 \qt{word}. The divisions within the compound word should be marked
1157 up with:
1158 \cmddef{MFUwordbreak}
1159 For example:
1160 \begin{coderesult}
1161 \gls{capitalisewords}\marg{a
1162 big\gls{MFUwordbreak}\marg{/}small idea}
1163 \tcblower
1164 \capitalisewords{a big\MFUwordbreak{/}small idea}
1165 \end{coderesult}
1166 Each sub-word within the compound word is encapsulated with:
1167 \cmddef{MFUcapword}
1168 Since it's inconvenient to have to markup every hyphen,
1169 \gls{MFUcapword} can be enabled to check for hyphens.
1170
1171 \cmddef{ifMFUhyphen}
1172 This conditional determines whether or not \gls{MFUcapword} should
1173 consider a hyphen a word break. If this conditional is true, then
1174 \gls{MFUcapword} will encapsulate its argument with:
1175 \cmddef{MFUhyphencapword}
1176 This will parse \meta{text} for hyphen characters and apply the case
1177 change to each hyphen-separated word. Otherwise \gls{MFUcapword}
1178 will treat its argument as a single word.
1179
1180 The conditional can be set to true with:
1181 \cmddef{MFUhyphentrue}
1182 and switched back off with:
1183 \cmddef{MFUhyphenfalse}
1184
1185 For example:
1186 \begin{codebox}
1187 \gls{capitalisewords}\marg{server-side includes} /
1188 \gls{MFUhyphentrue}
1189 \gls{capitalisewords}\marg{server-side includes}
1190 \end{codebox}
1191 \begin{resultbox}
1192 \capitalisewords{server-side includes} /
1193 \MFUhyphentrue
1194 \capitalisewords{server-side includes}
1195 \end{resultbox}
1196
1197 The actual case-change of each word is performed with:
1198 \cmddef{MFUcapwordfirstuc}
1199 This defaults to \code{\gls{makefirstuc}\margm{word}} but may be
1200 redefined to use \gls{MFUsentencecase}, if preferred.
1201
1202 \begin{important}
1203 Hyphens and \gls{MFUwordbreak} must be visible to the parser that
1204 searches for word breaks. This means they won't be detected if they
1205 are within a group or in the definition of a command.
1206 \end{important}
1207
1208 Formatting for the entire phrase must go outside
1209 \gls{capitalisewords} (unlike \gls{makefirstuc}).
1210 For example:
1211 \begin{codebox}
1212 \gls{capitalisewords}\marg{\cmd{emph}\marg{a sample phrase}} /
1213 \cmd{emph}\marg{\gls{capitalisewords}\marg{a sample phrase}}
1214 \end{codebox}
1215 \begin{resultbox}
1216 \capitalisewords{\emph{a sample phrase}} /
1217 \emph{\capitalisewords{a sample phrase}}
1218 \end{resultbox}
1219
1220 If your phrase is likely to contain formatting commands, you can instead use:
1221 \cmddef{capitalisefmtwords}
1222 where \meta{text} may be just words (as with \gls{capitalisewords}):
1223 \begin{compactcodebox}
1224 \gls{capitalisefmtwords}\margm{words}
1225 \end{compactcodebox}
1226 or may be entirely enclosed in a formatting command in the form:
1227 \begin{compactcodebox}
1228 \gls{capitalisefmtwords}\marg{\meta{cs}\margm{words}}
1229 \end{compactcodebox}
1230 or contain formatted sub-phrases:
1231 \begin{compactcodebox}
1232 \gls{capitalisefmtwords}\marg{\meta{words} \meta{cs}\margm{sub-phrase} \meta{words}}
1233 \end{compactcodebox}
1234 The starred form only permits a text-block command at the
1235 start of the phrase. See \sectionref{sec:titlecaseexamples} for
1236 examples.
1237
1238 \begin{warning}
1239 Avoid declarations, such as \cmd{bfseries} or \cmd{em}.
1240 \end{warning}
1241
1242 If expansion is required, you can use:
1243 \cmddef{xcapitalisefmtwords}
1244 which is a shortcut for:
1245 \begin{compactcodebox}
1246 \cmd{expandafter}\gls{capitalisefmtwords}\cmd{expandafter}\margm{text}
1247 \end{compactcodebox}
1248 (The star modifier will be applied with
1249 \code{\gls{xcapitalisefmtwords}*} in an appropriate manner.)
1250
1251 \cmddef{ecapitalisefmtwords}
1252 This will fully expand its argument before passing it to
1253 \gls{capitalisefmtwords}. Again, the star modifier may be used.
1254
1255 \begin{important}
1256 The unstarred \gls{capitalisefmtwords} is only designed for phrases that contain
1257 text-block commands with a single
1258 argument, which should be a word or sub-phrase. Anything
1259 more complicated is likely to break. Instead, use the
1260 starred form or \gls{capitalisewords}.
1261 \end{important}
1262
1263 \section{Excluding Words From Case-Changing}
1264 \label{sec:nocap}
1265
1266 \glsadd{exclusion-word}Some words typically shouldn't have their case changed unless they
1267 occur at the start. These words can be identified with:
1268 \cmddef{MFUnocap}
1269 This only has a local effect. The global version is:
1270 \cmddef{gMFUnocap}
1271 The list of words that shouldn't be capitalised can be cleared
1272 using:
1273 \cmddef{MFUclear}
1274
1275
1276 For example:
1277 \begin{codebox}
1278 \gls{capitalisewords}\marg{the wind in the willows}
1279 \codepar
1280 \gls{MFUnocap}\marg{in}\comment{}
1281 \gls{MFUnocap}\marg{the}\comment{}
1282 \codepar
1283 \gls{capitalisewords}\marg{the wind in the willows}
1284 \end{codebox}
1285 \begin{resultbox}
1286 \capitalisewords{the wind in the willows}
1287
1288 \MFUnocap{in}%
1289 \MFUnocap{the}%
1290
1291 \capitalisewords{the wind in the willows}
1292 \end{resultbox}
1293
1294 Since the case-change is ultimately performed by \gls{makefirstuc},
1295 you can also use an \idx{exclusion} to prevent an individual word
1296 from being changed. For example:
1297 \begin{codebox}
1298 \cmd{newcommand}\marg{\cmd{NoChange}}[1]\marg{\#1}
1299 \gls{MFUexcl}\marg{\cmd{NoChange}}
1300 \gls{MFUclear}
1301 \gls{capitalisewords}\marg{the \cmd{NoChange}\marg{wind} in the willows}
1302 \end{codebox}
1303 \begin{resultbox}
1304 \providecommand{\NoChange}[1]{#1}
1305 \MFUexcl{\NoChange}
1306 \MFUclear
1307 \capitalisewords{the \NoChange{wind} in the willows}
1308 \end{resultbox}
1309 This can also work if you redefine \gls{MFUcapwordfirstuc} to use
1310 \gls{MFUsentencecase} provided the exclusion command doesn't expand
1311 (so \cmd{NoChange} would need to be protected or made robust in the above
1312 example).
1313
1314 \begin{important}
1315 Exceptions only apply to (non-leading) whole words or words separated with
1316 \gls{MFUwordbreak} but not to parts of a hyphenated
1317 word that are split by \gls{MFUhyphencapword}.
1318 \end{important}
1319
1320 Examples:
1321 \begin{enumerate}
1322 \item
1323 Exceptions aren't applied if \gls{MFUwordbreak} occurs before the
1324 first space.
1325 \begin{codebox}
1326 \gls{MFUnocap}\marg{a}\gls{MFUnocap}\marg{the}\comment{}
1327 \gls{capitalisewords}\marg{a\gls{MFUwordbreak}\marg{/}the something}
1328 \end{codebox}
1329 \begin{resultbox}
1330 \MFUnocap{a}\MFUnocap{the}%
1331 \capitalisewords{a\MFUwordbreak{/}the something}
1332 \end{resultbox}
1333
1334 \item
1335 Exceptions are applied for non-leading words:
1336 \begin{codebox}
1337 \gls{MFUnocap}\marg{and}\gls{MFUnocap}\marg{or}\comment{}
1338 \gls{capitalisewords}\marg{one and\gls{MFUwordbreak}\marg{/}or another}
1339 \end{codebox}
1340 \begin{resultbox}
1341 \MFUnocap{and}\MFUnocap{or}%
1342 \capitalisewords{one and\MFUwordbreak{/}or another}
1343 \end{resultbox}
1344
1345 \item
1346 Exceptions aren't applied for hyphenated parts:
1347 \begin{codebox}
1348 \gls{MFUhyphentrue}
1349 \gls{MFUnocap}\marg{and}\gls{MFUnocap}\marg{or}\comment{}
1350 \gls{capitalisewords}\marg{one and-or another}
1351 \end{codebox}
1352 \begin{resultbox}
1353 \MFUhyphentrue
1354 \MFUnocap{and}\MFUnocap{or}%
1355 \capitalisewords{one and-or another}
1356 \end{resultbox}
1357 \end{enumerate}
1358
1359 \pkgdef{mfirstuc-english}
1360 The supplementary package \sty{mfirstuc-english} loads \sty{mfirstuc} and uses
1361 \gls{MFUnocap} to add common English articles and conjunctions, such
1362 as \qt{a}, \qt{an}, \qt{and}, \qt{but}. You may want to add other
1363 words to this list, such as prepositions but, as there's some
1364 dispute over whether prepositions should be capitalised, I~don't
1365 intend to add them to this package. Note that you need to explicitly
1366 load \sty{mfirstuc-english} if you require it. There's no automatic
1367 language detection performed by \sty{mfirstuc}.
1368
1369 If you want to write a similar package for another language, all you
1370 need to do is create a file with the extension \filefmt{.sty}
1371 that starts with:
1372 \begin{compactcodebox}
1373 \cmd{NeedsTeXFormat}\marg{LaTeX2e}
1374 \end{compactcodebox}
1375 The next line should identify the package. For example, if you have
1376 called the file \filefmt{mfirstuc-french.sty} then you need:
1377 \begin{compactcodebox}
1378 \cmd{ProvidesPackage}\marg{mfirstuc-french}
1379 \end{compactcodebox}
1380 It's a good idea to also add a version in the final optional
1381 argument, for example:
1382 \begin{compactcodebox}
1383 \cmd{ProvidesPackage}\marg{mfirstuc-french}[2014/07/30 v1.0]
1384 \end{compactcodebox}
1385 Next load \sty{mfirstuc}:
1386 \begin{compactcodebox}
1387 \cmd{RequirePackage}\marg{mfirstuc}
1388 \end{compactcodebox}
1389 Now add all your \gls{MFUnocap} commands. For example:
1390 \begin{compactcodebox}
1391 \gls{MFUnocap}\marg{de}
1392 \end{compactcodebox}
1393 At the end of the file add:
1394 \begin{compactcodebox}
1395 \cmd{endinput}
1396 \end{compactcodebox}
1397
1398 Put the file somewhere on \TeX's path, and now you can use this
1399 package in your document. You might also consider
1400 \href{http://ctan.org/upload}{uploading it to CTAN} in case
1401 other users find it useful.
1402
1403
1404 \section{PDF Bookmarks}
1405 \label{sec:pdfbookmarks}
1406
1407 If you are using \sty{hyperref} and want to use
1408 \gls{capitalisewords} or \gls{capitalisefmtwords} (or the expanded
1409 variants) in a section heading, the PDF bookmarks won't be able to
1410 use the command as it's not expandable, so you will get a warning
1411 that looks like:
1412 \begin{transcript}
1413 Package hyperref Warning: Token not allowed in a PDF string
1414 (PDFDocEncoding):
1415 (hyperref) removing `\gls{capitalisewords}'
1416 \end{transcript}
1417
1418 If you want to provide an alternative for the PDF bookmark, you can
1419 use \sty{hyperref}'s \gls{texorpdfstring} command. For example:
1420 \begin{codebox}
1421 \cmd{chapter}\marg{\gls{texorpdfstring}
1422 \marg{\gls{capitalisewords}\marg{a book of rhyme}}\comment{ TeX}
1423 \marg{A Book of Rhyme}\comment{ PDF}
1424 }
1425 \end{codebox}
1426 Alternatively, you can use \sty{hyperref}'s mechanism for
1427 disabling commands within the bookmarks. For example:
1428 \begin{codebox*}
1429 \gls{pdfstringdefDisableCommands}\marg{\comment{}
1430 \cmd{let}\gls{capitalisewords}\cmd{@firstofone}
1431 }
1432 \end{codebox*}
1433 The same applies to \gls{makefirstuc}. You can, however, use
1434 the expandable \gls{MFUsentencecase}. So you may prefer:
1435 \begin{codebox*}
1436 \gls{pdfstringdefDisableCommands}\marg{\comment{}
1437 \cmd{let}\gls{capitalisewords}\cmd{MFUsentencecase}
1438 \cmd{let}\gls{makefirstuc}\cmd{MFUsentencecase}
1439 }
1440 \end{codebox*}
1441
1442 See the \sty{hyperref} manual for further details.
1443
1444 \section{Examples}
1445 \label{sec:titlecaseexamples}
1446
1447 \begin{enumerate}
1448 \item Text only:
1449 \begin{coderesult}
1450 \gls{capitalisewords}\marg{a little book of rhyme}
1451 \tcblower
1452 \capitalisewords{a little book of rhyme}
1453 \end{coderesult}
1454
1455 \item Excluding words (see \sectionref{sec:nocap}):
1456 \begin{coderesult}
1457 \gls{MFUnocap}\marg{of}
1458 \gls{capitalisewords}\marg{a little book of rhyme}
1459 \tcblower
1460 \MFUnocap{of}
1461 \capitalisewords{a little book of rhyme}
1462 \end{coderesult}
1463
1464 \item \gls{space} isn't recognised as a word boundary:
1465 \begin{codebox}
1466 \gls{capitalisewords}\marg{a book of rhyme.}
1467 \codepar
1468 \gls{capitalisewords}\marg{a book\gls{space} of rhyme.}
1469 \end{codebox}
1470 \begin{resultbox}
1471 \capitalisewords{a book of rhyme.}
1472
1473 \capitalisewords{a book\space of rhyme.}
1474 \end{resultbox}
1475
1476 \item Phrase entirely enclosed in a formatting command:
1477 \begin{codebox}
1478 \gls{capitalisefmtwords}\marg{\cmd{emph}\marg{a small book of rhyme}}
1479 \end{codebox}
1480 \begin{resultbox}
1481 \capitalisefmtwords{\emph{a small book of rhyme}}
1482 \end{resultbox}
1483
1484 \item Sub-phrase enclosed in a formatting command:
1485 \begin{codebox}
1486 \gls{capitalisefmtwords}\marg{a \cmd{emph}\marg{small book} of rhyme}
1487 \end{codebox}
1488 \begin{resultbox}
1489 \capitalisefmtwords{a \emph{small book} of rhyme}
1490 \end{resultbox}
1491
1492 \item Nested text-block commands:
1493 \begin{codebox}
1494 \gls{capitalisefmtwords}\marg{\cmd{textbf}\marg{a \cmd{emph}\marg{small book}} of rhyme}
1495 \end{codebox}
1496 \begin{resultbox}
1497 \capitalisefmtwords{\textbf{a \emph{small book}} of rhyme}
1498 \end{resultbox}
1499
1500 \item Formatting and case-change exception (see \sectionref{sec:nocap}):
1501 \begin{codebox}
1502 \gls{MFUnocap}\marg{of}
1503 \gls{capitalisefmtwords}\marg{\cmd{textbf}\marg{a \cmd{emph}\marg{small book}} of rhyme}
1504 \end{codebox}
1505 \begin{resultbox}
1506 \MFUnocap{of}
1507 \capitalisefmtwords{\textbf{a \emph{small book}} of rhyme}
1508 \end{resultbox}
1509
1510 \item Starred form:
1511 \begin{codebox}
1512 \gls{MFUnocap}\marg{of}
1513 \gls{capitalisefmtwords}*\marg{\cmd{emph}\marg{a small book of rhyme}}
1514 \end{codebox}
1515 \begin{resultbox}
1516 \MFUnocap{of}
1517 \capitalisefmtwords*{\emph{a small book of rhyme}}
1518 \end{resultbox}
1519
1520 \item The starred form also works with just text (no text-block
1521 command):
1522 \begin{codebox}
1523 \gls{MFUnocap}\marg{of}
1524 \gls{capitalisefmtwords}*\marg{a small book of rhyme}
1525 \end{codebox}
1526 \begin{resultbox}
1527 \MFUnocap{of}
1528 \capitalisefmtwords*{a small book of rhyme}
1529 \end{resultbox}
1530
1531 \item Expansion:
1532 \begin{codebox}
1533 \cmd{newcommand}\marg{\cmd{abc}}\marg{\cmd{xyz}\gls+{space} four five}
1534 \cmd{newcommand}\marg{\cmd{xyz}}\marg{one two three}
1535 No expansion: \gls{capitalisewords}\marg{\cmd{abc}}.
1536 \codepar
1537 First object one-level expansion: \gls{xcapitalisewords}\marg{\cmd{abc}}.
1538 \codepar
1539 Fully expanded: \gls{ecapitalisewords}\marg{\cmd{abc}}.
1540 \end{codebox}
1541 \begin{resultbox}
1542 \newcommand{\abc}{\xyz\space four five}
1543 \newcommand{\xyz}{one two three}
1544 No expansion: \capitalisewords{\abc}.
1545
1546 First object one-level expansion: \xcapitalisewords{\abc}.
1547
1548 Fully expanded: \ecapitalisewords{\abc}.
1549 \end{resultbox}
1550
1551 Remember that the spaces need to be explicit. In the second case
1552 above, using \gls{xcapitalisewords}, the space before \qt{four} has
1553 been hidden within \gls{space} so it's not recognised as a word
1554 boundary, but in the third case, \gls{space} has been expanded to an
1555 actual space character.
1556
1557
1558 \end{enumerate}
1559
1560 If there is a text-block command within the argument of the
1561 starred form, it's assumed to be at the start of the argument.
1562 Unexpected results can occur if there are other commands.
1563 For example:
1564 \begin{badcodebox}
1565 \gls{MFUnocap}\marg{of}
1566 \gls{capitalisefmtwords}*\marg{\cmd{emph}\marg{a small} book \cmd{textbf}\marg{of rhyme}}
1567 \end{badcodebox}
1568 \begin{resultbox}
1569 \MFUnocap{of}
1570 \capitalisefmtwords*{\emph{a small} book \textbf{of rhyme}}
1571 \end{resultbox}
1572 In this case \code{\cmd{textbf}\marg{of rhyme}} is considered a
1573 single word. Similarly if the text-block command occurs
1574 in the middle of the argument:
1575 \begin{badcodebox}
1576 \gls{MFUnocap}\marg{of}
1577 \gls{capitalisefmtwords}*\marg{a \cmd{emph}\marg{very small} book of rhyme}
1578 \end{badcodebox}
1579 \begin{resultbox}
1580 \MFUnocap{of}
1581 \capitalisefmtwords*{a \emph{very small} book of rhyme}
1582 \end{resultbox}
1583 In this case \code{\cmd{emph}\marg{very small}} is considered a
1584 single word.
1585
1586 Grouping causes interference.
1587 As with all the commands described here, avoid declarations.
1588 \begin{badcodebox}
1589 \gls{capitalisefmtwords}\marg{\marg{\cmd{bfseries} a \cmd{emph}\marg{small book}} of rhyme}
1590 \end{badcodebox}
1591
1592 \begin{information}
1593 As a general rule, it's better to define \idxpl{semanticcommand} rather
1594 than directly using font commands and declarations within the
1595 document.
1596 \end{information}
1597
1598 Avoid complicated commands in the unstarred version. For example,
1599 the following breaks:
1600 \begin{badcodebox}
1601 \cmd{newcommand}*\marg{\cmd{swap}}[2]\marg{\marg{\#2}\marg{\#1}}
1602 \gls{capitalisefmtwords}\marg{a \cmd{swap}\marg{bo}\marg{ok} of rhyme}
1603 \end{badcodebox}
1604 However it can work with the starred form and the simpler
1605 \gls{capitalisewords}:
1606 \begin{codebox}
1607 \cmd{newcommand}*\marg{\cmd{swap}}[2]\marg{\marg{\#2}\marg{\#1}}
1608 \gls{capitalisefmtwords}*\marg{a \cmd{swap}\marg{bo}\marg{ok} of rhyme}
1609 \codepar
1610 \gls{capitalisewords}\marg{a \cmd{swap}\marg{bo}\marg{ok} of rhyme}
1611 \end{codebox}
1612 \begin{resultbox}
1613 \newcommand*{\swap}[2]{{#2}{#1}}
1614 \capitalisefmtwords*{a \swap{bo}{ok} of rhyme}
1615
1616 \capitalisewords{a \swap{bo}{ok} of rhyme}
1617 \end{resultbox}
1618 Note that the case change is applied to the first argument.
1619
1620 \chapter{Miscellaneous}
1621 \label{sec:misc}
1622
1623 \section{Saving \Glsfmtplural{exclusion}, \Glsfmtplural{blocker} and
1624 \Glsfmtplural{mapping} in the \exttext{aux} File}
1625 \label{sec:savetoaux}
1626
1627 If the \idxpl{exclusion}, \idxpl{mapping} and \idxpl{blocker} are
1628 required by some external tool, the information can be saved in the
1629 \ext+{aux} file.
1630
1631 \cmddef{MFUsaveatend}
1632 This saves the information at the end of the document using a delayed
1633 write. This means that it can register all information identified
1634 throughout the document, but there's a chance the document may end
1635 before the write takes place (for example, if the last page only
1636 contains floats). This command may be counteracted by:
1637 \cmddef{MFUsave}
1638 This saves the information using a protected write at the point
1639 where this command occurs, which may be too soon if additional
1640 \idxpl{exclusion}, \idxpl{mapping} or \idxpl{blocker} are identified
1641 later. This command will counteract any instance of
1642 \gls{MFUsaveatend}, regardless of whether or not \gls{MFUsaveatend}
1643 comes before or after \gls{MFUsave}.
1644
1645 The associated \ext{aux} commands are listed below. In each case, a
1646 definition is provided in the \ext{aux} file that does nothing.
1647 \cmddef{@mfu@excls}
1648 Lists all \idxpl{exclusion}.
1649 For example:
1650 \begin{compactcodebox*}
1651 \gls{@mfu@excls}\marg{\gls{begin} \gls{cite} \gls{end} \gls{label}
1652 \gls{ref} \gls{cite} \gls{NoCaseChange} \gls{ensuremath}
1653 \gls{MFUskippunc} \gls{gls} \gls{glspl}}
1654 \end{compactcodebox*}
1655
1656 \cmddef{@mfu@blockers}
1657 Lists all \idxpl{blocker}.
1658 For example:
1659 \begin{compactcodebox*}
1660 \gls{@mfu@blockers}\marg{\gls{Gls} \gls{Glspl} }
1661 \end{compactcodebox*}
1662
1663 \cmddef{@mfu@mappings}
1664 Lists all \idxpl{mapping} as a \keyval\ list.
1665 For example:
1666 \begin{compactcodebox*}
1667 \gls{@mfu@mappings}\marg{ \marg{\gls{gls} }= \marg{\gls{Gls} }, \marg{\gls{glspl} }= \marg{\gls{Glspl} }}
1668 \end{compactcodebox*}
1669
1670 \section{All-Caps}
1671 \label{sec:allcaps}
1672
1673 \cmddef{mfirstucMakeUppercase}
1674 This command was originally used to perform the actual conversion to
1675 \idx+{uppercase} and was defined to use command \gls{MakeUppercase}.
1676 The \sty{glossaries} package (before v4.50) formerly loaded the
1677 \sty{textcase} package and redefined \gls{mfirstucMakeUppercase} to
1678 use \gls{MakeTextUppercase}, which was better than
1679 \gls{MakeUppercase}.
1680
1681 The \sty{textcase} package has been deprecated as from 2022 and
1682 it now simply sets \gls{MakeTextUppercase} to \gls{MakeUppercase}
1683 because the new kernel now defines \gls{MakeUppercase} to use the
1684 newer \LaTeX3 command \gls{textuppercase:n}. Although that command
1685 is expandable, \gls{MakeUppercase} is robust.
1686
1687 As from v2.08, \sty{mfirstuc} now defines \gls{mfirstucMakeUppercase}
1688 so that it uses \gls{texttitlecasefirst:n} directly, rather than
1689 indirectly through \gls{MakeUppercase}, which means that it's now
1690 expandable. However, \gls{mfirstucMakeUppercase} is no longer used
1691 by \sty{mfirstuc} except in \gls{mfugrabfirstuc}, which is provided
1692 to emulate v2.07. Note that the \opt{grabfirst} option will also
1693 redefine \gls{mfirstucMakeUppercase} to use \gls{MakeUppercase}.
1694
1695 \section{UTF-8}
1696 \label{sec:utf8}
1697
1698 \begin{information}
1699 See \blog{binary-files-text-files-and-file-encodings/}{Binary
1700 Files, Text Files and File Encodings} if you are confused about how
1701 file encodings, such as \gls{utf8}, relate to text files.
1702 \end{information}
1703
1704 This section only applies to rollback or the use of \gls{mfugrabfirstuc}
1705 (implemented via the \opt{grabfirst} option).
1706
1707 Prior to version 2.08, the case-change applied by the
1708 \gls{glsmakefirstuc} command worked by utilizing the fact that, in
1709 most cases, \TeX\ doesn't require a regular argument to be enclosed
1710 in braces if it only consists of a single token. (This is why you
1711 can do, say, \code{\cmd{frac}12} instead of
1712 \code{\cmd{frac}\marg{1}\marg{2}} or \code{x\char`\^2}
1713 instead of \code{x\char`\^\marg{2}}, although this
1714 practice is discouraged by some.)
1715
1716 A~simplistic version of the original \gls{glsmakefirstuc} command is:
1717 \begin{codebox}
1718 \cmd{newcommand}*\marg{\cmd{FirstUC}}[1]\marg{\gls{MakeUppercase} \#1}
1719 \end{codebox}
1720 Here
1721 \begin{codebox}
1722 \cmd{FirstUC}\marg{abc}
1723 \end{codebox}
1724 is equivalent to
1725 \begin{codebox}
1726 \gls{MakeUppercase} abc
1727 \end{codebox}
1728 and since \gls{MakeUppercase} requires an argument, it grabs the
1729 first token (the character \qt{a} in this case) and uses that as the
1730 argument so that the result is \qt{Abc}. This behaviour can be
1731 achieved with \gls{mfugrabfirstuc}.
1732
1733 Unfortunately, this will fail if the content starts with a \gls{utf8}
1734 character and you are using \pdfLaTeX, where each octet of the
1735 \gls{utf8} character is a separate token. This isn't a problem
1736 with \XeLaTeX\ and \LuaLaTeX\ which both treat the entire multibyte
1737 character as a single token.
1738
1739 \LaTeX3 now provides \gls{texttitlecasefirst:n}
1740 to convert the first character to uppercase, so now the
1741 case-change can be applied with:
1742 \begin{codebox}
1743 \cmd{ExplSyntaxOn}
1744 \gls{texttitlecasefirst:n}\marg{élite}
1745 \cmd{ExplSyntaxOff}
1746 \end{codebox}
1747 This is exactly what \gls{MFUsentencecase} does without the need to
1748 switch on \LaTeX3 syntax. The difference with the default definition
1749 of \gls{glsmakefirstuc} is that it prevents its argument from being
1750 expanded.
1751
1752 \backmatter
1753 \printterms
1754 \printsummary
1755 \printuserguideindex
1756
1757 \end{document}