[latex3-commits] [l3svn] 03/04: Fix handling of cutouts if \par is in a group
noreply at latex-project.org
noreply at latex-project.org
Mon Jun 13 14:43:06 CEST 2016
This is an automated email from the git hooks/post-receive script.
joseph pushed a commit to branch master
in repository l3svn.
commit 01baf8faf4953694f784db211026791fa35361fd
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Mon Jun 13 13:40:24 2016 +0100
Fix handling of cutouts if \par is in a group
In a group, the removal of items from the tracking seq works
but once these are empty there was no trigger to reset
\parshape. As the common case is no shape to do, it is
desirable to avoid setting \parshape every time. The approach
now is to note that we can tell if we have reached the top
level of the galley (at which point we are OK), and until we
have to set the shape for every par after a cutout starts.
---
l3experimental/xgalley/l3galley.dtx | 73 ++++++++++++++++++++++++++---------
1 file changed, 55 insertions(+), 18 deletions(-)
diff --git a/l3experimental/xgalley/l3galley.dtx b/l3experimental/xgalley/l3galley.dtx
index 514ca4e..9c2a0d2 100644
--- a/l3experimental/xgalley/l3galley.dtx
+++ b/l3experimental/xgalley/l3galley.dtx
@@ -744,9 +744,16 @@
% Settings for application by the galley respect the usual \TeX{} grouping and
% so are all local variables.
%
+% \begin{variable}{\g_@@_cutout_active_bool, \g_@@_cutout_active_bool}
+% \begin{macrocode}
+\bool_new:N \g_@@_cutout_active_bool
+\bool_new:N \l_@@_cutout_active_bool
+% \end{macrocode}
+% \end{variable}
+%
% \begin{variable}
% {\l_@@_cutout_left_indent_seq, \l_@@_cutout_right_indent_seq}
-% Essentially scratch space, used when setting up a cutout in a paragrph,
+% Essentially scratch space, used when setting up a cutout in a paragraph,
% but named as there is quite a bit to do in that code.
% \begin{macrocode}
\seq_new:N \l_@@_cutout_left_indent_seq
@@ -982,6 +989,15 @@
% galley level must form a group: galley levels are tied to vertical
% boxes and so this is a reasonable requirements.
%
+% \begin{variable}{\l_@@_group_level_int}
+% The top group level for the galley needs to be known to allow
+% some data structures to be reset correctly: they can only be
+% fully cleared at the outer level.
+% \begin{macrocode}
+\int_new:N \l_@@_group_level_int
+% \end{macrocode}
+% \end{variable}
+%
% \begin{macro}{\@@_initialise_variables:}
% At the start of a galley level the global variables need to be reset to
% standard values. For example, the measure is set to the galley width and
@@ -989,7 +1005,9 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_initialise_variables:
{
+ \int_set:Nn \l_@@_group_level_int { \etex_currentgrouplevel:D }
\bool_gset_true:N \g_@@_begin_level_bool
+ \bool_gset_false:N \g_@@_cutout_active_bool
\seq_gclear:N \g_@@_cutout_left_seq
\seq_gclear:N \g_@@_cutout_right_seq
\tl_gclear:N \g_@@_interpar_penalty_user_tl
@@ -1035,6 +1053,8 @@
{
\bool_set_eq:NN \l_@@_begin_level_bool
\g_@@_begin_level_bool
+ \bool_set_eq:NN \l_@@_cutout_active_bool
+ \g_@@_cutout_active_bool
\seq_set_eq:NN \l_@@_cutout_left_seq
\g_@@_cutout_left_seq
\seq_set_eq:NN \l_@@_cutout_right_seq
@@ -1068,6 +1088,8 @@
{
\bool_gset_eq:NN \g_@@_begin_level_bool
\l_@@_begin_level_bool
+ \bool_gset_eq:NN \g_@@_cutout_active_bool
+ \l_@@_cutout_active_bool
\seq_gset_eq:NN \g_@@_cutout_left_seq
\l_@@_cutout_left_seq
\seq_gset_eq:NN \g_@@_cutout_right_seq
@@ -1144,7 +1166,7 @@
% \begin{macro}{\galley_par:}
% \begin{macro}[aux]{\@@_par_auxi:, \@@_par_auxii:, \@@_par_auxiii:}
% \begin{macro}[aux]{\@@_par_aux:N}
-% \begin{macro}[int]{\@@_par_set_cutout:, \@@_par_update_cutout:}
+% \begin{macro}[int]{\@@_par_update_cutout:}
% The idea here is to expand the next token in exactly the same way as \TeX{}
% would do anyway. The \texttt{f}-type expansion will ignore any protection,
% but will stop at a scan marker. Thus the code can test for an
@@ -1194,7 +1216,8 @@
% \begin{macrocode}
{
\g_galley_par_end_hook_tl
- \@@_par_set_cutout:
+ \bool_if:NT \g_@@_cutout_active_bool
+ { \@@_parshape_set: }
\group_begin:
\tex_par:D
\group_end:
@@ -1221,21 +1244,25 @@
\tex_penalty:D \c_ten_thousand
}
% \end{macrocode}
-% When cutouts are active, there is a need to set the paragraph shape
-% \enquote{just in time}. After the typesetting, the lines remaining in
-% the cutout has to be updated for the next run. This is all done for
-% each paragraph to avoid any grouping issues and without needing to set
-% \cs{tex_parshape:n} globally.
+% Once a cutout has been set, properly tidying up needs some work. The
+% cutout is applied \enquote{just in time} at the start of each paragraph
+% (see above). After the paragraph, the consumed lines are removed from
+% the tracking sequences and the paragraph shape is reset. The latter step
+% is required as we do not set the paragraph shape for every paragraph.
+% Once the two sequences are empty, there is no cutout to apply. However,
+% it can still be \enquote{active}. If a cutout is started then we have a
+% group, it is possible for the cutout to be entirely applied before the
+% end of the group. At that point, the two sequences show there is nothing
+% to do \emph{but} the active paragraph shape still has some lines indented.
+% As we avoid setting the \tn{parshape} primitive for every paragraph,
+% the result of only checking the sequences would be that the cutout would
+% reappear after the group! Instead, we use a boolean and only set it
+% false once the group level is that of the galley itself. (There is a slight
+% inefficiency here in that we thus do set the paragraph shape for each
+% paragraph after a cutout until we reach the top group level of the galley.
+% That should be an acceptable hit given the extra work needed to track
+% reset-in-this-group as well.)
% \begin{macrocode}
-\cs_new_protected:Npn \@@_par_set_cutout:
- {
- \bool_if:nF
- {
- \seq_if_empty_p:N \g_@@_cutout_left_seq
- && \seq_if_empty_p:N \g_@@_cutout_right_seq
- }
- { \@@_parshape_set: }
- }
\cs_new_protected:Npn \@@_par_update_cutout:
{
\bool_if:nF
@@ -1251,12 +1278,20 @@
}
\@@_parshape_set:
}
+ \int_compare:nNnT \l_@@_group_level_int = \etex_currentgrouplevel:D
+ {
+ \bool_if:nT
+ {
+ \seq_if_empty_p:N \g_@@_cutout_left_seq
+ && \seq_if_empty_p:N \g_@@_cutout_right_seq
+ }
+ { \bool_gset_false:N \g_@@_cutout_active_bool }
+ }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
-% \end{macro}
%
% \begin{macro}{\galley_par:n}
% Inserts tokens such that they are appended to the end of the last
@@ -1757,6 +1792,8 @@
{ \@@_cutout:Nc \g_@@_tmpa_seq { g_@@_cutout_ #1 _seq } }
\seq_gset_eq:cN { g_@@_cutout_ #1 _seq } \l_@@_tmp_seq
}
+ \seq_if_empty:cF { g_@@_cutout_ #1 _seq }
+ { \bool_gset_true:N \g_@@_cutout_active_bool }
}
\cs_new_protected:Npn \@@_cutout:NN #1#2
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the latex3-commits
mailing list