[latex3-commits] [git/LaTeX3-latex3-latex3] master: xbox: New approach for lrbox (baea9ab73)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Aug 26 09:40:02 CEST 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/baea9ab73f6e9ba6ee18bd8dca20377a630d119c
>---------------------------------------------------------------
commit baea9ab73f6e9ba6ee18bd8dca20377a630d119c
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Wed Aug 26 08:12:58 2020 +0100
xbox: New approach for lrbox
>---------------------------------------------------------------
baea9ab73f6e9ba6ee18bd8dca20377a630d119c
l3trial/xbox/testfiles/xbox000.tlg | 1 +
l3trial/xbox/testfiles/xbox001.luatex.tlg | 14 +++----
l3trial/xbox/testfiles/xbox001.ptex.tlg | 18 +++------
l3trial/xbox/testfiles/xbox001.tlg | 14 +++----
l3trial/xbox/testfiles/xbox001.uptex.tlg | 18 +++------
l3trial/xbox/testfiles/xbox001.xetex.tlg | 14 +++----
l3trial/xbox/xbox.dtx | 61 ++++++++++---------------------
7 files changed, 46 insertions(+), 94 deletions(-)
diff --git a/l3trial/xbox/testfiles/xbox000.tlg b/l3trial/xbox/testfiles/xbox000.tlg
index 01d21e507..4bdabd02d 100644
--- a/l3trial/xbox/testfiles/xbox000.tlg
+++ b/l3trial/xbox/testfiles/xbox000.tlg
@@ -10,5 +10,6 @@ Package: xbox ....-..-.. L3 Experimental document level boxes
\l__xbox_totalheight_dim=\dimen...
\l__xbox_x_dim=\dimen...
\l__xbox_y_dim=\dimen...
+\g_xbox_lr_box=\box...
\l__hbox_internal_box=\box...
)
diff --git a/l3trial/xbox/testfiles/xbox001.luatex.tlg b/l3trial/xbox/testfiles/xbox001.luatex.tlg
index 74de6d7a4..ff88d0512 100644
--- a/l3trial/xbox/testfiles/xbox001.luatex.tlg
+++ b/l3trial/xbox/testfiles/xbox001.luatex.tlg
@@ -6,17 +6,17 @@ TEST 1: \newsavebox
============================================================
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"4E.
+> \myboxa=\char"4F.
<argument> \newsavebox {\myboxa }\show \myboxa
\begingroup \newsavebox {\myboxb }\show \my
l. ... }
Defining \myboxb on line ...
\myboxb=\box...
-> \myboxb=\char"4F.
+> \myboxb=\char"50.
<argument> ...begingroup \newsavebox {\myboxb }\show \myboxb
\endgroup \show \myboxb \n...
l. ... }
-> \myboxb=\char"4F.
+> \myboxb=\char"50.
<argument> ...\myboxb }\show \myboxb \endgroup \show \myboxb
\newsavebox {\myboxa }\sho...
l. ... }
@@ -28,10 +28,10 @@ This is a coding error.
LaTeX has been asked to create a new control sequence '\myboxa' but this name
has already been used elsewhere.
The current meaning is:
- \char"4E
+ \char"4F
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"50.
+> \myboxa=\char"51.
<argument> ...ow \myboxb \newsavebox {\myboxa }\show \myboxa
l. ... }
============================================================
@@ -567,7 +567,6 @@ TEST 7: lrbox
============================================================
> \box...=
\hbox(6.83331+0.0)x123.52777, direction TLT
-.\pdfcolorstack 0 push {0 g 0 G}
.\OT1/cmr/m/n/10 S
.\OT1/cmr/m/n/10 o
.\OT1/cmr/m/n/10 m
@@ -581,7 +580,6 @@ TEST 7: lrbox
.\glue(\spaceskip) 3.33333 plus 1.66666 minus 1.11111
.\glue(\spaceskip) 3.33333 plus 1.66666 minus 1.11111
.\hbox(6.83331+0.0)x69.19458, direction TLT
-..\pdfcolorstack 0 push {0 g 0 G}
..\OT1/cmr/m/n/10 S
..\OT1/cmr/m/n/10 o
..\OT1/cmr/m/n/10 m
@@ -596,8 +594,6 @@ TEST 7: lrbox
..\OT1/cmr/m/n/10 e
..\OT1/cmr/m/n/10 x
..\OT1/cmr/m/n/10 t
-..\pdfcolorstack 0 pop
-.\pdfcolorstack 0 pop
! OK.
<argument> \myboxa
l. ... }
diff --git a/l3trial/xbox/testfiles/xbox001.ptex.tlg b/l3trial/xbox/testfiles/xbox001.ptex.tlg
index 16da71a88..2dc56fe82 100644
--- a/l3trial/xbox/testfiles/xbox001.ptex.tlg
+++ b/l3trial/xbox/testfiles/xbox001.ptex.tlg
@@ -6,17 +6,17 @@ TEST 1: \newsavebox
============================================================
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"50.
+> \myboxa=\char"51.
<argument> \newsavebox {\myboxa }\show \myboxa
\begingroup \newsavebox {\myb...
l. ... }
Defining \myboxb on line ...
\myboxb=\box...
-> \myboxb=\char"51.
+> \myboxb=\char"52.
<argument> ...\newsavebox {\myboxb }\show \myboxb
\endgroup \show \myboxb \n...
l. ... }
-> \myboxb=\char"51.
+> \myboxb=\char"52.
<argument> ...how \myboxb \endgroup \show \myboxb
\newsavebox {\myboxa }\sho...
l. ... }
@@ -28,10 +28,10 @@ This is a coding error.
LaTeX has been asked to create a new control sequence '\myboxa' but this name
has already been used elsewhere.
The current meaning is:
- \char"50
+ \char"51
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"52.
+> \myboxa=\char"53.
<argument> ...\newsavebox {\myboxa }\show \myboxa
l. ... }
============================================================
@@ -607,9 +607,6 @@ TEST 7: lrbox
============================================================
> \box...=
\hbox(6.83331+0.0)x123.52777
-.\special{color push gray 0}
-.\special{ps:SDict begin /color.sc { } def end}
-.\special{ps:SDict begin /color.fc { } def end}
.\OT1/cmr/m/n/10 S
.\OT1/cmr/m/n/10 o
.\OT1/cmr/m/n/10 m
@@ -623,9 +620,6 @@ TEST 7: lrbox
.\glue 3.33333 plus 1.66666 minus 1.11111
.\glue 3.33333 plus 1.66666 minus 1.11111
.\hbox(6.83331+0.0)x69.19458
-..\special{color push gray 0}
-..\special{ps:SDict begin /color.sc { } def end}
-..\special{ps:SDict begin /color.fc { } def end}
..\OT1/cmr/m/n/10 S
..\OT1/cmr/m/n/10 o
..\OT1/cmr/m/n/10 m
@@ -640,8 +634,6 @@ TEST 7: lrbox
..\OT1/cmr/m/n/10 e
..\OT1/cmr/m/n/10 x
..\OT1/cmr/m/n/10 t
-..\special{color pop}
-.\special{color pop}
! OK.
<argument> \myboxa
l. ... }
diff --git a/l3trial/xbox/testfiles/xbox001.tlg b/l3trial/xbox/testfiles/xbox001.tlg
index fb7cb703f..9d46e250d 100644
--- a/l3trial/xbox/testfiles/xbox001.tlg
+++ b/l3trial/xbox/testfiles/xbox001.tlg
@@ -6,17 +6,17 @@ TEST 1: \newsavebox
============================================================
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"4E.
+> \myboxa=\char"4F.
<argument> \newsavebox {\myboxa }\show \myboxa
\begingroup \newsavebox {\myb...
l. ... }
Defining \myboxb on line ...
\myboxb=\box...
-> \myboxb=\char"4F.
+> \myboxb=\char"50.
<argument> ...\newsavebox {\myboxb }\show \myboxb
\endgroup \show \myboxb \n...
l. ... }
-> \myboxb=\char"4F.
+> \myboxb=\char"50.
<argument> ...how \myboxb \endgroup \show \myboxb
\newsavebox {\myboxa }\sho...
l. ... }
@@ -28,10 +28,10 @@ This is a coding error.
LaTeX has been asked to create a new control sequence '\myboxa' but this name
has already been used elsewhere.
The current meaning is:
- \char"4E
+ \char"4F
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"50.
+> \myboxa=\char"51.
<argument> ...\newsavebox {\myboxa }\show \myboxa
l. ... }
============================================================
@@ -563,7 +563,6 @@ TEST 7: lrbox
============================================================
> \box...=
\hbox(6.83331+0.0)x123.52777
-.\pdfcolorstack 0 push {0 g 0 G}
.\OT1/cmr/m/n/10 S
.\OT1/cmr/m/n/10 o
.\OT1/cmr/m/n/10 m
@@ -577,7 +576,6 @@ TEST 7: lrbox
.\glue 3.33333 plus 1.66666 minus 1.11111
.\glue 3.33333 plus 1.66666 minus 1.11111
.\hbox(6.83331+0.0)x69.19458
-..\pdfcolorstack 0 push {0 g 0 G}
..\OT1/cmr/m/n/10 S
..\OT1/cmr/m/n/10 o
..\OT1/cmr/m/n/10 m
@@ -592,8 +590,6 @@ TEST 7: lrbox
..\OT1/cmr/m/n/10 e
..\OT1/cmr/m/n/10 x
..\OT1/cmr/m/n/10 t
-..\pdfcolorstack 0 pop
-.\pdfcolorstack 0 pop
! OK.
<argument> \myboxa
l. ... }
diff --git a/l3trial/xbox/testfiles/xbox001.uptex.tlg b/l3trial/xbox/testfiles/xbox001.uptex.tlg
index 16da71a88..2dc56fe82 100644
--- a/l3trial/xbox/testfiles/xbox001.uptex.tlg
+++ b/l3trial/xbox/testfiles/xbox001.uptex.tlg
@@ -6,17 +6,17 @@ TEST 1: \newsavebox
============================================================
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"50.
+> \myboxa=\char"51.
<argument> \newsavebox {\myboxa }\show \myboxa
\begingroup \newsavebox {\myb...
l. ... }
Defining \myboxb on line ...
\myboxb=\box...
-> \myboxb=\char"51.
+> \myboxb=\char"52.
<argument> ...\newsavebox {\myboxb }\show \myboxb
\endgroup \show \myboxb \n...
l. ... }
-> \myboxb=\char"51.
+> \myboxb=\char"52.
<argument> ...how \myboxb \endgroup \show \myboxb
\newsavebox {\myboxa }\sho...
l. ... }
@@ -28,10 +28,10 @@ This is a coding error.
LaTeX has been asked to create a new control sequence '\myboxa' but this name
has already been used elsewhere.
The current meaning is:
- \char"50
+ \char"51
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"52.
+> \myboxa=\char"53.
<argument> ...\newsavebox {\myboxa }\show \myboxa
l. ... }
============================================================
@@ -607,9 +607,6 @@ TEST 7: lrbox
============================================================
> \box...=
\hbox(6.83331+0.0)x123.52777
-.\special{color push gray 0}
-.\special{ps:SDict begin /color.sc { } def end}
-.\special{ps:SDict begin /color.fc { } def end}
.\OT1/cmr/m/n/10 S
.\OT1/cmr/m/n/10 o
.\OT1/cmr/m/n/10 m
@@ -623,9 +620,6 @@ TEST 7: lrbox
.\glue 3.33333 plus 1.66666 minus 1.11111
.\glue 3.33333 plus 1.66666 minus 1.11111
.\hbox(6.83331+0.0)x69.19458
-..\special{color push gray 0}
-..\special{ps:SDict begin /color.sc { } def end}
-..\special{ps:SDict begin /color.fc { } def end}
..\OT1/cmr/m/n/10 S
..\OT1/cmr/m/n/10 o
..\OT1/cmr/m/n/10 m
@@ -640,8 +634,6 @@ TEST 7: lrbox
..\OT1/cmr/m/n/10 e
..\OT1/cmr/m/n/10 x
..\OT1/cmr/m/n/10 t
-..\special{color pop}
-.\special{color pop}
! OK.
<argument> \myboxa
l. ... }
diff --git a/l3trial/xbox/testfiles/xbox001.xetex.tlg b/l3trial/xbox/testfiles/xbox001.xetex.tlg
index 4c67f7a52..428ed986e 100644
--- a/l3trial/xbox/testfiles/xbox001.xetex.tlg
+++ b/l3trial/xbox/testfiles/xbox001.xetex.tlg
@@ -6,17 +6,17 @@ TEST 1: \newsavebox
============================================================
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"4E.
+> \myboxa=\char"4F.
<argument> \newsavebox {\myboxa }\show \myboxa
\begingroup \newsavebox {\myb...
l. ... }
Defining \myboxb on line ...
\myboxb=\box...
-> \myboxb=\char"4F.
+> \myboxb=\char"50.
<argument> ...\newsavebox {\myboxb }\show \myboxb
\endgroup \show \myboxb \n...
l. ... }
-> \myboxb=\char"4F.
+> \myboxb=\char"50.
<argument> ...how \myboxb \endgroup \show \myboxb
\newsavebox {\myboxa }\sho...
l. ... }
@@ -28,10 +28,10 @@ This is a coding error.
LaTeX has been asked to create a new control sequence '\myboxa' but this name
has already been used elsewhere.
The current meaning is:
- \char"4E
+ \char"4F
Defining \myboxa on line ...
\myboxa=\box...
-> \myboxa=\char"50.
+> \myboxa=\char"51.
<argument> ...\newsavebox {\myboxa }\show \myboxa
l. ... }
============================================================
@@ -563,7 +563,6 @@ TEST 7: lrbox
============================================================
> \box...=
\hbox(6.83331+0.0)x123.52777
-.\special{color push gray 0}
.\OT1/cmr/m/n/10 S
.\OT1/cmr/m/n/10 o
.\OT1/cmr/m/n/10 m
@@ -577,7 +576,6 @@ TEST 7: lrbox
.\glue 3.33333 plus 1.66666 minus 1.11111
.\glue 3.33333 plus 1.66666 minus 1.11111
.\hbox(6.83331+0.0)x69.19458
-..\special{color push gray 0}
..\OT1/cmr/m/n/10 S
..\OT1/cmr/m/n/10 o
..\OT1/cmr/m/n/10 m
@@ -592,8 +590,6 @@ TEST 7: lrbox
..\OT1/cmr/m/n/10 e
..\OT1/cmr/m/n/10 x
..\OT1/cmr/m/n/10 t
-..\special{color pop}
-.\special{color pop}
! OK.
<argument> \myboxa
l. ... }
diff --git a/l3trial/xbox/xbox.dtx b/l3trial/xbox/xbox.dtx
index 1eee452e2..5efb0974b 100644
--- a/l3trial/xbox/xbox.dtx
+++ b/l3trial/xbox/xbox.dtx
@@ -813,6 +813,12 @@
% These functions all involve boxing up material, then allowing adjustment
% of size based on \cs{height}, \cs{width}, \emph{etc.}
%
+% \begin{variable}{\g_xbox_lr_box}
+% \begin{macrocode}
+\box_new:N \g_xbox_lr_box
+% \end{macrocode}
+% \end{variable}
+%
% \begin{macro}{\xbox_to_wd:nnn}
% Typeset the material to measure it up, then re-box to the requested
% width and position.
@@ -1490,52 +1496,25 @@
% \end{macro}
%
% \begin{environment}{lrbox}
-% There are at least two potential approaches to dealing with the \env{lrbox}
-% environment. The \LaTeXe{} method is to use \tn{aftergroup} to insert
-% the closing |}| for the box \emph{after} the \tn{endgroup} inside
-% \cs{end}. That works well when using a \TeX{} box for the storage as there
-% is nothing to do after the |}|, but is not as convenient with a coffin as
-% the structures need to be set up. That means that to work that way the
-% code here would need to use internal details of the end-of-coffin
-% methods.
-%
-% The alternative method, used here, is to utilise some detail of the
-% environment system but to use only standard interfaces to the coffin
-% system. The code therefore escapes from the group set up by \cs{end} after
-% saving the name and start line of the environment using an \texttt{x}-type
-% expansion. The environment detail has to be set twice: once inside the
-% box doing the collection, and once for the \cs{end} function, as the
-% check for a matching environment takes place after the \TeX{} box is
-% closed. That means that the end-of-environment function has to be
-% redefined: doing it this way avoids needing any detail of the \pkg{xparse}
-% internals for an environment.
-%
-% This all looks a bit \enquote{programmatic} for use directly inside
-% an \pkg{xparse} argument, but it's very much tied to how \LaTeXe{}
-% environment syntax works and so this seems reasonable.
+% With the new hook system, an \texttt{lrbox} is trivial to create. The only
+% requirement is we put the hook change at the end of the environment to cover
+% the case where there is nesting.
% \begin{macrocode}
-\RenewDocumentEnvironment { lrbox } { m }
+\cs_if_exist:NT \AddToHook
{
- \use:x
+ \RenewDocumentEnvironment { lrbox } { m }
{
- \group_end:
- \hcoffin_set:Nw #1
- \cs_set:cpn { environment~lrbox~end }
- {
- \tex_unskip:D
- \hcoffin_set_end:
- \group_begin:
- \tl_set:Nn \exp_not:N \@currenvir { \@currenvir }
- \tl_set:Nn \exp_not:N \@currenvline { \on at line }
- }
- \tl_set:Nn \exp_not:N \@currenvir { \@currenvir }
- \tl_set:Nn \exp_not:N \@currenvline { \on at line }
- \cs_set_eq:Nc \exp_not:N \endlrbox { environment~lrbox~end }
- \exp_not:N \@endpefalse
+ \hbox_gset:Nw \g_xbox_lr_box
+ \@endpefalse
+ \tex_ignorespaces:D
+ }
+ {
+ \tex_unskip:D
+ \hbox_gset_end:
+ \AddToHookNext { env/lrbox/after }
+ { \hcoffin_set:Nn #1 { \hbox_unpack_drop:N \g_xbox_lr_box } }
}
- \tex_ignorespaces:D
}
- { }
% \end{macrocode}
% \end{environment}
%
More information about the latex3-commits
mailing list.