[latex3-commits] [latex3/latex2e] titlecase: Re-work \MakeTitlecase implementation (5468a7df3)
github at latex-project.org
github at latex-project.org
Mon Nov 11 09:59:59 CET 2024
Repository : https://github.com/latex3/latex2e
On branch : titlecase
Link : https://github.com/latex3/latex2e/commit/5468a7df3b5e269126c30839a61d993b05cf402b
>---------------------------------------------------------------
commit 5468a7df3b5e269126c30839a61d993b05cf402b
Author: Joseph Wright <joseph at texdev.net>
Date: Mon Nov 11 08:59:59 2024 +0000
Re-work \MakeTitlecase implementation
Fixes latex3/latex3#1316
>---------------------------------------------------------------
5468a7df3b5e269126c30839a61d993b05cf402b
base/changes.txt | 4 +++
base/doc/ltnews41.tex | 20 +++++++++++++
base/ltfinal.dtx | 18 ++++++++----
base/testfiles/github-1545.lvt | 29 +++++++++++++++++++
base/testfiles/github-1545.tlg | 64 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 130 insertions(+), 5 deletions(-)
diff --git a/base/changes.txt b/base/changes.txt
index e0258170d..82117cbeb 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -6,6 +6,10 @@ 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>
+ * ltfinal.dtx (subsection{Case changing}):
+ Use \text_titlecase_first:nn for titlecasing
+
2024-11-06 Joseph Wright <Joseph.Wright at latex-project.org>
* ltoutenc.dtx
Add support for \={i} to OT1 and T1
diff --git a/base/doc/ltnews41.tex b/base/doc/ltnews41.tex
index 0c9751704..efe3e3005 100644
--- a/base/doc/ltnews41.tex
+++ b/base/doc/ltnews41.tex
@@ -149,6 +149,26 @@
\section{Code improvements}
+\subsection{Refinement of \cs{MakeTitlecase}}
+
+We introduced \cs{MakeTitlecase} as a late addition to the June
+2022 release, making use of the improved case code in
+\pkg{expl3}. Unlike upper and lowercasing, making text
+titlecased is more tricky to get right: for example, do you just
+change the first character and leave the rest alone.
+
+A subtle issue was reported against the \pkg{expl3} repository
+(\url{https://github.com/latex3/latex3/issues/1316}) which links
+to how we deal with the question of case changing
+\enquote{words} but shows up if you titlecase text stored in a
+command.
+
+We have looked again at how to implement \cs{MakeTitlecase} to
+be as predictable as possible, and have made a change in this
+release. The command no longer tries to lowercase text before
+applying titlecasing, and gives the correct result for text
+stored in commands.
+
\section{Bug fixes}
%\subsection{A fix}
diff --git a/base/ltfinal.dtx b/base/ltfinal.dtx
index 2c6b96049..58f810577 100644
--- a/base/ltfinal.dtx
+++ b/base/ltfinal.dtx
@@ -33,7 +33,7 @@
%<*driver>
% \fi
\ProvidesFile{ltfinal.dtx}
- [2024/07/08 v2.3c LaTeX Kernel (Final Settings)]
+ [2024/11/11 v2.3d LaTeX Kernel (Final Settings)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltfinal.dtx}
@@ -1080,6 +1080,8 @@
% \end{macrocode}
% \end{macro}
%
+% \subsection{Case changing}
+%
% \begin{macro}{\MakeUppercase}
% \begin{macro}{\MakeLowercase}
% \begin{macro}{\MakeTitlecase}
@@ -1110,6 +1112,7 @@
% \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}}
% Wrappers around the L3 case changing functions.
% |\protected| to make them mostly safe as replacements for |uppercase|
% and |\lowercase|.
@@ -1153,7 +1156,7 @@
}
}
{ \keys_set:nn { __kernel } {#2} }
- \use:c { text_ #1 case:Vn } \reserved at a {#3}
+ \use:c { text_ #1 :Vn } \reserved at a {#3}
}
% \end{macrocode}
% The odd use of \emph{three} spaces here is needed as \pkg{ltcmd} uses the
@@ -1173,6 +1176,11 @@
\reserved at a { Lower }
\reserved at a { Title }
% \end{macrocode}
+% These don't get covered above so we do them manually.
+% \begin{macrocode}
+\cs_generate_variant:Nn \text_titlecase_all:nn { V }
+\cs_generate_variant:Nn \text_titlecase_first:nn { V }
+% \end{macrocode}
% \changes{v2.2y}{2022/11/30}{Set \cs{oe}/\cs{OE} equal to act as a marker for \pkg{babel}}
% \changes{v2.2z}{2023/03/28}{Use groups for gh/1021}
% Currently, \pkg{babel} uses the equivalence of \cs{oe} and \cs{OE} to force casing of
@@ -1183,17 +1191,17 @@
\cs_new_protected:cpn { MakeLowercase \c_space_tl \c_space_tl \c_space_tl } [#1] #2
{{
\let \OE \oe
- \@@text at case@aux { lower } {#1} {#2}
+ \@@text at case@aux { lowercase } {#1} {#2}
}}
\cs_new_protected:cpn { MakeUppercase \c_space_tl \c_space_tl \c_space_tl } [#1] #2
{{
\let \oe \OE
- \@@text at case@aux { upper } {#1} {#2}
+ \@@text at case@aux { uppercase } {#1} {#2}
}}
\cs_new_protected:cpn { MakeTitlecase \c_space_tl \c_space_tl \c_space_tl } [#1] #2
{{
\let \oe \OE
- \@@text at case@aux { title } {#1} {#2}
+ \@@text at case@aux { titlecase_first } {#1} {#2}
}}
% \end{macrocode}
%
diff --git a/base/testfiles/github-1545.lvt b/base/testfiles/github-1545.lvt
new file mode 100644
index 000000000..598dcf5fa
--- /dev/null
+++ b/base/testfiles/github-1545.lvt
@@ -0,0 +1,29 @@
+\documentclass{article}
+
+\input{test2e}
+
+\NewDocumentCommand\hello{}{hello}
+\NewDocumentCommand\helloA{}{helloA}
+\NewDocumentCommand\helloB{}{helloB}
+\NewDocumentCommand\helloC{}{helloC}
+\NewDocumentCommand\helloD{}{helloD}
+\DeclareCaseChangeEquivalent{\hello}{%
+ \CaseSwitch
+ {\helloA}
+ {\helloB}
+ {\helloC}
+ {\helloD}}
+
+\showoutput
+
+\begin{document}
+
+\START
+
+\MakeLowercase{\hello}
+
+\MakeUppercase{\hello}
+
+\MakeTitlecase{\hello}
+
+\end{document}
diff --git a/base/testfiles/github-1545.tlg b/base/testfiles/github-1545.tlg
new file mode 100644
index 000000000..7fc242c85
--- /dev/null
+++ b/base/testfiles/github-1545.tlg
@@ -0,0 +1,64 @@
+This is a generated file for the LaTeX2e validation system.
+Don't change this file in any respect.
+Completed box being shipped out [1]
+\vbox(633.0+0.0)x407.0
+.\glue 16.0
+.\vbox(617.0+0.0)x345.0, shifted 62.0
+..\vbox(12.0+0.0)x345.0, glue set 12.0fil
+...\glue 0.0 plus 1.0fil
+...\hbox(0.0+0.0)x345.0
+....\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
+...\write-{}
+...\glue(\topskip) 3.05556
+...\hbox(6.94444+0.0)x345.0, glue set 302.22217fil
+....\hbox(0.0+0.0)x15.0
+....\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 C
+....\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 302.36104fil
+....\hbox(0.0+0.0)x15.0
+....\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 B
+....\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 301.8055fil
+....\hbox(0.0+0.0)x15.0
+....\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 0.0 plus 1.0fil
+...\glue 0.0
+...\glue 0.0 plus 0.0001fil
+..\glue(\baselineskip) 23.55556
+..\hbox(6.44444+0.0)x345.0
+...\hbox(6.44444+0.0)x345.0, glue set 170.0fil
+....\glue 0.0 plus 1.0fil
+....\OT1/cmr/m/n/10 1
+....\glue 0.0 plus 1.0fil
+(github-1545.aux)
More information about the latex3-commits
mailing list.