[latex3-commits] [latex3/latex2e] titlecase: Extend titlecasing to first/all words (026cf3f1e)
github at latex-project.org
github at latex-project.org
Tue Nov 12 14:46:16 CET 2024
Repository : https://github.com/latex3/latex2e
On branch : titlecase
Link : https://github.com/latex3/latex2e/commit/026cf3f1e3d8e68fe63f550f6edc17c69fbaad1e
>---------------------------------------------------------------
commit 026cf3f1e3d8e68fe63f550f6edc17c69fbaad1e
Author: Joseph Wright <joseph at texdev.net>
Date: Tue Nov 12 07:07:59 2024 +0000
Extend titlecasing to first/all words
>---------------------------------------------------------------
026cf3f1e3d8e68fe63f550f6edc17c69fbaad1e
base/changes.txt | 7 ++++--
base/doc/ltnews41.tex | 4 ++++
base/doc/usrguide.tex | 14 ++++++++++++
base/ltfinal.dtx | 13 +++++++----
base/testfiles/github-1545.lvt | 4 ++++
base/testfiles/github-1545.tlg | 52 +++++++++++++++++++++++++++++++++++++++---
6 files changed, 85 insertions(+), 9 deletions(-)
diff --git a/base/changes.txt b/base/changes.txt
index 82117cbeb..75821971e 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -6,9 +6,12 @@ to completeness or accuracy and it contains some references to files that are
not part of the distribution.
================================================================================
-2024-11-11 Joseph Wright <Joseph.Wright at latex-project.org>
+2024-11-12 Joseph Wright <Joseph.Wright at latex-project.org>
* ltfinal.dtx (subsection{Case changing}):
- Use \text_titlecase_first:nn for titlecasing
+ Use \text_titlecase_...:nn for titlecasing
+ Introduce option to titlecase first or all words
+ * usrguide.tex:
+ Document new key for titlecasing
2024-11-06 Joseph Wright <Joseph.Wright at latex-project.org>
* ltoutenc.dtx
diff --git a/base/doc/ltnews41.tex b/base/doc/ltnews41.tex
index 7c91a8241..eef1f26fe 100644
--- a/base/doc/ltnews41.tex
+++ b/base/doc/ltnews41.tex
@@ -169,6 +169,10 @@ release. The command no longer tries to lowercase text before
applying titlecasing, and gives the correct result for text
stored in commands.
+We have also added an additional key to the optional argument to
+\cs{MakeTitlecase} which allows the user to decide if this will
+apply only to the first word (the default) or to all words.
+
\section{Bug fixes}
%\subsection{A fix}
diff --git a/base/doc/usrguide.tex b/base/doc/usrguide.tex
index abf128361..21b15fb68 100644
--- a/base/doc/usrguide.tex
+++ b/base/doc/usrguide.tex
@@ -1282,6 +1282,20 @@ available under the alias \texttt{lang}, which can be used to give a language
identifier in BCP-47 format. This is then applied to select language-specific
features during case-changing.
+For titlecasing, the key \texttt{words} may also be used: this
+takes a choice of \texttt{first} or \texttt{all}. The standard
+setting is \texttt{first}, and means that only the very first
+\enquote{letter} is (broadly) uppercased. The alternative,
+\texttt{all}, means that the input is divided at each space, and
+for each word that results, the first letter is uppercased. For
+example
+\begin{verbatim}
+ \MakeTitlecase[words = first]{some words}
+ \MakeTitlecase[words = all]{some words}
+\end{verbatim}
+gives \enquote{\MakeTitlecase[words = first]{some words}
+\MakeTitlecase[words = all]{some words}}.
+
The input given to these commands is \enquote{expanded} before case changing is
applied. This means that any commands within the input that convert to pure
text will be case changed. Mathematical content is automatically excluded, as
diff --git a/base/ltfinal.dtx b/base/ltfinal.dtx
index 58f810577..7be7c033b 100644
--- a/base/ltfinal.dtx
+++ b/base/ltfinal.dtx
@@ -33,7 +33,7 @@
%<*driver>
% \fi
\ProvidesFile{ltfinal.dtx}
- [2024/11/11 v2.3d LaTeX Kernel (Final Settings)]
+ [2024/11/12 v2.3d LaTeX Kernel (Final Settings)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltfinal.dtx}
@@ -1112,7 +1112,8 @@
% \changes{v2.2x}{2022/10/26}{Make case changing commands language-aware}
% \changes{v2.2x}{2022/10/26}{Auto-detect \pkg{babel} locale}
% \changes{v2.3a}{2023/04/11}{Use new generic mechanism to detect locale}
-% \changes{v2.3d}{2024/11/11}{Use updated titlecase-first function in \pkg{expl3}}
+% \changes{v2.3d}{2024/11/12}{Use updated titlecase-first function in \pkg{expl3}}
+% \changes{v2.3d}{2024/11/12}{Add option to titlecase first or all words}
% Wrappers around the L3 case changing functions.
% |\protected| to make them mostly safe as replacements for |uppercase|
% and |\lowercase|.
@@ -1140,11 +1141,15 @@
\keys_define:nn { __kernel }
{
lang .str_set:N = \reserved at a ,
- locale .str_set:N = \reserved at a
+ locale .str_set:N = \reserved at a ,
+ words .choices:nn =
+ { all , first }
+ { \str_set:Nn \reserved at b {#1} }
}
\cs_new_protected:Npn \@@text at case@aux #1#2#3
{
\cs_set_nopar:Npn \reserved at a { }
+ \cs_set_nopar:Npn \reserved at b { }
\tl_if_blank:nTF {#2}
{
\str_set:Nx \reserved at a
@@ -1201,7 +1206,7 @@
\cs_new_protected:cpn { MakeTitlecase \c_space_tl \c_space_tl \c_space_tl } [#1] #2
{{
\let \oe \OE
- \@@text at case@aux { titlecase_first } {#1} {#2}
+ \@@text at case@aux { titlecase_ \reserved at b } {#1} {#2}
}}
% \end{macrocode}
%
diff --git a/base/testfiles/github-1545.lvt b/base/testfiles/github-1545.lvt
index 598dcf5fa..fe263d8e7 100644
--- a/base/testfiles/github-1545.lvt
+++ b/base/testfiles/github-1545.lvt
@@ -26,4 +26,8 @@
\MakeTitlecase{\hello}
+\MakeTitlecase{some words}
+\MakeTitlecase[words = first]{some words}
+\MakeTitlecase[words = all]{some words}
+
\end{document}
diff --git a/base/testfiles/github-1545.tlg b/base/testfiles/github-1545.tlg
index 7fc242c85..bcca128a7 100644
--- a/base/testfiles/github-1545.tlg
+++ b/base/testfiles/github-1545.tlg
@@ -10,7 +10,7 @@ Completed box being shipped out [1]
....\hbox(0.0+0.0)x345.0
..\glue 25.0
..\glue(\lineskip) 0.0
-..\vbox(550.0+0.0)x345.0, glue set 515.94489fil
+..\vbox(550.0+0.0)x345.0, glue set 503.94617fil
...\write-{}
...\glue(\topskip) 3.05556
...\hbox(6.94444+0.0)x345.0, glue set 302.22217fil
@@ -41,14 +41,60 @@ Completed box being shipped out [1]
...\glue(\parskip) 0.0 plus 1.0
...\glue(\parskip) 0.0
...\glue(\baselineskip) 5.05556
-...\hbox(6.94444+0.0)x345.0, glue set 301.8055fil
+...\hbox(6.94444+0.0)x345.0, glue set 299.44438fil
....\hbox(0.0+0.0)x15.0
+....\OT1/cmr/m/n/10 e
+....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 h
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 l
....\OT1/cmr/m/n/10 l
....\OT1/cmr/m/n/10 o
-....\OT1/cmr/m/n/10 D
+....\penalty 10000
+....\glue(\parfillskip) 0.0 plus 1.0fil
+....\glue(\rightskip) 0.0
+...\glue(\parskip) 0.0 plus 1.0
+...\glue(\parskip) 0.0
+...\glue(\baselineskip) 5.05556
+...\hbox(6.94444+0.0)x345.0, glue set 156.36086fil
+....\hbox(0.0+0.0)x15.0
+....\OT1/cmr/m/n/10 e
+....\OT1/cmr/m/n/10 n
+....\OT1/cmr/m/n/10 s
+....\OT1/cmr/m/n/10 o
+....\OT1/cmr/m/n/10 m
+....\OT1/cmr/m/n/10 e
+....\glue 3.33333 plus 1.66666 minus 1.11111
+....\OT1/cmr/m/n/10 w
+....\kern-0.27779
+....\OT1/cmr/m/n/10 o
+....\OT1/cmr/m/n/10 r
+....\OT1/cmr/m/n/10 d
+....\OT1/cmr/m/n/10 s
+....\glue 3.33333 plus 1.66666 minus 1.11111
+....\OT1/cmr/m/n/10 S
+....\OT1/cmr/m/n/10 o
+....\OT1/cmr/m/n/10 m
+....\OT1/cmr/m/n/10 e
+....\glue 3.33333 plus 1.66666 minus 1.11111
+....\OT1/cmr/m/n/10 w
+....\kern-0.27779
+....\OT1/cmr/m/n/10 o
+....\OT1/cmr/m/n/10 r
+....\OT1/cmr/m/n/10 d
+....\OT1/cmr/m/n/10 s
+....\glue 3.33333 plus 1.66666 minus 1.11111
+....\OT1/cmr/m/n/10 S
+....\OT1/cmr/m/n/10 o
+....\OT1/cmr/m/n/10 m
+....\OT1/cmr/m/n/10 e
+....\glue 3.33333 plus 1.66666 minus 1.11111
+....\OT1/cmr/m/n/10 W
+....\kern-0.83334
+....\OT1/cmr/m/n/10 o
+....\OT1/cmr/m/n/10 r
+....\OT1/cmr/m/n/10 d
+....\OT1/cmr/m/n/10 s
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
More information about the latex3-commits
mailing list.