[latex3-commits] [git/LaTeX3-latex3-latex2e] gh239: Implement copying composites from a predefined list (81b00a7f)
PhelypeOleinik
tex.phelype at gmail.com
Fri Jun 12 01:16:13 CEST 2020
Repository : https://github.com/latex3/latex2e
On branch : gh239
Link : https://github.com/latex3/latex2e/commit/81b00a7f142146520bd5febe64f244bbb0291075
>---------------------------------------------------------------
commit 81b00a7f142146520bd5febe64f244bbb0291075
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date: Thu Jun 11 20:16:13 2020 -0300
Implement copying composites from a predefined list
>---------------------------------------------------------------
81b00a7f142146520bd5febe64f244bbb0291075
base/ltoutenc.dtx | 93 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 82 insertions(+), 11 deletions(-)
diff --git a/base/ltoutenc.dtx b/base/ltoutenc.dtx
index a0d1daaf..75e06808 100644
--- a/base/ltoutenc.dtx
+++ b/base/ltoutenc.dtx
@@ -1241,6 +1241,10 @@
% \begin{macro}{\@copy at declaretextcommand@enc}
% \begin{macro}{\@copy at declaretextcommand@defaults}
% \begin{macro}{\@unexpanded at cdrcar}
+% \begin{macro}{\@if at text@composite at copy@else}
+% \begin{macro}{\@copy at text@composite}
+% \begin{macro}{\@copy at one@composite}
+% \begin{macro}{\@copy at composite@stop}
% \changes{v1.5h}{2020/05/09}{Added \cs{DeclareCommandCopy} (gh/239)}
%
% With the generic \cs{NewCommandCopy} macro defined earlier in
@@ -1392,7 +1396,7 @@
\ifx\reserved at a#5%
\long\def#4{\UseTextAccent{#1}#2}%
\else
- \@if at text@composite at copy@else#4#5#3{#6}%
+ \@if at text@composite at copy@else#4#5{#6}%
{\declare at command@copy at let#4#5}%
\fi
\fi}
@@ -1402,14 +1406,23 @@
% composite command. Text composites are declared differently for
% each argument \meta{char}, and are stored as
% |\\|\meta{enc}|\|\meta{cmd}-\meta{char}, so we can't copy them
-% unless we know every \meta{char} that was declared. A copied
-% composite will still work, but that's because it will use the old
-% name, so it isn't a \emph{full} copy.
+% unless we know every \meta{char} that was declared. To completely
+% copy a composite we define a list of characters used in composites
+% for each encoding, and when copying we cycle through that list
+% copying the command when defined. \cs{@copy at text@composite} takes
+% care of copying a composite.
% \begin{macrocode}
-\def\@if at text@composite at copy@else#1#2#3#4{%
+\def\@if at text@composite at copy@else#1#2#3{%
\begingroup
\escapechar=`\\
\edef\x{\endgroup
+% \end{macrocode}
+%
+% Here we use the same approach as in \cs{@if at DeclareTextCommand}:
+% define a temporary macro with a template text and then check if the
+% macro we're copying matches. Here's the macro that will make the
+% test:
+% \begin{macrocode}
\def\noexpand\reserved at a####1\detokenize{%
macro:}\string##1->%
\detokenize{\@text at composite#2}\string##1\detokenize{\@empty
@@ -1419,16 +1432,70 @@
\else
\expandafter\@firstoftwo
\fi}}%
+% \end{macrocode}
+%
+% And here we use it on \cs{meaning}\verb=#2=:
+% \begin{macrocode}
\noexpand\reserved at a\meaning#2\detokenize{%
macro:}\string##1->%
\detokenize{\@text at composite#2}\string##1\detokenize{\@empty
\@text at composite}{\relax}\noexpand\@nil
- }\x
- {\@latex at error{Composites cannot be copied yet}\@eha%
- \@firstofone
- % \@copy at text@composite
- }%
- {\@firstofone}}
+% \end{macrocode}
+%
+% If the test is true, call \cs{@copy at text@composite} to do the
+% copying (with \cs{lowercase} to get )
+% \begin{macrocode}
+ }\x{\@copy at text@composite#1#2{#3}%
+ \@gobble}%
+ {\@firstofone}}
+% \end{macrocode}
+%
+% Copying the composite command is rather easy, as we can temporarily
+% redefine \cs{@text at composite} to do the hard work for us.
+% \begin{macrocode}
+\def\@copy at text@composite#1#2#3{%
+ \begingroup
+ \def\@text at composite##1##2\@text at composite##3{%
+ \endgroup
+ \def#1####1{\@text at composite#1##2\@text at composite{##3}}}%
+ #2{##1}%
+% \end{macrocode}
+%
+% Now expand the list of composites for the current (being copied)
+% encoding (\verb=#3=) and call \cs{@copy at one@composite} with the new
+% name, the old name, and one item in the list.
+% \begin{macrocode}
+ \begingroup
+ \escapechar=`\\
+ \edef\x{\endgroup
+ \noexpand\@copy at one@composite
+ {\string#1}{\string#2}%
+ \ifx\csname @list@#3enc at composites\endcsname\relax
+ \unexpande{\@nnil\@nil
+ \@latex at error{List of composites undefined for encoding #3}\@ehc}
+ \else
+ \unexpanded\expandafter\expandafter
+ \expandafter{\csname @list@#3enc at composites\endcsname
+ \@nnil\@nil}%
+ \fi}%
+ \x}
+% \end{macrocode}
+%
+% To actually make the copy, use just \cs{ifcsname} as it prevents the
+% csname from being added to the hash table, and makes the whole thing
+% a bit faster, since it doesn't require the two test from
+% \cs{@ifundefined} (as a side effect, commands that are equal to
+% \cs{relax} are copied through, but then, it's unlikely).
+% \begin{macrocode}
+\def\@copy at one@composite#1#2#3{%
+ \ifx\@nnil#3\@copy at composite@stop\fi
+ \ifcsname#2-\string#3\endcsname
+ \expandafter
+ \let\csname#1-\string#3\expandafter\endcsname
+ \csname#2-\string#3\endcsname
+ \fi
+ \@copy at one@composite{#1}{#2}}
+\def\@copy at composite@stop\fi#1\@copy at one@composite#2\@nil{\fi}
% \end{macrocode}
%
% Here's the \cs{@copy at declaretextcommand@enc} auxiliary:
@@ -1465,6 +1532,10 @@
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
%
% \subsubsection{Hyphenation}
%
More information about the latex3-commits
mailing list.