diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3experimental/xgalley/l3galley.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3experimental/xgalley/l3galley.dtx | 176 |
1 files changed, 102 insertions, 74 deletions
diff --git a/Master/texmf-dist/source/latex/l3experimental/xgalley/l3galley.dtx b/Master/texmf-dist/source/latex/l3experimental/xgalley/l3galley.dtx index a35de8f7643..70147a113d9 100644 --- a/Master/texmf-dist/source/latex/l3experimental/xgalley/l3galley.dtx +++ b/Master/texmf-dist/source/latex/l3experimental/xgalley/l3galley.dtx @@ -38,8 +38,8 @@ %<*driver|package> % The version of expl3 required is tested as early as possible, as % some really old versions do not define \ProvidesExplPackage. -\RequirePackage{expl3}[2016/05/14] -%<package>\@ifpackagelater{expl3}{2016/05/14} +\RequirePackage{expl3}[2016/10/19] +%<package>\@ifpackagelater{expl3}{2016/10/19} %<package> {} %<package> {% %<package> \PackageError{l3galley}{Support package l3kernel too old} @@ -51,7 +51,7 @@ %<package> }% %<package> \endinput %<package> } -\GetIdInfo$Id: l3galley.dtx 6493 2016-05-14 21:08:13Z joseph $ +\GetIdInfo$Id: l3galley.dtx 6730 2016-10-19 11:19:38Z joseph $ {L3 Experimental galley code} %</driver|package> %<*driver> @@ -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,14 +989,25 @@ % 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 % any paragraph shape is cleared. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_initialise_variables: +\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 @@ -1012,10 +1030,10 @@ % \begin{macro}{\@@_initialise_settings:} % This sets the local values of the various galley settings. The % flag \cs{l_@@_parshape_multipar_bool} is set \texttt{true} here -% as it allows an efficency saving in parshape setting: only +% as it allows an efficiency saving in parshape setting: only % when it is actively set \texttt{false} is action needed. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_initialise_settings: +\cs_new_protected:Npn \@@_initialise_settings: { \bool_set_true:N \l_@@_parshape_multipar_bool \seq_clear:N \l_@@_parshape_left_indent_seq @@ -1031,10 +1049,12 @@ % Saving and restoring parameters is carried out by a series of copy % functions. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_save_parameters: +\cs_new_protected:Npn \@@_save_parameters: { \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 @@ -1064,10 +1084,12 @@ \tl_set_eq:NN \l_@@_whatsit_next_tl \g_galley_whatsit_next_tl } -\cs_new_protected_nopar:Npn \@@_restore_parameters: +\cs_new_protected:Npn \@@_restore_parameters: { \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 @@ -1106,7 +1128,7 @@ % settings, starting a group then initialising both the local and global % variables. % \begin{macrocode} -\cs_new_protected_nopar:Npn \galley_level: +\cs_new_protected:Npn \galley_level: { \@@_save_parameters: \group_begin: @@ -1122,7 +1144,7 @@ % must come in a fixed location. All of this relies on the % \enquote{color safe} group used inside a box. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_level_end: +\cs_new_protected:Npn \@@_level_end: { \par \@@_restore_parameters: @@ -1144,13 +1166,13 @@ % \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 % \enquote{omit paragraph} marker. % \begin{macrocode} -\cs_new_protected_nopar:Npn \galley_par: +\cs_new_protected:Npn \galley_par: { \s__par_omit \exp_after:wN \@@_par_auxi: \exp:w \exp_end_continue_f:w @@ -1175,7 +1197,7 @@ % \cs{etex_interlinepenalties:D}). In vertical mode, that means just % inserting the primitive. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_par_auxii: +\cs_new_protected:Npn \@@_par_auxii: { \mode_if_vertical:TF { @@ -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,22 +1244,26 @@ \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. -% \begin{macrocode} -\cs_new_protected_nopar: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_nopar:Npn \@@_par_update_cutout: +% 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_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 @@ -1278,7 +1313,7 @@ % The meaning of the token \cs{par} itself starts off as a standard % paragraph. % \begin{macrocode} -\cs_set_protected_nopar:Npn \par { \galley_par: } +\cs_set_protected:Npn \par { \galley_par: } % \end{macrocode} % \end{macro} % @@ -1304,7 +1339,7 @@ % settings from the surrounding material. They may also start and end with % special spacing values. % \begin{macrocode} -\cs_new_protected_nopar:Npn \galley_display_begin: +\cs_new_protected:Npn \galley_display_begin: { \group_begin: \@@_save_parameters: @@ -1355,7 +1390,7 @@ % \cs{group_insert_after:N}. Resetting the meaning of the \cs{par} token % needs to be carried out after the group used for the environment. % \begin{macrocode} -\cs_new_protected_nopar:Npn \galley_display_end: +\cs_new_protected:Npn \galley_display_end: { \par \@@_restore_parameters: @@ -1369,7 +1404,7 @@ % \cs{par} token is then altered so that a check can be made to see if % this assumption was correct. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_display_par_setup: +\cs_new_protected:Npn \@@_display_par_setup: { \bool_gset_false:N \g_galley_omit_next_indent_bool \cs_set_eq:NN \par \@@_display_par: @@ -1388,7 +1423,7 @@ % cutout will have to be updated as it depends on the number of lines % \TeX{} has typeset. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_display_par: +\cs_new_protected:Npn \@@_display_par: { \cs_set_eq:NN \par \galley_par: \mode_if_vertical:TF @@ -1506,7 +1541,7 @@ % tidied up before sorting out any items which have been set on a % single-paragraph basis. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_start_paragraph_std: +\cs_new_protected:Npn \@@_start_paragraph_std: { \@@_start_paragraph_common:N \@@_insert_vertical_items: \@@_insert_horizontal_items: @@ -1523,7 +1558,7 @@ % must not add any vertical space as the start of the box unless there % is a user space to insert. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_start_paragraph_first: +\cs_new_protected:Npn \@@_start_paragraph_first: { \bool_gset_false:N \g_@@_begin_level_bool \mode_if_horizontal:TF @@ -1532,7 +1567,7 @@ \@@_insert_horizontal_items: \@@_restore_running_parameters: } -\cs_new_protected_nopar:Npn \@@_insert_vspace_first: +\cs_new_protected:Npn \@@_insert_vspace_first: { \tl_if_empty:NF \g_@@_interpar_vspace_user_tl { \skip_vertical:n { \g_@@_interpar_vspace_user_tl } } @@ -1553,7 +1588,7 @@ % the inter-paragraph space is applied: only one space is ever added % there. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_insert_vertical_items: +\cs_new_protected:Npn \@@_insert_vertical_items: { \g_galley_whatsit_previous_tl \tl_gclear:N \g_galley_whatsit_previous_tl @@ -1583,7 +1618,7 @@ % Horizontal mode objects start with the whatsits for the next paragraph. An % indent is then included if the removed box was not void. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_insert_horizontal_items: +\cs_new_protected:Npn \@@_insert_horizontal_items: { \g_galley_whatsit_next_tl \tl_gclear:N \g_galley_whatsit_next_tl @@ -1604,7 +1639,7 @@ % variable in which the appropriate assignments are stored. The % list can then be cleared. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_restore_running_parameters: +\cs_new_protected:Npn \@@_restore_running_parameters: { \g_galley_restore_running_tl \tl_gclear:N \g_galley_restore_running_tl @@ -1669,12 +1704,12 @@ % Setting the paragraph shape is mainly a question of converting the input. % First, though, a flag is set. % \begin{macrocode} -\cs_new_protected_nopar:Npn \galley_parshape_set_multi:nnnN +\cs_new_protected:Npn \galley_parshape_set_multi:nnnN { \bool_set_true:N \l_@@_parshape_multipar_bool \@@_parshape_set:nnnN } -\cs_new_protected_nopar:Npn \galley_parshape_set_single:nnnN +\cs_new_protected:Npn \galley_parshape_set_single:nnnN { \bool_set_false:N \l_@@_parshape_multipar_bool \@@_parshape_set:nnnN @@ -1725,9 +1760,9 @@ % the same idea with one or two very specific points of difference. As such, % the two interface functions both use the same implementation. % \begin{macrocode} -\cs_new_protected_nopar:Npn \galley_cutout_left:nn +\cs_new_protected:Npn \galley_cutout_left:nn { \@@_cutout:nnn { left } } -\cs_new_protected_nopar:Npn \galley_cutout_right:nn +\cs_new_protected:Npn \galley_cutout_right:nn { \@@_cutout:nnn { right } } % \end{macrocode} % The cutout information needs to be saved in in the appropriate sequence. @@ -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 { @@ -1796,31 +1833,19 @@ % code, the approach taken here is always to reset the entire shape. This % is done in three stages, one for each conceptual element. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_parshape_set: +\cs_new_protected:Npn \@@_parshape_set: { \@@_parshape_set_margins: \@@_parshape_set_indents: \@@_parshape_set_cutouts: - \tl_set:Nx \l_@@_tmp_tl - { - \__int_value:w \tex_parshape:D - \int_step_function:nnnN \c_one \c_one \tex_parshape:D - \tmp - } -% \tl_show:N \l_@@_tmp_tl } - \def\tmp#1{% - \c_space_tl - \__int_value:w \etex_parshapeindent:D #1 \c_space_tl \c_space_tl - \__int_value:w \etex_parshapelength:D #1 \c_space_tl - } % \end{macrocode} % Setting the margins is simple. Either they are zero, using the full measure, % or they are not. This is always set even if there are other elements to % apply as these settings are very fast, so it is not worth doing a check % at this stage for further parts to apply. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_parshape_set_margins: +\cs_new_protected:Npn \@@_parshape_set_margins: { \bool_if:nTF { @@ -1842,7 +1867,7 @@ % will always apply. The margins are reapplied at this stage as part of % the auxiliary for the calculation of indentation. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_parshape_set_indents: +\cs_new_protected:Npn \@@_parshape_set_indents: { \bool_if:nF { @@ -1878,12 +1903,12 @@ % temporary sequences so that they can safely be \enquote{chomped} by % \cs{@@_cutout:NN}. We then construct the overall list of indents required % and store them in dedicated temporary storage. That is necessary as to get -% the indents corret on both sides is to use a thread mapping. That also +% the indents correct on both sides is to use a thread mapping. That also % means that the two sequences need to be of the same length. That is % done by finding the length difference then applying an auxiliary to % the shorter sequence. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_parshape_set_cutouts: +\cs_new_protected:Npn \@@_parshape_set_cutouts: { \bool_if:nF { @@ -2363,7 +2388,7 @@ % so an \texttt{f}-type expansion is used to make life a little less % complex. % \begin{macrocode} -\cs_new_protected_nopar:Npn \@@_calc_interline_penalties: +\cs_new_protected:Npn \@@_calc_interline_penalties: { \exp_args:Nff \@@_calc_interline_penalties:nn { @@ -2466,7 +2491,10 @@ } } \cs_new:Npn \@@_save_display_widow_penalties:n #1 - { \__int_value:w \etex_displaywidowpenalties:D \__int_eval:w #1 \__int_eval_end: , } + { + \__int_value:w \etex_displaywidowpenalties:D + \__int_eval:w #1 \__int_eval_end: , + } \cs_new_protected:Npn \galley_save_widow_penalties:N #1 { \clist_set:Nx #1 @@ -2483,7 +2511,7 @@ % a simple conversion. The general interline penalty is always the % last value in the primitive array. % \begin{macrocode} -\cs_new_protected_nopar:Npn \galley_interline_penalty: +\cs_new_protected:Npn \galley_interline_penalty: { \__int_value:w \etex_interlinepenalties:D \etex_interlinepenalties:D \c_zero } % \end{macrocode} % \end{macro} @@ -2508,7 +2536,7 @@ % structures rather than directly onto the main vertical list. Other % than that it is the same as the \LaTeXe{} version. % \begin{macrocode} -\cs_set_nopar:Npn \clearpage +\cs_set:Npn \clearpage { \mode_if_vertical:T { @@ -2530,7 +2558,7 @@ % In package mode, some of \LaTeXe{}'s functions are re-implemented using % the galley system. Not all of the optional arguments currently work! % \begin{macrocode} -\cs_set_nopar:Npn \nobreak +\cs_set_protected:Npn \nobreak { \bool_gset_true:N \g_galley_no_break_next_bool } % \end{macrocode} % The \tn{noindent} primitive will causes problems, as it is used by @@ -2539,7 +2567,7 @@ % need leave vertical mode, at the moment we stick with the primitive as % well as setting the galley flag. % \begin{macrocode} -\cs_set_protected_nopar:Npn \noindent +\cs_set_protected:Npn \noindent { \tex_noindent:D \bool_gset_false:N \g_galley_omit_next_indent_bool @@ -2602,15 +2630,15 @@ % \begin{macro}{\addpenalty, \addvspace} % The mechanism here is entirely different, but at least this works! % \begin{macrocode} -\cs_set_nopar:Npn \addpenalty { \galley_penalty_add_single:n } -\cs_set_nopar:Npn \addvspace { \galley_vspace_max_single:n } +\cs_set_protected:Npn \addpenalty { \galley_penalty_add_single:n } +\cs_set_protected:Npn \addvspace { \galley_vspace_max_single:n } % \end{macrocode} %\end{macro} % % \begin{macro}{\@afterheading} % Set some flags and hope for the best! % \begin{macrocode} -\cs_set_nopar:Npn \@afterheading +\cs_set_protected:Npn \@afterheading { \bool_gset_true:N \g_galley_no_break_next_bool \if@afterindent @@ -2626,7 +2654,7 @@ % shape is set in a different way. As a result, the label is part of the % same paragraph as the main body, hence the need to leave vertical mode. % \begin{macrocode} -\cs_set:Npn \@hangfrom #1 +\cs_set_protected:Npn \@hangfrom #1 { \bool_gset_true:N \g_galley_omit_next_indent_bool \leavevmode |