| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3draw-layers.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2019-2026 The LaTeX Project |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% http://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "l3experimental bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/latex3 |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
% |
| 25 |
%<*driver> |
| 26 |
\RequirePackage{expl3} |
| 27 |
\documentclass[full]{l3doc} |
| 28 |
\begin{document} |
| 29 |
\DocInput{\jobname.dtx} |
| 30 |
\end{document} |
| 31 |
%</driver> |
| 32 |
% \fi |
| 33 |
% |
| 34 |
% \title{^^A |
| 35 |
% The \pkg{l3draw-layers} package\\ Layers^^A |
| 36 |
% } |
| 37 |
% |
| 38 |
% \author{^^A |
| 39 |
% The \LaTeX{} Project\thanks |
| 40 |
% {^^A |
| 41 |
% E-mail: |
| 42 |
% \href{mailto:[email protected]} |
| 43 |
% {[email protected]}^^A |
| 44 |
% }^^A |
| 45 |
% } |
| 46 |
% |
| 47 |
% \date{Released 2026-05-26} |
| 48 |
% |
| 49 |
% \maketitle |
| 50 |
% |
| 51 |
% \begin{implementation} |
| 52 |
% |
| 53 |
% \section{\pkg{l3draw-layers} implementation} |
| 54 |
% |
| 55 |
% \begin{macrocode} |
| 56 |
%<*package> |
| 57 |
% \end{macrocode} |
| 58 |
% |
| 59 |
% \begin{macrocode} |
| 60 |
%<@@=draw> |
| 61 |
% \end{macrocode} |
| 62 |
% |
| 63 |
% \subsection{User interface} |
| 64 |
% |
| 65 |
% \begin{variable}{\l_@@_layer_tl} |
| 66 |
% The name of the current layer: we start off with |main|. |
| 67 |
% \begin{macrocode} |
| 68 |
\tl_new:N \l_@@_layer_tl |
| 69 |
\tl_set:Nn \l_@@_layer_tl { main } |
| 70 |
% \end{macrocode} |
| 71 |
% \end{variable} |
| 72 |
% |
| 73 |
% \begin{variable}{\l_@@_layer_close_bool} |
| 74 |
% Used to track if a layer needs to be closed. |
| 75 |
% \begin{macrocode} |
| 76 |
\bool_new:N \l_@@_layer_close_bool |
| 77 |
% \end{macrocode} |
| 78 |
% \end{variable} |
| 79 |
% |
| 80 |
% \begin{variable}{\l_draw_layers_clist, \g_@@_layers_clist} |
| 81 |
% The list of layers to use starts off with just the |main| one. |
| 82 |
% \begin{macrocode} |
| 83 |
\clist_new:N \l_draw_layers_clist |
| 84 |
\clist_set:Nn \l_draw_layers_clist { main } |
| 85 |
\clist_new:N \g_@@_layers_clist |
| 86 |
% \end{macrocode} |
| 87 |
% \end{variable} |
| 88 |
% |
| 89 |
% \begin{macro}{\draw_layer_begin:n, \@@_layer_begin:n} |
| 90 |
% \begin{macro}{\draw_layer_end:} |
| 91 |
% Layers may be called multiple times and have to work when nested. That |
| 92 |
% drives a bit of grouping to get everything in order. Layers have to be zero |
| 93 |
% width, so they get set as we go along. |
| 94 |
% \begin{macrocode} |
| 95 |
\cs_new_protected:Npn \draw_layer_begin:n #1 |
| 96 |
{ |
| 97 |
\clist_if_in:NnTF \l_draw_layers_clist {#1} |
| 98 |
{ |
| 99 |
\bool_lazy_or:nnF |
| 100 |
{ \str_if_eq_p:nn {#1} { main } } |
| 101 |
{ \box_if_exist_p:c { g_@@_layer_ #1 _box } } |
| 102 |
{ |
| 103 |
\box_new:c { g_@@_layer_ #1 _box } |
| 104 |
\box_new:c { l_@@_layer_ #1 _box } |
| 105 |
} |
| 106 |
\str_if_eq:nnTF {#1} { main } |
| 107 |
{ \msg_error:nnn { draw } { main-layer } } |
| 108 |
{ \@@_layer_begin:n {#1} } |
| 109 |
} |
| 110 |
{ |
| 111 |
\bool_lazy_any:nF |
| 112 |
{ |
| 113 |
{ \str_if_eq_p:nn {#1} { main } } |
| 114 |
{ \str_if_eq_p:nn {#1} { discard } } |
| 115 |
{ \box_if_exist_p:c { g_@@_layer_ #1 _box } } |
| 116 |
} |
| 117 |
{ \msg_error:nnn { draw } { unknown-layer } {#1} } |
| 118 |
} |
| 119 |
} |
| 120 |
\cs_new_protected:Npn \@@_layer_begin:n #1 |
| 121 |
{ |
| 122 |
\group_begin: |
| 123 |
\str_if_eq:VnTF \l_@@_layer_tl {#1} |
| 124 |
{ \bool_set_false:N \l_@@_layer_close_bool } |
| 125 |
{ |
| 126 |
\bool_set_true:N \l_@@_layer_close_bool |
| 127 |
\tl_set:Nn \l_@@_layer_tl {#1} |
| 128 |
\box_gset_wd:cn { g_@@_layer_ #1 _box } { 0pt } |
| 129 |
\hbox_gset:cw { g_@@_layer_ #1 _box } |
| 130 |
\box_use_drop:c { g_@@_layer_ #1 _box } |
| 131 |
\group_begin: |
| 132 |
} |
| 133 |
\draw_set_linewidth:n { \l_draw_default_linewidth_dim } |
| 134 |
} |
| 135 |
\cs_new_protected:Npn \draw_layer_end: |
| 136 |
{ |
| 137 |
\bool_if:NT \l_@@_layer_close_bool |
| 138 |
{ |
| 139 |
\group_end: |
| 140 |
\hbox_gset_end: |
| 141 |
} |
| 142 |
\group_end: |
| 143 |
} |
| 144 |
% \end{macrocode} |
| 145 |
% \end{macro} |
| 146 |
% \end{macro} |
| 147 |
% |
| 148 |
% \subsection{Internal cross-links} |
| 149 |
% |
| 150 |
% \begin{macro}{\@@_layers_insert:} |
| 151 |
% The |main| layer is special, otherwise just dump the layer box inside |
| 152 |
% a scope. |
| 153 |
% \begin{macrocode} |
| 154 |
\cs_new_protected:Npn \@@_layers_insert: |
| 155 |
{ |
| 156 |
\clist_map_inline:Nn \l_draw_layers_clist |
| 157 |
{ |
| 158 |
\str_if_eq:nnTF {##1} { main } |
| 159 |
{ |
| 160 |
\box_set_wd:Nn \l_@@_layer_main_box { 0pt } |
| 161 |
\box_use_drop:N \l_@@_layer_main_box |
| 162 |
} |
| 163 |
{ |
| 164 |
\@@_backend_scope_begin: |
| 165 |
\box_gset_wd:cn { g_@@_layer_ ##1 _box } { 0pt } |
| 166 |
\box_use_drop:c { g_@@_layer_ ##1 _box } |
| 167 |
\@@_backend_scope_end: |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
% \end{macrocode} |
| 172 |
% \end{macro} |
| 173 |
% |
| 174 |
% \begin{macro}{\@@_layers_save:, \@@_layers_restore:} |
| 175 |
% Simple save/restore functions. After creating a local copy of the |
| 176 |
% layer box, we must clear the global one so nested drawings do not |
| 177 |
% inherit the parent's layers. |
| 178 |
% \begin{macrocode} |
| 179 |
\cs_new_protected:Npn \@@_layers_save: |
| 180 |
{ |
| 181 |
\clist_map_inline:Nn \l_draw_layers_clist |
| 182 |
{ |
| 183 |
\str_if_eq:nnF {##1} { main } |
| 184 |
{ |
| 185 |
\box_set_eq:cc { l_@@_layer_ ##1 _box } |
| 186 |
{ g_@@_layer_ ##1 _box } |
| 187 |
\box_gclear:c { g_@@_layer_ ##1 _box } |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
\cs_new_protected:Npn \@@_layers_restore: |
| 192 |
{ |
| 193 |
\clist_map_inline:Nn \l_draw_layers_clist |
| 194 |
{ |
| 195 |
\str_if_eq:nnF {##1} { main } |
| 196 |
{ |
| 197 |
\box_gset_eq:cc { g_@@_layer_ ##1 _box } |
| 198 |
{ l_@@_layer_ ##1 _box } |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
% \end{macrocode} |
| 203 |
% \end{macro} |
| 204 |
% |
| 205 |
% \begin{macrocode} |
| 206 |
\msg_new:nnnn { draw } { main-layer } |
| 207 |
{ Material~cannot~be~added~to~'main'~layer. } |
| 208 |
{ The~main~layer~may~only~be~accessed~at~the~top~level. } |
| 209 |
\msg_new:nnn { draw } { main-reserved } |
| 210 |
{ The~'main'~layer~is~reserved. } |
| 211 |
\msg_new:nnnn { draw } { unknown-layer } |
| 212 |
{ Layer~'#1'~has~not~been~created. } |
| 213 |
{ You~have~tried~to~use~layer~'#1',~but~it~was~never~set~up. } |
| 214 |
% \end{macrocode} |
| 215 |
% |
| 216 |
% \begin{macrocode} |
| 217 |
%</package> |
| 218 |
% \end{macrocode} |
| 219 |
% |
| 220 |
% \end{implementation} |
| 221 |
% |
| 222 |
% \PrintIndex |