\Gls
, which need to have the first letter converted to uppercase (sentence-case), but as the commands provided by mfirstuc may be used without glossaries, the two were split into separately maintained packages in 2015 (mfirstuc v2.0 and glossaries v4.18).
Version 2.08 has reimplemented \makefirstuc
using LaTeX3 commands. If there are any compatibility issues, you can rollback to v2.07:
\usepackage
{mfirstuc}[=2.07]
1. Sentence-Case
There are two sentence-case commands provided: \MFUsentencecase
and \makefirstuc
. A summary of the principle features of the two commands is given in Table 1.1.
Feature | \MFUsentencecase |
\makefirstuc |
---|---|---|
Can expand? | ✔ | ✖ |
Supports exclusions? | ✔ | ✔ |
Supports blockers? | ✖ | ✔ |
Supports mappings? | ✖ | ✔ |
Semantic commands must be robust? | ✔ | ✖ |
1.1. Examples
Text only (leading UTF-8 now supported):
\makefirstuc
{élite} /\MFUsentencecase
{élite}
Leading punctuation is ignored:
\makefirstuc
{`word'} /\MFUsentencecase
{`word'}
However, if the punctuation character is followed by a blocker or mapping command, the punctuation will need to be excluded otherwise the command will be treated as an exclusion. If possible, use semantic markup instead of directly including the punctuation.
Fragile commands need to be protected with \MFUsentencecase
:
\newcommand
{\alert
}[1]{\textcolor
{red}{\textbf
{#1}}}\makefirstuc
{\alert
{élite}} /\MFUsentencecase
{\protect
\alert
{élite}}
Exclusions are supported by both \makefirstuc
and \MFUsentencecase
:
\MFUexcl
{\index
}\makefirstuc
{\index
{word}example} /\MFUsentencecase
{\index
{word}example}
Blockers are only supported by \makefirstuc
. They are treated as exclusions with \MFUsentencecase
, which produces a different result:
\MFUblocker
{\nameref
}\makefirstuc
{\nameref
{sec:sentencecase} section} /\MFUsentencecase
{\nameref
{sec:sentencecase} section}
Mappings are only supported by \makefirstuc
. They are treated as exclusions with \MFUsentencecase
, which produces a different result:
\newrobustcmd
{\secref
}[1]{section~\ref
{#1}}\newrobustcmd
{\Secref
}[1]{Section~\ref
{#1}}\MFUaddmap
{\secref
}{\Secref
}\makefirstuc
{\secref
{sec:sentencecase} example} /\MFUsentencecase
{\secref
{sec:sentencecase} example}
Argument expansion: \MFUsentencecase
expands its argument and then skips exclusions whereas \makefirstuc
parses its argument without expansion and then passes the relevant content to \glsmakefirstuc
. Note that different results will occur with the expanded and unexpanded package options. For example:
\usepackage
[expanded]{mfirstuc}\newcommand
{\testa
}{sample}\newcommand
{\testb
}{\testa
\
test}\begin{document}
\makefirstuc
{\testb
} /\xmakefirstuc
{\testb
} /\emakefirstuc
{\testb
} /\MFUsentencecase
{\testb
}\end{document}
This produces:\usepackage
{mfirstuc}[=v2.07]\newcommand
{\testa
}{sample}\newcommand
{\testb
}{\testa
\
test}\begin{document}
\makefirstuc
{\testb
} /\xmakefirstuc
{\testb
} /\emakefirstuc
{\testb
}\end{document}
Argument expansion with mappings (and the default unexpanded option):
\newrobustcmd
{\secref
}[1]{section~\ref
{#1}}\newrobustcmd
{\Secref
}[1]{Section~\ref
{#1}}\MFUaddmap
{\secref
}{\Secref
}\newcommand
{\testa
}{\secref
{sec:sentencecase}}\newcommand
{\testb
}{\testa
\
example}\makefirstuc
{\testb
} /\xmakefirstuc
{\testb
} /\emakefirstuc
{\testb
} /\MFUsentencecase
{\testb
}
1.2. Sentence Case Commands
This simply uses
\text_titlecase_first:n
, which is provided by the LaTeX3 kernel. Note that this fully expands the argument. If you use this command, ensure that your semantic commands are robust. For example: \newrobustcmd
{\alert
}[1]{\textcolor
{red}{\textbf
{#1}}}\MFUsentencecase
{\alert
{sample} text}
This is because the expansion that’s performed before the case-change will result in:\newcommand
{\alert
}[1]{\textcolor
{red}{\textbf
{#1}}}\MFUsentencecase
{\alert
{sample} text}
This triggers an error since\textcolor
{Red}{\textbf
{sample}} text
Red
isn’t a recognised colour name.This is the original command provided by mfirstuc, which was written to assist sentence-casing in the glossaries package and had to take markup into account. It parses its argument to try to determine which part needs the case-change. The actual case-change is performed by
\glsmakefirstuc
.
As from v2.08, the definition of \makefirstuc
has been updated to use LaTeX3 code, but the argument is still parsed, which allows for non-robust semantic commands, and now also takes blockers and mappings into account. For example:
\newcommand
{\alert
}[1]{\textcolor
{red}{\textbf
{#1}}}\makefirstuc
{\alert
{sample} text}
The rules used when parsing
are as follows:
\makefirstuc
{ }
- 1.if is empty do nothing;
- 2.if consists of a single item or starts with a group do
;\glsmakefirstuc
{ } - 3.if starts with a command :
- (a)if is
\protect
, skip it and continue to the next step where the command under inspection is now the one that follows\protect
: - (b)if has been identified as a blocker, just do (that is, no case-change is applied);
- (c)if isn’t followed by a group then do
;\glsmakefirstuc
{ } - (d)otherwise assume the format is
(where { } may be empty) and then:
- i.if has been mapped to then do
; { }
- ii.if has been identified as an exclusion, do
; { }\makefirstuc
{ } - iii.otherwise do
. {\makefirstuc
{ }}
- i.if has been mapped to then do
- (a)if is
- 4.otherwise do
.\glsmakefirstuc
{ }
Note that the above algorithm uses recursion. The termination points are: don’t implement a change, replace a command with another command, or apply the case-change via \glsmakefirstuc
.
For convenience, the following commands are also provided:
This is simply a shortcut for:This ensures the first token in is expanded before being passed to\expandafter
\makefirstuc
\expandafter
{ }
\makefirstuc
.This fully expands its argument before passing it to
\makefirstuc
. For example: \newcommand
{\test
}[1]{sample #1}\newcommand
{\tmp
}{\test
{text}}\makefirstuc
{\tmp
} /\xmakefirstuc
{\tmp
} /\emakefirstuc
{\tmp
}
\MFUsentencecase
instead of \emakefirstuc
.
\emakefirstuc
, mappings and blockers will only be detected if they are robust or protected, otherwise they will expand too soon to be detected. This command is used by
\makefirstuc
to perform the case-change. The “gls” prefix is for historical reasons as the original code was part of the glossaries package. With the default unexpanded option, this command is defined as: The use of\MFUsentencecase
{\unexpanded
{ }}
\unexpanded
inhibits the expansion of that would otherwise occur. This allows \makefirstuc
to maintain as much backward-compatibility with version 2.07 as possible. This is particularly important when using the glossaries package with a style that automatically converts the description to sentence-case, as there may well be documents with complex descriptions that contain fragile commands.
The expanded package option will redefine \glsmakefirstuc
to use \MFUsentencecase
without \unexpanded
. The grabfirst package option will redefine \glsmakefirstuc
to use \mfugrabfirstuc
to emulates the behaviour of \glsmakefirstuc
in v2.07 and below without using rollback.
This robust command is provided to emulate v2.07 and its use is discouraged. Note that you may still have different results compared to v2.07, so you may need to use rollback instead. (Note that the grabfirst option additionally redefines
\mfirstucMakeUppercase
to \MakeUppercase
, which you will also need.)
This applies \mfirstucMakeUppercase
to the first token in and leaves the remainder unchanged. This won’t work if starts with a UTF-8 character unless you use XeLaTeX or LuaLaTeX, so avoid using this method where possible. For example:
This is equivalent to:\renewcommand
{\mfirstucMakeUppercase
}[1]{%\MakeUppercase
{#1}% }\mfugrabfirstuc
{sample}
\mfirstucMakeUppercase
{s}ample
Whereas only works with XeLaTeX or LuaLaTeX.\renewcommand
{\mfirstucMakeUppercase
}[1]{%\MakeUppercase
{#1}% }\mfugrabfirstuc
{élite}
\makefirstuc
that tried to only apply the case-change to the first token, this won’t produce the desired result if the argument starts with a punctuation character. For example:
\mfugrabfirstuc
{`sample'}
This is equivalent to: \mfirstucMakeUppercase
{`}sample'
so no case-change is applied.
1.3. Exclusions
\mfirstucMakeUppercase
, but this is generally desirable. Identifies the text-block command
as an { }exclusion. That is, one that should have its argument excluded from a case-change.
Internally, \MFUexcl
adds to LaTeX3’s exclusion list \l_text_case_exclude_arg_tl
, which means that \MFUsentencecase
will skip the command and its argument and apply the case-change to the following content. Some common commands (\begin
\cite
\end
\label
and \ref
) are automatically added by the LaTeX3 kernel. The exclusions are also recognised by \makefirstuc
when it parses its argument.
\NoCaseChange
is automatically treated as an exclusion by the LaTeX3 case-changing commands with recent LaTeX kernels. You may want to add it as a blocker for \makefirstuc
and keep \MFUskippunc
for exclusions.
Note that \ensuremath
is added as an exclusion by mfirstuc otherwise \makefirstuc
will pass its argument to \MFUsentencecase
, which will cause a problem.
Another way of identifying content that should be excluded with \makefirstuc
is to encapsulate it with:
The command name stems from earlier versions where leading punctuation needed to be skipped. This is no longer necessary, but the command remains as a general purpose robust exclusion command.
For example, \glsadd
(provided by glossaries) should have its argument skipped, since its argument is a label, so the following will ensure that
will be skipped, and the case-change will be applied to the following text for both \glsadd
{ }\MFUsentencecase
and \makefirstuc
.
This will be equivalent to:\MFUexcl
{\glsadd
}\makefirstuc
{\glsadd
{ex}some text}\MFUsentencecase
{\glsadd
{ex}some text}
\glsadd
{ex}Some text
However, \glsadd
can take an optional argument which, if present, will cause a problem. For example: Both commands will cause the following error:\MFUexcl
{\glsadd
}\makefirstuc
{\glsadd
[counter=section]{ex}some text}\MFUsentencecase
{\glsadd
[counter=section]{ex}some text}
! Package glossaries Error: Glossary entry `[' has not been defined.This is because the open square bracket is assumed to be the argument of
\glsadd
, so this effectively becomes: which means that now\glsadd
{[}Counter=section] exsome text\glsadd
{[}Counter=section] exsome text
[
is considered the label and everything that follows is just text.
For this situation to work, you need to encapsulate the problematic content with an exclusion command, such as \NoCaseChange
or \MFUskippunc
:
This will also work with\makefirstuc
{\MFUskippunc
{\glsadd
[counter=section]{ex}}some text}
\MFUsentencecase
because mfirstuc automatically adds \MFUskippunc
to the exclusion list.
\glsadd
is automatically added as an exclusion, but be aware of the problem with using the optional argument, as described above.
Punctuation characters are skipped by \MFUsentencecase
. For example:
\MFUsentencecase
{`word'}
However, leading punctuation will result in \makefirstuc
passing its entire argument to \MFUsentencecase
(since the argument doesn’t start with ), which means that { }
\makefirstuc
won’t detect any blocker or mapping.
For example:
If you are using a package such as csquotes, bear in mind that if the command is followed by an asterisk (a “starred command”) or an optional argument then it won’t fit the expected\MFUblocker
{\nameref
}\newcommand
*{\qt
}[1]{``#1''}\makefirstuc
{``\nameref
{sec:sentencecase} section''} /\makefirstuc
{\MFUskippunc
{``}\nameref
{sec:sentencecase} section''} /\makefirstuc
{\qt
{\nameref
{sec:sentencecase} section}}
format and unexpected results will occur. { }
1.4. Blockers
A blocker is a command that prevents any case-change if it occurs at the start of \makefirstuc
or after the argument of an exclusion. Blockers are not supported by \MFUsentencecase
but are instead treated as exclusions.
Identifies as a blocker. Since blockers aren’t supported by
\MFUsentencecase
, this automatically implements \MFUexcl
{ }
to protect its argument from \MFUsentencecase
, but it won’t prevent subsequent content from being changed.For example:
\MFUblocker
{\nameref
}\makefirstuc
{\nameref
{sec:sentencecase} section}
In the following, the blocker isn’t detected by \makefirstuc
because the content doesn’t start with or { }
\protect { }
. This means that the entire content is passed to \MFUsentencecase
which treats \nameref
as an exclusion:
\MFUblocker
{\nameref
}\makefirstuc
{\relax
\nameref
{sec:sentencecase} section}
\makefirstuc
unless the other command is expanded before applying \makefirstuc
. For example, by using \xmakefirstuc
or \emakefirstuc
. If it doesn’t get expanded until after it has been passed to \MFUsentencecase
, then it will be treated as an exclusion instead.
Recent LaTeX kernels provide \NoCaseChange
and automatically add it as an exclusion. You may want to add it as a blocker for \makefirstuc
. For example:
Note that mfirstuc adds\makefirstuc
{\ensuremath
{\alpha
}-particle} /\makefirstuc
{$
\alpha
$
-particle} /\MFUsentencecase
{\ensuremath
{\alpha
}-particle} /\MFUsentencecase
{$
\alpha
$
-particle}\MFUblocker
{\NoCaseChange
}%\makefirstuc
{\ensuremath
{\alpha
}-particle} /\makefirstuc
{\NoCaseChange
{$
\alpha
$
}-particle} /\MFUsentencecase
{\ensuremath
{\alpha
}-particle} /\MFUsentencecase
{\NoCaseChange
{$
\alpha
$
}-particle}
\ensuremath
as an exclusion so \makefirstuc
will skip it. Whereas the example above that starts with $
will have the entire argument passed to \MFUsentencecase
, which skips the maths content. In the first paragraph, \NoCaseChange
is only an exclusion, but in the second paragraph it’s also a blocker. Blocker: 𝛼-Particle / 𝛼-particle / 𝛼-Particle / 𝛼-Particle
1.5. Mappings
A mapping indicates that one command should be substituted for another, instead of applying a case-change. The assumption is that the substituted command should perform the case-change instead. Mappings are not supported by \MFUsentencecase
but are instead treated as exclusions.
Identifies a mapping which indicates that
\makefirstuc
should replace with and not apply a case-change. This automatically implements: This means that is identified as a blocker (since it’s assumed to already be a sentence-case command) and is identified as an exclusion to protect its argument from\MFUexcl
{ }\MFUblocker
{ }
\MFUsentencecase
, which doesn’t support mappings.
For example (with glossaries):
This will be converted to:\MFUaddmap
{\gls
}{\Gls
}\makefirstuc
{\gls
{ex} some text}
\Gls
{ex} some text
Note that this and similar mappings are automatically added in glossaries v4.50+ and glossaries-extra v1.49+.
\makefirstuc
unless the other command is expanded before applying \makefirstuc
. For example, by using \xmakefirstuc
or \emakefirstuc
. If it doesn’t get expanded until after it has been passed to \MFUsentencecase
, then it will be treated as an exclusion instead.
1.6. Package Options
Redefines
\glsmakefirstuc
to simply use \MFUsentencecase
.Redefines
\glsmakefirstuc
to use \MFUsentencecase
without expanding its argument.Redefines
\glsmakefirstuc
to use \mfugrabfirstuc
and also redefines \mfirstucMakeUppercase
to use \MakeUppercase
.
This option is best avoided and is only provided to emulate the v2.07 behaviour of \glsmakefirstuc
. However, you may still have different results compared to v2.07, so you may need to use rollback instead.
2. Title-Case
The title-case commands are designed to convert the first letter of each word in a phrase to uppercase. These commands are robust.
This command applies a sentence-case command to each word in where the space character is used as the word separator. Note that it has to be an ordinary space character, not another form of space, such as~
or \space
. Note that no expansion is performed on . For example:
\capitalisewords
{a sample phrase}
See §2.1 for excluding words (such as “of”) from the case-changing.
\text_titlecase:n
, which converts the first letter to uppercase and all other letters to lowercase. For convenience, there are shortcut commands if expansion is required before parsing the argument:
This is a shortcut for:This fully expands before passing it to\expandafter
\capitalisewords
\expandafter
{ }
\capitalisewords
.
The parser used by \capitalisewords
first splits up the text on each space character. Each of these space-separated words may actually be a compound, so further parsing is performed on each “word”. The divisions within the compound word should be marked up with:
\capitalisewords
{a big\MFUwordbreak
{/}small idea}
Each sub-word within the compound word is encapsulated with:
Since it’s inconvenient to have to markup every hyphen,\MFUcapword
can be enabled to check for hyphens.
This conditional determines whether or not \MFUcapword
should consider a hyphen a word break. If this conditional is true, then \MFUcapword
will encapsulate its argument with:
This will parse for hyphen characters and apply the case change to each hyphen-separated word. Otherwise \MFUcapword
will treat its argument as a single word.The conditional can be set to true with:
and switched back off with:For example:
\capitalisewords
{server-side includes} /\MFUhyphentrue
\capitalisewords
{server-side includes}
The actual case-change of each word is performed with:
This defaults to\makefirstuc
{ }
but may be redefined to use \MFUsentencecase
, if preferred.
\MFUwordbreak
must be visible to the parser that searches for word breaks. This means they won’t be detected if they are within a group or in the definition of a command.
Formatting for the entire phrase must go outside \capitalisewords
(unlike \makefirstuc
). For example:
\capitalisewords
{\emph
{a sample phrase}} /\emph
{\capitalisewords
{a sample phrase}}
If your phrase is likely to contain formatting commands, you can instead use:
where may be just words (as with\capitalisewords
): \capitalisefmtwords
{ }
or may be entirely enclosed in a formatting command in the form: \capitalisefmtwords
{ { }}
or contain formatted sub-phrases: \capitalisefmtwords
{ { } }
The starred form only permits a text-block command at the start of the phrase. See §2.3 for examples.
If expansion is required, you can use:
which is a shortcut for:(The star modifier will be applied with\expandafter
\capitalisefmtwords
\expandafter
{ }
\xcapitalisefmtwords
*
in an appropriate manner.)This will fully expand its argument before passing it to
\capitalisefmtwords
. Again, the star modifier may be used.
\capitalisefmtwords
is only designed for phrases that contain text-block commands with a single argument, which should be a word or sub-phrase. Anything more complicated is likely to break. Instead, use the starred form or \capitalisewords
.
2.1. Excluding Words From Case-Changing
Some words typically shouldn’t have their case changed unless they occur at the start. These words can be identified with:
This only has a local effect. The global version is: The list of words that shouldn’t be capitalised can be cleared using:For example:
\capitalisewords
{the wind in the willows}\MFUnocap
{in}%\MFUnocap
{the}%\capitalisewords
{the wind in the willows}
Since the case-change is ultimately performed by \makefirstuc
, you can also use an exclusion to prevent an individual word from being changed. For example:
\newcommand
{\NoChange
}[1]{#1}\MFUexcl
{\NoChange
}\MFUclear
\capitalisewords
{the\NoChange
{wind} in the willows}
\MFUcapwordfirstuc
to use \MFUsentencecase
provided the exclusion command doesn’t expand (so \NoChange
would need to be protected or made robust in the above example).
\MFUwordbreak
but not to parts of a hyphenated word that are split by \MFUhyphencapword
. Examples:
- 1.Exceptions aren’t applied if
\MFUwordbreak
occurs before the first space.\MFUnocap
{a}\MFUnocap
{the}%\capitalisewords
{a\MFUwordbreak
{/}the something}A/The Something - 2.Exceptions are applied for non-leading words:
\MFUnocap
{and}\MFUnocap
{or}%\capitalisewords
{one and\MFUwordbreak
{/}or another}One and/or Another - 3.Exceptions aren’t applied for hyphenated parts:
\MFUhyphentrue
\MFUnocap
{and}\MFUnocap
{or}%\capitalisewords
{one and-or another}One And-Or Another
The supplementary package mfirstuc-english loads mfirstuc and uses
\MFUnocap
to add common English articles and conjunctions, such as “a”, “an”, “and”, “but”. You may want to add other words to this list, such as prepositions but, as there’s some dispute over whether prepositions should be capitalised, I don’t intend to add them to this package. Note that you need to explicitly load mfirstuc-english if you require it. There’s no automatic language detection performed by mfirstuc.If you want to write a similar package for another language, all you need to do is create a file with the extension .sty that starts with:
\NeedsTeXFormat
{LaTeX2e}
The next line should identify the package. For example, if you have called the file mfirstuc-french.sty then you need: \ProvidesPackage
{mfirstuc-french}
It’s a good idea to also add a version in the final optional argument, for example: \ProvidesPackage
{mfirstuc-french}[2014/07/30 v1.0]
Next load mfirstuc: \RequirePackage
{mfirstuc}
Now add all your \MFUnocap
commands. For example: \MFUnocap
{de}
At the end of the file add: \endinput
Put the file somewhere on TeX’s path, and now you can use this package in your document. You might also consider uploading it to CTAN in case other users find it useful.
2.2. PDF Bookmarks
If you are using hyperref and want to use \capitalisewords
or \capitalisefmtwords
(or the expanded variants) 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:
Package hyperref Warning: Token not allowed in a PDF string
(PDFDocEncoding):
(hyperref) removing `\capitalisewords
'
If you want to provide an alternative for the PDF bookmark, you can use hyperref’s \texorpdfstring
command. For example:
Alternatively, you can use hyperref’s mechanism for disabling commands within the bookmarks. For example:\chapter
{\texorpdfstring
{\capitalisewords
{a book of rhyme}}% TeX {A Book of Rhyme}% PDF }
The same applies to\pdfstringdefDisableCommands
{%\let
\capitalisewords
\@firstofone
}
\makefirstuc
. You can, however, use the expandable \MFUsentencecase
. So you may prefer: \pdfstringdefDisableCommands
{%\let
\capitalisewords
\MFUsentencecase
\let
\makefirstuc
\MFUsentencecase
}
See the hyperref manual for further details.
2.3. Examples
- 1.Text only:
\capitalisewords
{a little book of rhyme}A Little Book Of Rhyme - 2.Excluding words (see §2.1):
\MFUnocap
{of}\capitalisewords
{a little book of rhyme}A Little Book of Rhyme - 3.
\space
isn’t recognised as a word boundary:\capitalisewords
{a book of rhyme.}\capitalisewords
{a book\space
of rhyme.}A Book Of Rhyme.A Book of Rhyme.
- 4.Phrase entirely enclosed in a formatting command:
\capitalisefmtwords
{\emph
{a small book of rhyme}}A Small Book Of Rhyme - 5.Sub-phrase enclosed in a formatting command:
\capitalisefmtwords
{a\emph
{small book} of rhyme}A Small Book Of Rhyme - 6.Nested text-block commands:
\capitalisefmtwords
{\textbf
{a\emph
{small book}} of rhyme}A Small Book Of Rhyme - 7.Formatting and case-change exception (see §2.1):
\MFUnocap
{of}\capitalisefmtwords
{\textbf
{a\emph
{small book}} of rhyme}A Small Book of Rhyme - 8.Starred form:
\MFUnocap
{of}\capitalisefmtwords
*{\emph
{a small book of rhyme}}A Small Book of Rhyme - 9.The starred form also works with just text (no text-block command):
\MFUnocap
{of}\capitalisefmtwords
*{a small book of rhyme}A Small Book of Rhyme - 10.Expansion:
\newcommand
{\abc
}{\xyz
\space
four five}\newcommand
{\xyz
}{one two three} No expansion:\capitalisewords
{\abc
}. First object one-level expansion:\xcapitalisewords
{\abc
}. Fully expanded:\ecapitalisewords
{\abc
}.No expansion: one two three four five.First object one-level expansion: one two three Four Five.
Fully expanded: One Two Three Four Five.
Remember that the spaces need to be explicit. In the second case above, using
\xcapitalisewords
, the space before “four” has been hidden within\space
so it’s not recognised as a word boundary, but in the third case,\space
has been expanded to an actual space character.
If there is a text-block command within the argument of the starred form, it’s assumed to be at the start of the argument. Unexpected results can occur if there are other commands. For example:
In this case\MFUnocap
{of}\capitalisefmtwords
*{\emph
{a small} book\textbf
{of rhyme}}
\textbf{of rhyme}
is considered a single word. Similarly if the text-block command occurs in the middle of the argument: \MFUnocap
{of}\capitalisefmtwords
*{a\emph
{very small} book of rhyme}
\emph{very small}
is considered a single word.Grouping causes interference. As with all the commands described here, avoid declarations.
\capitalisefmtwords
{{\bfseries
a\emph
{small book}} of rhyme}
Avoid complicated commands in the unstarred version. For example, the following breaks:
However it can work with the starred form and the simpler\newcommand
*{\swap
}[2]{{#2}{#1}}\capitalisefmtwords
{a\swap
{bo}{ok} of rhyme}
\capitalisewords
: \newcommand
*{\swap
}[2]{{#2}{#1}}\capitalisefmtwords
*{a\swap
{bo}{ok} of rhyme}\capitalisewords
{a\swap
{bo}{ok} of rhyme}
A okBo Of Rhyme
3. Miscellaneous
3.1. Saving exclusions, blockers and mappings in the aux File
If the exclusions, mappings and blockers are required by some external tool, the information can be saved in the aux file.
This saves the information at the end of the document using a delayed write. This means that it can register all information identified throughout the document, but there’s a chance the document may end before the write takes place (for example, if the last page only contains floats). This command may be counteracted by: This saves the information using a protected write at the point where this command occurs, which may be too soon if additional exclusions, mappings or blockers are identified later. This command will counteract any instance of
\MFUsaveatend
, regardless of whether or not \MFUsaveatend
comes before or after \MFUsave
.The associated aux commands are listed below. In each case, a definition is provided in the aux file that does nothing.
Lists all exclusions. For example:\@mfu@excls
{\begin
\cite
\end
\label
\ref
\cite
\NoCaseChange
\ensuremath
\MFUskippunc
\gls
\glspl
}
Lists all blockers. For example:
\@mfu@blockers
{\Gls
\Glspl
}
Lists all mappings as a = list. For example:
\@mfu@mappings
{ {\gls
}= {\Gls
}, {\glspl
}= {\Glspl
}}
3.2. All-Caps
This command was originally used to perform the actual conversion to uppercase and was defined to use command
\MakeUppercase
. The glossaries package (before v4.50) formerly loaded the textcase package and redefined \mfirstucMakeUppercase
to use \MakeTextUppercase
, which was better than \MakeUppercase
.
The textcase package has been deprecated as from 2022 and it now simply sets \MakeTextUppercase
to \MakeUppercase
because the new kernel now defines \MakeUppercase
to use the newer LaTeX3 command \text_uppercase:n
. Although that command is expandable, \MakeUppercase
is robust.
As from v2.08, mfirstuc now defines \mfirstucMakeUppercase
so that it uses \text_titlecase_first:n
directly, rather than indirectly through \MakeUppercase
, which means that it’s now expandable. However, \mfirstucMakeUppercase
is no longer used by mfirstuc except in \mfugrabfirstuc
, which is provided to emulate v2.07. Note that the grabfirst option will also redefine \mfirstucMakeUppercase
to use \MakeUppercase
.
3.3. UTF-8
This section only applies to rollback or the use of \mfugrabfirstuc
(implemented via the grabfirst option).
Prior to version 2.08, the case-change applied by the \glsmakefirstuc
command worked by utilizing the fact that, in most cases, TeX doesn’t require a regular argument to be enclosed in braces if it only consists of a single token. (This is why you can do, say, \frac12
instead of \frac{1}{2}
or x^2
instead of x^{2}
, although this practice is discouraged by some.)
A simplistic version of the original \glsmakefirstuc
command is:
Here\newcommand
*{\FirstUC
}[1]{\MakeUppercase
#1}
\FirstUC
{abc}
is equivalent to \MakeUppercase
abc
and since \MakeUppercase
requires an argument, it grabs the first token (the character “a” in this case) and uses that as the argument so that the result is “Abc”. This behaviour can be achieved with \mfugrabfirstuc
.Unfortunately, this will fail if the content starts with a UTF-8 character and you are using pdfLaTeX, where each octet of the UTF-8 character is a separate token. This isn’t a problem with XeLaTeX and LuaLaTeX which both treat the entire multibyte character as a single token.
LaTeX3 now provides \text_titlecase_first:n
to convert the first character to uppercase, so now the case-change can be applied with:
This is exactly what\ExplSyntaxOn
\text_titlecase_first:n
{élite}\ExplSyntaxOff
\MFUsentencecase
does without the need to switch on LaTeX3 syntax. The difference with the default definition of \glsmakefirstuc
is that it prevents its argument from being expanded.
Symbols
- 📌
- The syntax and usage of a command, environment or option etc.
- ℹ
- An important message.
- 🛈
- Prominent information.
- 🖹
- LaTeX code to insert into your document.
- 🖹🛇
- Problematic code which should be avoided.
- 🖺
- How the example code should appear in the PDF.
- 🔎
- Text in a transcript or log file or written to STDOUT or STDERR.
- 🗋U
- Code that requires a native Unicode engine (XeLaTeX or LuaLaTeX).
- 𝍢
- An option that doesn’t take a value.
- ⚠
- A warning.
Glossary
- Blocker
- A command that prohibits case-changing. If encountered by
\makefirstuc
, it won’t attempt to apply any case-changing. See §1.4. - Exclusion command
- A command whose argument should be skipped by the case-changer. The content that follows the command should have its case-changed instead. See §1.3.
- Exclusion word
- A word that shouldn’t have its case changed by title-case commands, unless the word occurs at the start.
- Mapping
- A command that should be substituted by another, if encountered by
\makefirstuc
, instead of applying a case-change. See §1.5. - Semantic command
- Essentially, this is a command associated with a particular element, idea or topic that hides the font and other stylistic formatting inside its definition. For example, Latin taxonomy is usually displayed in italic. Explicitly using font commands, for example
is syntactic markup. Whereas defining a command called, say,\textit
{Clostridium}\bacteria
that displays its argument in italics is a semantic command. The actual styling is hidden and the command relates specifically to a particular concept.Syntactic:
The end result is the same: The advantage with semantic commands is that it’s much easier to change the style, simply by adjusting the command definition. Note that I’ve used\textit
{Clostridium}\newrobustcmd
*{\bacteria
}[1]\emph
{#1}%
Semantic:\bacteria
{Clostridium}\newrobustcmd
to make the semantic command robust as the style commands can cause a problem if they expand too soon. - Sentence-case
- Content that should appear at the start of a sentence that needs to have its first significant character converted to uppercase. See §1.
- Title-case
- Content that needs to appear in a title that should have each significant word converted to sentence-case. See §2.
- Unicode Transformation Format (8-bit) (UTF-8)
- A variable-width encoding that uses 8-bit code units. This means that some characters are represented by more that one byte. XeLaTeX and LuaLaTeX treat the multi-byte sequence as a single token, but the older LaTeX formats have single-byte tokens, which can cause complications, although these have mostly been addressed with the newer kernels introduced over the past few years. Related blog article: Binary Files, Text Files and File Encodings.
Command Summary
@
An aux file command that lists all the identified blockers. §3.1; 27
An aux file command that lists all the identified exclusions. §3.1; 26
An aux file command that lists all the identified mappings as a = list. §3.1; 27
C
Similar to \capitalisewords
but for content that may contain formatting commands. §2; 16
Applies title-case to . This will apply \MFUcapword
to each word in (unless the word has been identified as an exclusion word and doesn’t occur at the start of ). §2; 14
E
Fully expands \capitalisefmtwords
including the *
modifier, if provided. §2; 17
Fully expands \capitalisewords
. §2; 14
Fully expands \makefirstuc
. §1.2; 6
G
Used by \makefirstuc
to perform the case-change. This uses
but by default will prevent its argument from being expanded. §1.2; 6\MFUsentencecase
{ }
Globally adds exclusion word list for \capitalisewords
. §2.1; 18
I
Conditional that determines whether or not hyphens should be considered word boundaries by the title-case commands. §2; 15
M
Converts sentence-case internally using \glsmakefirstuc
to perform the case-change, but first parses to deal with special cases. §1.2; 4
Converts uppercase. Now only used in \mfugrabfirstuc
. §3.2; 27
Identifies a mapping from the command to command . §1.5; 12
Locally identifies blocker command. §1.4; 11
as a
Uses either \MFUhyphencapword
or \MFUcapwordfirstuc
depending on \ifMFUhyphen
. §2; 15
Used by \MFUcapword
and \MFUhyphencapword
to apply the case-change to the given word. This just does
by default. §2; 16\makefirstuc
{ }
Locally clears the exclusion word list for \capitalisewords
. §2.1; 18
Locally identifies exclusion command. §1.3; 8
as an
Provide to emulate \glsmakefirstuc
in v2.07 and below, but can still produce different results to v2.07. This will attempt to grab only the first character of and convert it to uppercase, leaving the rest of unchanged. This won’t work if starts with a UTF-8 character, unless you are using XeLaTeX or LuaLaTeX. §1.2; 7
Used by \MFUcapword
to apply \MFUcapwordfirstuc
to each hyphen-separated word in , if hyphens should indicate a word-break. §2; 15
Sets \ifMFUhyphen
to false. §2; 15
Sets \ifMFUhyphen
to true. §2; 15
Locally adds exclusion word list for \capitalisewords
. §2.1; 17
Saves the list of exclusions, blockers and mappings to the aux file (if required by some external tool). This command sets itself to \relax
so it doesn’t repeat the action if used multiple times, and counteracts any use of \MFUsaveatend
. §3.1; 26
Saves the list of exclusions, blockers and mappings to the aux file (if required by some external tool) at the end of the document. This command sets itself to \relax
so it doesn’t repeat the action if used multiple times, but it can be overridden by \MFUsave
. §3.1; 26
Converts sentence-case with expansion. §1.2; 4
to
Used to markup a character or command that should be treated as a word break by the title-case commands. §2; 15
X
Shortcut for \expandafter
including the \capitalisefmtwords
\expandafter{ }*
modifier, if provided. §2; 17
Shortcut for \expandafter
. §2; 14\capitalisewords
\expandafter{ }
Shortcut for \expandafter
. §1.2; 5\makefirstuc
\expandafter{ }
Index
Symbols
~
14$
12@
B
C
E
F
G
\Glspl
27H
I
\index
2L
\l_text_case_exclude_arg_tl
8M
\MakeTextUppercase
27N
P
\pdfstringdefDisableCommands
21\protect
5R
S
T
\texorpdfstring
20\text_titlecase:n
14\text_uppercase:n
27U
\unexpanded
6X