| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3box.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2005-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 |
% https://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "l3kernel 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 |
\documentclass[full,kernel]{l3doc} |
| 27 |
\begin{document} |
| 28 |
\DocInput{\jobname.dtx} |
| 29 |
\end{document} |
| 30 |
%</driver> |
| 31 |
% \fi |
| 32 |
% |
| 33 |
% \title{^^A |
| 34 |
% The \pkg{l3box} module\\ Boxes^^A |
| 35 |
% } |
| 36 |
% |
| 37 |
% \author{^^A |
| 38 |
% The \LaTeX{} Project\thanks |
| 39 |
% {^^A |
| 40 |
% E-mail: |
| 41 |
% \href{mailto:[email protected]} |
| 42 |
% {[email protected]}^^A |
| 43 |
% }^^A |
| 44 |
% } |
| 45 |
% |
| 46 |
% \date{Released 2026-05-15} |
| 47 |
% |
| 48 |
% \maketitle |
| 49 |
% |
| 50 |
% \begin{documentation} |
| 51 |
% |
| 52 |
% Box variables contain typeset material that can be inserted on the |
| 53 |
% page or in other boxes. Their contents cannot be converted back to |
| 54 |
% lists of tokens. |
| 55 |
% There are three kinds of box operations: horizontal mode denoted |
| 56 |
% with prefix |\hbox_|, vertical mode with prefix |\vbox_|, and the |
| 57 |
% generic operations working in both modes with prefix |\box_|. |
| 58 |
% For instance, a new box variable containing the words \enquote{Hello, |
| 59 |
% world!} (in a horizontal box) can be obtained by the following code. |
| 60 |
% \begin{verbatim} |
| 61 |
% \box_new:N \l_hello_box |
| 62 |
% \hbox_set:Nn \l_hello_box { Hello, ~ world! } |
| 63 |
% \end{verbatim} |
| 64 |
% The argument is typeset inside a \TeX{} group so that any variables |
| 65 |
% assigned during the construction of this box restores its value |
| 66 |
% afterwards. |
| 67 |
% |
| 68 |
% Box variables from \pkg{l3box} are compatible with those of \LaTeXe{} |
| 69 |
% and plain \TeX{} and can be used interchangeably. The \pkg{l3box} |
| 70 |
% commands to construct boxes, such as \cs{hbox:n} or \cs{hbox_set:Nn}, |
| 71 |
% are \enquote{color-safe}, meaning that |
| 72 |
% \begin{verbatim} |
| 73 |
% \hbox:n { \color_select:n { blue } Hello, } ~ world! |
| 74 |
% \end{verbatim} |
| 75 |
% will result in \enquote{Hello,} taking the color blue, but |
| 76 |
% \enquote{world!} remaining with the prevailing color outside the box. |
| 77 |
% |
| 78 |
% \section{Creating and initializing boxes} |
| 79 |
% |
| 80 |
% \begin{function}{\box_new:N, \box_new:c} |
| 81 |
% \begin{syntax} |
| 82 |
% \cs{box_new:N} \meta{box} |
| 83 |
% \end{syntax} |
| 84 |
% Creates a new \meta{box} or raises an error if the name is |
| 85 |
% already taken. The declaration is global. The \meta{box} is |
| 86 |
% initially void. |
| 87 |
% \end{function} |
| 88 |
% |
| 89 |
% \begin{function}{\box_clear:N, \box_clear:c, \box_gclear:N, \box_gclear:c} |
| 90 |
% \begin{syntax} |
| 91 |
% \cs{box_clear:N} \meta{box} |
| 92 |
% \end{syntax} |
| 93 |
% Clears the content of the \meta{box} by setting the box equal to |
| 94 |
% \cs{c_empty_box}. |
| 95 |
% \end{function} |
| 96 |
% |
| 97 |
% \begin{function} |
| 98 |
% {\box_clear_new:N, \box_clear_new:c, \box_gclear_new:N, \box_gclear_new:c} |
| 99 |
% \begin{syntax} |
| 100 |
% \cs{box_clear_new:N} \meta{box} |
| 101 |
% \end{syntax} |
| 102 |
% Ensures that the \meta{box} exists globally by applying |
| 103 |
% \cs{box_new:N} if necessary, then applies |
| 104 |
% \cs[index=box_clear:N]{box_(g)clear:N} to leave |
| 105 |
% the \meta{box} empty. |
| 106 |
% \end{function} |
| 107 |
% |
| 108 |
% \begin{function} |
| 109 |
% { |
| 110 |
% \box_set_eq:NN, \box_set_eq:cN, \box_set_eq:Nc, \box_set_eq:cc, |
| 111 |
% \box_gset_eq:NN, \box_gset_eq:cN, \box_gset_eq:Nc, \box_gset_eq:cc |
| 112 |
% } |
| 113 |
% \begin{syntax} |
| 114 |
% \cs{box_set_eq:NN} \meta{box_1} \meta{box_2} |
| 115 |
% \end{syntax} |
| 116 |
% Sets the content of \meta{box_1} equal to that of \meta{box_2}. |
| 117 |
% \end{function} |
| 118 |
% |
| 119 |
% \begin{function}[EXP, pTF, added=2012-03-03] |
| 120 |
% {\box_if_exist:N, \box_if_exist:c} |
| 121 |
% \begin{syntax} |
| 122 |
% \cs{box_if_exist_p:N} \meta{box} |
| 123 |
% \cs{box_if_exist:NTF} \meta{box} \Arg{true code} \Arg{false code} |
| 124 |
% \end{syntax} |
| 125 |
% Tests whether the \meta{box} is currently defined. This does not |
| 126 |
% check that the \meta{box} really is a box. |
| 127 |
% \end{function} |
| 128 |
% |
| 129 |
% \section{Using boxes} |
| 130 |
% |
| 131 |
% \begin{function}{\box_use:N, \box_use:c} |
| 132 |
% \begin{syntax} |
| 133 |
% \cs{box_use:N} \meta{box} |
| 134 |
% \end{syntax} |
| 135 |
% Inserts the current content of the \meta{box} onto the current |
| 136 |
% list for typesetting. An error is raised if the variable does |
| 137 |
% not exist or if it is invalid. |
| 138 |
% \begin{texnote} |
| 139 |
% This is the \TeX{} primitive \tn{copy}. |
| 140 |
% \end{texnote} |
| 141 |
% \end{function} |
| 142 |
% |
| 143 |
% \begin{function}{\box_move_right:nn, \box_move_left:nn} |
| 144 |
% \begin{syntax} |
| 145 |
% \cs{box_move_right:nn} \Arg{dim expr} \Arg{box function} |
| 146 |
% \end{syntax} |
| 147 |
% This function operates in vertical mode, and inserts the |
| 148 |
% material specified by the \meta{box function} |
| 149 |
% such that its reference point is displaced horizontally by the given |
| 150 |
% \meta{dim expr} from the reference point for typesetting, to the right |
| 151 |
% or left as appropriate. The \meta{box function} should be |
| 152 |
% a box operation such as \cs{box_use:N} |\<box>| or a \enquote{raw} |
| 153 |
% box specification such as \cs{vbox:n} |{ xyz }|. |
| 154 |
% \end{function} |
| 155 |
% |
| 156 |
% \begin{function}{\box_move_up:nn, \box_move_down:nn} |
| 157 |
% \begin{syntax} |
| 158 |
% \cs{box_move_up:nn} \Arg{dim expr} \Arg{box function} |
| 159 |
% \end{syntax} |
| 160 |
% This function operates in horizontal mode, and inserts the |
| 161 |
% material specified by the \meta{box function} |
| 162 |
% such that its reference point is displaced vertically by the given |
| 163 |
% \meta{dim expr} from the reference point for typesetting, up |
| 164 |
% or down as appropriate. The \meta{box function} should be |
| 165 |
% a box operation such as \cs{box_use:N} |\<box>| or a \enquote{raw} |
| 166 |
% box specification such as \cs{vbox:n} |{ xyz }|. |
| 167 |
% \end{function} |
| 168 |
% |
| 169 |
% \section{Measuring and setting box dimensions} |
| 170 |
% |
| 171 |
% \begin{function}{\box_dp:N, \box_dp:c} |
| 172 |
% \begin{syntax} |
| 173 |
% \cs{box_dp:N} \meta{box} |
| 174 |
% \end{syntax} |
| 175 |
% Calculates the depth (below the baseline) of the \meta{box} |
| 176 |
% in a form suitable for use in a \meta{dim expr}. |
| 177 |
% \begin{texnote} |
| 178 |
% This is the \TeX{} primitive \tn{dp}. |
| 179 |
% \end{texnote} |
| 180 |
% \end{function} |
| 181 |
% |
| 182 |
% \begin{function}{\box_ht:N, \box_ht:c} |
| 183 |
% \begin{syntax} |
| 184 |
% \cs{box_ht:N} \meta{box} |
| 185 |
% \end{syntax} |
| 186 |
% Calculates the height (above the baseline) of the \meta{box} |
| 187 |
% in a form suitable for use in a \meta{dim expr}. |
| 188 |
% \begin{texnote} |
| 189 |
% This is the \TeX{} primitive \tn{ht}. |
| 190 |
% \end{texnote} |
| 191 |
% \end{function} |
| 192 |
% |
| 193 |
% \begin{function}{\box_wd:N, \box_wd:c} |
| 194 |
% \begin{syntax} |
| 195 |
% \cs{box_wd:N} \meta{box} |
| 196 |
% \end{syntax} |
| 197 |
% Calculates the width of the \meta{box} in a form |
| 198 |
% suitable for use in a \meta{dim expr}. |
| 199 |
% \begin{texnote} |
| 200 |
% This is the \TeX{} primitive \tn{wd}. |
| 201 |
% \end{texnote} |
| 202 |
% \end{function} |
| 203 |
% |
| 204 |
% \begin{function}[added = 2021-05-05]{\box_ht_plus_dp:N, \box_ht_plus_dp:c} |
| 205 |
% \begin{syntax} |
| 206 |
% \cs{box_ht_plus_dp:N} \meta{box} |
| 207 |
% \end{syntax} |
| 208 |
% Calculates the total vertical size (height plus depth) of the \meta{box} |
| 209 |
% in a form suitable for use in a \meta{dim expr}. |
| 210 |
% \end{function} |
| 211 |
% |
| 212 |
% \begin{function}[updated = 2019-01-22] |
| 213 |
% { |
| 214 |
% \box_set_dp:Nn, \box_set_dp:cn, |
| 215 |
% \box_gset_dp:Nn, \box_gset_dp:cn |
| 216 |
% } |
| 217 |
% \begin{syntax} |
| 218 |
% \cs{box_set_dp:Nn} \meta{box} \Arg{dim expr} |
| 219 |
% \end{syntax} |
| 220 |
% Set the depth (below the baseline) of the \meta{box} to the value of |
| 221 |
% the \Arg{dim expr}. |
| 222 |
% \end{function} |
| 223 |
% |
| 224 |
% \begin{function}[updated = 2019-01-22] |
| 225 |
% { |
| 226 |
% \box_set_ht:Nn, \box_set_ht:cn, |
| 227 |
% \box_gset_ht:Nn, \box_gset_ht:cn |
| 228 |
% } |
| 229 |
% \begin{syntax} |
| 230 |
% \cs{box_set_ht:Nn} \meta{box} \Arg{dim expr} |
| 231 |
% \end{syntax} |
| 232 |
% Set the height (above the baseline) of the \meta{box} to the value of |
| 233 |
% the \Arg{dim expr}. |
| 234 |
% \end{function} |
| 235 |
% |
| 236 |
% \begin{function}[updated = 2019-01-22] |
| 237 |
% { |
| 238 |
% \box_set_wd:Nn, \box_set_wd:cn, |
| 239 |
% \box_gset_wd:Nn, \box_gset_wd:cn |
| 240 |
% } |
| 241 |
% \begin{syntax} |
| 242 |
% \cs{box_set_wd:Nn} \meta{box} \Arg{dim expr} |
| 243 |
% \end{syntax} |
| 244 |
% Set the width of the \meta{box} to the value of the |
| 245 |
% \Arg{dim expr}. |
| 246 |
% \end{function} |
| 247 |
% |
| 248 |
% \section{Box conditionals} |
| 249 |
% |
| 250 |
% \begin{function}[EXP,pTF]{\box_if_empty:N, \box_if_empty:c} |
| 251 |
% \begin{syntax} |
| 252 |
% \cs{box_if_empty_p:N} \meta{box} |
| 253 |
% \cs{box_if_empty:NTF} \meta{box} \Arg{true code} \Arg{false code} |
| 254 |
% \end{syntax} |
| 255 |
% Tests if \meta{box} is a empty (equal to \cs{c_empty_box}). |
| 256 |
% \end{function} |
| 257 |
% |
| 258 |
% \begin{function}[EXP,pTF]{\box_if_horizontal:N, \box_if_horizontal:c} |
| 259 |
% \begin{syntax} |
| 260 |
% \cs{box_if_horizontal_p:N} \meta{box} |
| 261 |
% \cs{box_if_horizontal:NTF} \meta{box} \Arg{true code} \Arg{false code} |
| 262 |
% \end{syntax} |
| 263 |
% Tests if \meta{box} is a horizontal box. |
| 264 |
% \end{function} |
| 265 |
% |
| 266 |
% \begin{function}[EXP,pTF]{\box_if_vertical:N, \box_if_vertical:c} |
| 267 |
% \begin{syntax} |
| 268 |
% \cs{box_if_vertical_p:N} \meta{box} |
| 269 |
% \cs{box_if_vertical:NTF} \meta{box} \Arg{true code} \Arg{false code} |
| 270 |
% \end{syntax} |
| 271 |
% Tests if \meta{box} is a vertical box. |
| 272 |
% \end{function} |
| 273 |
% |
| 274 |
% \section{The last box inserted} |
| 275 |
% |
| 276 |
% \begin{function} |
| 277 |
% { |
| 278 |
% \box_set_to_last:N, \box_set_to_last:c, |
| 279 |
% \box_gset_to_last:N, \box_gset_to_last:c |
| 280 |
% } |
| 281 |
% \begin{syntax} |
| 282 |
% \cs{box_set_to_last:N} \meta{box} |
| 283 |
% \end{syntax} |
| 284 |
% Sets the \meta{box} equal to the last item (box) added to the current |
| 285 |
% partial list, removing the item from the list at the same time. When |
| 286 |
% applied to the main vertical list, the \meta{box} is always void as |
| 287 |
% it is not possible to recover the last added item. |
| 288 |
% \end{function} |
| 289 |
% |
| 290 |
% \section{Constant boxes} |
| 291 |
% |
| 292 |
% \begin{variable}[updated = 2012-11-04]{\c_empty_box} |
| 293 |
% This is a permanently empty box, which is neither set as horizontal |
| 294 |
% nor vertical. |
| 295 |
% \begin{texnote} |
| 296 |
% At the \TeX{} level this is a void box. |
| 297 |
% \end{texnote} |
| 298 |
% \end{variable} |
| 299 |
% |
| 300 |
% \section{Scratch boxes} |
| 301 |
% |
| 302 |
% \begin{variable}[updated = 2012-11-04]{\l_tmpa_box, \l_tmpb_box} |
| 303 |
% Scratch boxes for local assignment. These are never used by |
| 304 |
% the kernel code, and so are safe for use with any \LaTeX3-defined |
| 305 |
% function. However, they may be overwritten by other non-kernel |
| 306 |
% code and so should only be used for short-term storage. |
| 307 |
% \end{variable} |
| 308 |
% |
| 309 |
% \begin{variable}{\g_tmpa_box, \g_tmpb_box} |
| 310 |
% Scratch boxes for global assignment. These are never used by |
| 311 |
% the kernel code, and so are safe for use with any \LaTeX3-defined |
| 312 |
% function. However, they may be overwritten by other non-kernel |
| 313 |
% code and so should only be used for short-term storage. |
| 314 |
% \end{variable} |
| 315 |
% |
| 316 |
% \section{Viewing box contents} |
| 317 |
% |
| 318 |
% \begin{function}[updated = 2012-05-11]{\box_show:N, \box_show:c} |
| 319 |
% \begin{syntax} |
| 320 |
% \cs{box_show:N} \meta{box} |
| 321 |
% \end{syntax} |
| 322 |
% Shows full details of the content of the \meta{box} in the terminal. |
| 323 |
% \end{function} |
| 324 |
% |
| 325 |
% \begin{function}[added = 2012-05-11]{\box_show:Nnn, \box_show:cnn} |
| 326 |
% \begin{syntax} |
| 327 |
% \cs{box_show:Nnn} \meta{box} \Arg{int expr_1} \Arg{int expr_2} |
| 328 |
% \end{syntax} |
| 329 |
% Display the contents of \meta{box} in the terminal, showing the first |
| 330 |
% \meta{int expr_1} items of the box, and descending into \meta{int expr_2} |
| 331 |
% group levels. |
| 332 |
% \end{function} |
| 333 |
% |
| 334 |
% \begin{function}[added = 2012-05-11]{\box_log:N, \box_log:c} |
| 335 |
% \begin{syntax} |
| 336 |
% \cs{box_log:N} \meta{box} |
| 337 |
% \end{syntax} |
| 338 |
% Writes full details of the content of the \meta{box} to the log. |
| 339 |
% \end{function} |
| 340 |
% |
| 341 |
% \begin{function}[added = 2012-05-11]{\box_log:Nnn, \box_log:cnn} |
| 342 |
% \begin{syntax} |
| 343 |
% \cs{box_log:Nnn} \meta{box} \Arg{int expr_1} \Arg{int expr_2} |
| 344 |
% \end{syntax} |
| 345 |
% Writes the contents of \meta{box} to the log, showing the first |
| 346 |
% \meta{int expr_1} items of the box, and descending into \meta{int expr_2} |
| 347 |
% group levels. |
| 348 |
% \end{function} |
| 349 |
% |
| 350 |
% \section{Boxes and color} |
| 351 |
% |
| 352 |
% All \LaTeX{}3 boxes are \enquote{color safe}: a color set inside the box |
| 353 |
% stops applying after the end of the box has occurred. |
| 354 |
% |
| 355 |
% \section{Horizontal mode boxes} |
| 356 |
% |
| 357 |
% \begin{function}[updated = 2017-04-05]{\hbox:n} |
| 358 |
% \begin{syntax} |
| 359 |
% \cs{hbox:n} \Arg{contents} |
| 360 |
% \end{syntax} |
| 361 |
% Typesets the \meta{contents} into a horizontal box of natural |
| 362 |
% width and then includes this box in the current list for typesetting. |
| 363 |
% \end{function} |
| 364 |
% |
| 365 |
% \begin{function}[updated = 2017-04-05]{\hbox_to_wd:nn} |
| 366 |
% \begin{syntax} |
| 367 |
% \cs{hbox_to_wd:nn} \Arg{dim expr} \Arg{contents} |
| 368 |
% \end{syntax} |
| 369 |
% Typesets the \meta{contents} into a horizontal box of width |
| 370 |
% \meta{dim expr} and then includes this box in the current list for |
| 371 |
% typesetting. |
| 372 |
% \end{function} |
| 373 |
% |
| 374 |
% \begin{function}[updated = 2017-04-05]{\hbox_to_zero:n} |
| 375 |
% \begin{syntax} |
| 376 |
% \cs{hbox_to_zero:n} \Arg{contents} |
| 377 |
% \end{syntax} |
| 378 |
% Typesets the \meta{contents} into a horizontal box of zero width |
| 379 |
% and then includes this box in the current list for typesetting. |
| 380 |
% \end{function} |
| 381 |
% |
| 382 |
% \begin{function}[updated = 2017-04-05] |
| 383 |
% {\hbox_set:Nn, \hbox_set:cn, \hbox_gset:Nn, \hbox_gset:cn} |
| 384 |
% \begin{syntax} |
| 385 |
% \cs{hbox_set:Nn} \meta{box} \Arg{contents} |
| 386 |
% \end{syntax} |
| 387 |
% Typesets the \meta{contents} at natural width and then stores the |
| 388 |
% result inside the \meta{box}. |
| 389 |
% \end{function} |
| 390 |
% |
| 391 |
% \begin{function}[updated = 2017-04-05] |
| 392 |
% { |
| 393 |
% \hbox_set_to_wd:Nnn, \hbox_set_to_wd:cnn, |
| 394 |
% \hbox_gset_to_wd:Nnn, \hbox_gset_to_wd:cnn |
| 395 |
% } |
| 396 |
% \begin{syntax} |
| 397 |
% \cs{hbox_set_to_wd:Nnn} \meta{box} \Arg{dim expr} \Arg{contents} |
| 398 |
% \end{syntax} |
| 399 |
% Typesets the \meta{contents} to the width given by the \meta{dim expr} |
| 400 |
% and then stores the result inside the \meta{box}. |
| 401 |
% \end{function} |
| 402 |
% |
| 403 |
% \begin{function}[added = 2020-08-25]{\hbox_overlap_center:n} |
| 404 |
% \begin{syntax} |
| 405 |
% \cs{hbox_overlap_center:n} \Arg{contents} |
| 406 |
% \end{syntax} |
| 407 |
% Typesets the \meta{contents} into a horizontal box of zero width |
| 408 |
% such that material protrudes equally to both sides of the insertion point. |
| 409 |
% \end{function} |
| 410 |
% |
| 411 |
% \begin{function}[updated = 2017-04-05]{\hbox_overlap_right:n} |
| 412 |
% \begin{syntax} |
| 413 |
% \cs{hbox_overlap_right:n} \Arg{contents} |
| 414 |
% \end{syntax} |
| 415 |
% Typesets the \meta{contents} into a horizontal box of zero width |
| 416 |
% such that material protrudes to the right of the insertion point. |
| 417 |
% \end{function} |
| 418 |
% |
| 419 |
% \begin{function}[updated = 2017-04-05]{\hbox_overlap_left:n} |
| 420 |
% \begin{syntax} |
| 421 |
% \cs{hbox_overlap_left:n} \Arg{contents} |
| 422 |
% \end{syntax} |
| 423 |
% Typesets the \meta{contents} into a horizontal box of zero width |
| 424 |
% such that material protrudes to the left of the insertion point. |
| 425 |
% \end{function} |
| 426 |
% |
| 427 |
% \begin{function}[updated = 2017-04-05] |
| 428 |
% { |
| 429 |
% \hbox_set:Nw, \hbox_set:cw, |
| 430 |
% \hbox_set_end:, |
| 431 |
% \hbox_gset:Nw, \hbox_gset:cw, |
| 432 |
% \hbox_gset_end: |
| 433 |
% } |
| 434 |
% \begin{syntax} |
| 435 |
% \cs{hbox_set:Nw} \meta{box} \meta{contents} \cs{hbox_set_end:} |
| 436 |
% \end{syntax} |
| 437 |
% Typesets the \meta{contents} at natural width and then stores the |
| 438 |
% result inside the \meta{box}. In contrast |
| 439 |
% to \cs{hbox_set:Nn} this function does not absorb the argument |
| 440 |
% when finding the \meta{content}, and so can be used in circumstances |
| 441 |
% where the \meta{content} may not be a simple argument. |
| 442 |
% \end{function} |
| 443 |
% |
| 444 |
% \begin{function}[added = 2017-06-08] |
| 445 |
% { |
| 446 |
% \hbox_set_to_wd:Nnw, \hbox_set_to_wd:cnw, |
| 447 |
% \hbox_gset_to_wd:Nnw, \hbox_gset_to_wd:cnw |
| 448 |
% } |
| 449 |
% \begin{syntax} |
| 450 |
% \cs{hbox_set_to_wd:Nnw} \meta{box} \Arg{dim expr} \meta{contents} \cs{hbox_set_end:} |
| 451 |
% \end{syntax} |
| 452 |
% Typesets the \meta{contents} to the width given by the \meta{dim expr} |
| 453 |
% and then stores the result inside the \meta{box}. In contrast |
| 454 |
% to \cs{hbox_set_to_wd:Nnn} this function does not absorb the argument |
| 455 |
% when finding the \meta{content}, and so can be used in circumstances |
| 456 |
% where the \meta{content} may not be a simple argument. |
| 457 |
% \end{function} |
| 458 |
% |
| 459 |
% \begin{function}{\hbox_unpack:N, \hbox_unpack:c} |
| 460 |
% \begin{syntax} |
| 461 |
% \cs{hbox_unpack:N} \meta{box} |
| 462 |
% \end{syntax} |
| 463 |
% Unpacks the content of the horizontal \meta{box}, retaining any stretching |
| 464 |
% or shrinking applied when the \meta{box} was set. |
| 465 |
% \begin{texnote} |
| 466 |
% This is the \TeX{} primitive \tn{unhcopy}. |
| 467 |
% \end{texnote} |
| 468 |
% \end{function} |
| 469 |
% |
| 470 |
% \section{Vertical mode boxes} |
| 471 |
% |
| 472 |
% Vertical boxes inherit their baseline from their contents. The |
| 473 |
% standard case is that the baseline of the box is at the same position |
| 474 |
% as that of the last item added to the box. This means that the box |
| 475 |
% has no depth unless the last item added to it had depth. As a |
| 476 |
% result most vertical boxes have a large height value and small or |
| 477 |
% zero depth. The exception are |_top| boxes, where the reference point |
| 478 |
% is that of the first item added. These tend to have a large depth and |
| 479 |
% small height, although the latter is typically non-zero. |
| 480 |
% |
| 481 |
% \begin{function}[updated = 2017-04-05]{\vbox:n} |
| 482 |
% \begin{syntax} |
| 483 |
% \cs{vbox:n} \Arg{contents} |
| 484 |
% \end{syntax} |
| 485 |
% Typesets the \meta{contents} into a vertical box of natural height |
| 486 |
% and includes this box in the current list for typesetting. |
| 487 |
% \end{function} |
| 488 |
% |
| 489 |
% \begin{function}[updated = 2017-04-05]{\vbox_top:n} |
| 490 |
% \begin{syntax} |
| 491 |
% \cs{vbox_top:n} \Arg{contents} |
| 492 |
% \end{syntax} |
| 493 |
% Typesets the \meta{contents} into a vertical box of natural height |
| 494 |
% and includes this box in the current list for typesetting. The |
| 495 |
% vertical position of reference point of the box is equal to the |
| 496 |
% baseline of the \emph{first} item added to the box. |
| 497 |
% \end{function} |
| 498 |
% |
| 499 |
% \begin{function}[added = 2026-02-17]{\vbox_center:n} |
| 500 |
% \begin{syntax} |
| 501 |
% \cs{vbox_center:n} \Arg{contents} |
| 502 |
% \end{syntax} |
| 503 |
% Typesets the \meta{contents} into a vertical box of natural height |
| 504 |
% and includes this box in the current list for typesetting. The |
| 505 |
% vertical position of reference point of the box is at the vertical |
| 506 |
% midpoint of content of the box. |
| 507 |
% \end{function} |
| 508 |
% |
| 509 |
% \begin{function}[added = 2026-02-25]{\vbox:w, \vbox_top:w, \vbox_center:w, \vbox_end:} |
| 510 |
% \begin{syntax} |
| 511 |
% \cs{vbox:w} |
| 512 |
% \meta{contents} |
| 513 |
% \cs{vbox_end:} |
| 514 |
% \end{syntax} |
| 515 |
% Typesets the \meta{contents} into a vertical box of natural height |
| 516 |
% and includes this box in the current list for typesetting. The reference |
| 517 |
% of the box is determined as for the matching |:n| function. |
| 518 |
% \end{function} |
| 519 |
% |
| 520 |
% \begin{function}[added = 2026-02-17, updated = 2026-02-24] |
| 521 |
% {\vbox:nn, \vbox_top:nn, \vbox_center:nn} |
| 522 |
% \begin{syntax} |
| 523 |
% \cs{vbox_center:nn} \Arg{offset} \Arg{contents} |
| 524 |
% \end{syntax} |
| 525 |
% Typesets the \meta{contents} into a vertical box of natural height |
| 526 |
% and includes this box in the current list for typesetting. The reference |
| 527 |
% of the box is determined as for the matching |:n| function. The box |
| 528 |
% is then displaced vertically by the \meta{offset} (a \meta{dim expr}) |
| 529 |
% from existing baseline. |
| 530 |
% \begin{texnote} |
| 531 |
% If the \meta{offset} makes use of math font dimensions, these |
| 532 |
% should be correctly initialized. In \LaTeX{}, this would be achieved |
| 533 |
% by applying \tn{check@mathfonts} immediately before using the |
| 534 |
% functions. If the \meta{offset} is the math axis |
| 535 |
% (|\fontdimen22\textfont2|), the dimensions of the resulting box will |
| 536 |
% be identical to those from \tn{vcenter}. |
| 537 |
% \end{texnote} |
| 538 |
% \end{function} |
| 539 |
% |
| 540 |
% \begin{function}[added = 2026-02-25]{\vbox:nw, \vbox_top:nw, \vbox_center:nw} |
| 541 |
% \begin{syntax} |
| 542 |
% \cs{vbox:nw} \Arg{offset} |
| 543 |
% \meta{contents} |
| 544 |
% \cs{vbox_end:} |
| 545 |
% \end{syntax} |
| 546 |
% Typesets the \meta{contents} into a vertical box of natural height |
| 547 |
% and includes this box in the current list for typesetting. The reference |
| 548 |
% of the box is determined as for the matching |:n| function. The box |
| 549 |
% is then displaced vertically by the \meta{offset} (a \meta{dim expr}) |
| 550 |
% from existing baseline. |
| 551 |
% \end{function} |
| 552 |
% |
| 553 |
% \begin{function}[updated = 2017-04-05]{\vbox_to_ht:nn} |
| 554 |
% \begin{syntax} |
| 555 |
% \cs{vbox_to_ht:nn} \Arg{dim expr} \Arg{contents} |
| 556 |
% \end{syntax} |
| 557 |
% Typesets the \meta{contents} into a vertical box of height |
| 558 |
% \meta{dim expr} and then includes this box in the current list for |
| 559 |
% typesetting. |
| 560 |
% \end{function} |
| 561 |
% |
| 562 |
% \begin{function}[added = 2026-02-01]{\vbox_top_to_ht:nn} |
| 563 |
% \begin{syntax} |
| 564 |
% \cs{vbox_top_to_ht:nn} \Arg{dim expr} \Arg{contents} |
| 565 |
% \end{syntax} |
| 566 |
% Typesets the \meta{contents} into a vertical box of height |
| 567 |
% \meta{dim expr} and then includes this box in the current list for |
| 568 |
% typesetting. The vertical position of reference point of the box |
| 569 |
% is equal to the baseline of the \emph{first} item added to the box. |
| 570 |
% \end{function} |
| 571 |
% |
| 572 |
% \begin{function}[added = 2026-02-17]{\vbox_center_to_ht:nn} |
| 573 |
% \begin{syntax} |
| 574 |
% \cs{vbox_center_to_ht:nn} \Arg{dim expr} \Arg{contents} |
| 575 |
% \end{syntax} |
| 576 |
% Typesets the \meta{contents} into a vertical box of height |
| 577 |
% \meta{dim expr} and then includes this box in the current list for |
| 578 |
% typesetting. The vertical position of reference point of the box |
| 579 |
% is at the vertical midpoint of content of the box. |
| 580 |
% \end{function} |
| 581 |
% |
| 582 |
% \begin{function}[added = 2026-02-25] |
| 583 |
% {\vbox_to_ht:nw, \vbox_top_to_ht:nw, \vbox_center_to_ht:nw} |
| 584 |
% \begin{syntax} |
| 585 |
% \cs{vbox_to_ht:nw} \Arg{dim expr} |
| 586 |
% \meta{contents} |
| 587 |
% \cs{vbox_end:} |
| 588 |
% \end{syntax} |
| 589 |
% Typesets the \meta{contents} into a vertical box of height \meta{dim expr} |
| 590 |
% and includes this box in the current list for typesetting. The reference |
| 591 |
% of the box is determined as for the matching |:nn| function. |
| 592 |
% \end{function} |
| 593 |
% |
| 594 |
% \begin{function}[updated = 2017-04-05]{\vbox_to_zero:n} |
| 595 |
% \begin{syntax} |
| 596 |
% \cs{vbox_to_zero:n} \Arg{contents} |
| 597 |
% \end{syntax} |
| 598 |
% Typesets the \meta{contents} into a vertical box of zero height |
| 599 |
% and then includes this box in the current list for typesetting. |
| 600 |
% \end{function} |
| 601 |
% |
| 602 |
% \begin{function}[updated = 2017-04-05] |
| 603 |
% {\vbox_set:Nn, \vbox_set:cn, \vbox_gset:Nn, \vbox_gset:cn} |
| 604 |
% \begin{syntax} |
| 605 |
% \cs{vbox_set:Nn} \meta{box} \Arg{contents} |
| 606 |
% \end{syntax} |
| 607 |
% Typesets the \meta{contents} at natural height and then stores the |
| 608 |
% result inside the \meta{box}. |
| 609 |
% \end{function} |
| 610 |
% |
| 611 |
% \begin{function}[updated = 2017-04-05] |
| 612 |
% {\vbox_set_top:Nn, \vbox_set_top:cn, \vbox_gset_top:Nn, \vbox_gset_top:cn} |
| 613 |
% \begin{syntax} |
| 614 |
% \cs{vbox_set_top:Nn} \meta{box} \Arg{contents} |
| 615 |
% \end{syntax} |
| 616 |
% Typesets the \meta{contents} at natural height and then stores the |
| 617 |
% result inside the \meta{box}. The baseline of the box is equal |
| 618 |
% to that of the \emph{first} item added to the box. |
| 619 |
% \end{function} |
| 620 |
% |
| 621 |
% \begin{function}[updated = 2017-04-05] |
| 622 |
% { |
| 623 |
% \vbox_set_to_ht:Nnn, \vbox_set_to_ht:cnn, |
| 624 |
% \vbox_gset_to_ht:Nnn, \vbox_gset_to_ht:cnn |
| 625 |
% } |
| 626 |
% \begin{syntax} |
| 627 |
% \cs{vbox_set_to_ht:Nnn} \meta{box} \Arg{dim expr} \Arg{contents} |
| 628 |
% \end{syntax} |
| 629 |
% Typesets the \meta{contents} to the height given by the |
| 630 |
% \meta{dim expr} and then stores the result inside the \meta{box}. |
| 631 |
% \end{function} |
| 632 |
% |
| 633 |
% \begin{function}[updated = 2017-04-05] |
| 634 |
% { |
| 635 |
% \vbox_set:Nw, \vbox_set:cw, |
| 636 |
% \vbox_set_end:, |
| 637 |
% \vbox_gset:Nw, \vbox_gset:cw, |
| 638 |
% \vbox_gset_end: |
| 639 |
% } |
| 640 |
% \begin{syntax} |
| 641 |
% \cs{vbox_set:Nw} \meta{box} \meta{contents} \cs{vbox_set_end:} |
| 642 |
% \end{syntax} |
| 643 |
% Typesets the \meta{contents} at natural height and then stores the |
| 644 |
% result inside the \meta{box}. In contrast |
| 645 |
% to \cs{vbox_set:Nn} this function does not absorb the argument |
| 646 |
% when finding the \meta{content}, and so can be used in circumstances |
| 647 |
% where the \meta{content} may not be a simple argument. |
| 648 |
% \end{function} |
| 649 |
% |
| 650 |
% \begin{function}[added = 2017-06-08] |
| 651 |
% { |
| 652 |
% \vbox_set_to_ht:Nnw, \vbox_set_to_ht:cnw, |
| 653 |
% \vbox_gset_to_ht:Nnw, \vbox_gset_to_ht:cnw |
| 654 |
% } |
| 655 |
% \begin{syntax} |
| 656 |
% \cs{vbox_set_to_ht:Nnw} \meta{box} \Arg{dim expr} \meta{contents} \cs{vbox_set_end:} |
| 657 |
% \end{syntax} |
| 658 |
% Typesets the \meta{contents} to the height given by the \meta{dim expr} |
| 659 |
% and then stores the result inside the \meta{box}. In contrast |
| 660 |
% to \cs{vbox_set_to_ht:Nnn} this function does not absorb the argument |
| 661 |
% when finding the \meta{content}, and so can be used in circumstances |
| 662 |
% where the \meta{content} may not be a simple argument. |
| 663 |
% \end{function} |
| 664 |
% |
| 665 |
% |
| 666 |
% \begin{function}[updated = 2018-12-29] |
| 667 |
% { |
| 668 |
% \vbox_set_split_to_ht:NNn, \vbox_set_split_to_ht:cNn, |
| 669 |
% \vbox_set_split_to_ht:Ncn, \vbox_set_split_to_ht:ccn, |
| 670 |
% \vbox_gset_split_to_ht:NNn, \vbox_gset_split_to_ht:cNn, |
| 671 |
% \vbox_gset_split_to_ht:Ncn, \vbox_gset_split_to_ht:ccn |
| 672 |
% } |
| 673 |
% \begin{syntax} |
| 674 |
% \cs{vbox_set_split_to_ht:NNn} \meta{box_1} \meta{box_2} \Arg{dim expr} |
| 675 |
% \end{syntax} |
| 676 |
% Sets \meta{box_1} to contain material to the height given by the |
| 677 |
% \meta{dim expr} by removing content from the top of \meta{box_2} |
| 678 |
% (which must be a vertical box). |
| 679 |
% \end{function} |
| 680 |
% |
| 681 |
% \begin{function}{\vbox_unpack:N, \vbox_unpack:c} |
| 682 |
% \begin{syntax} |
| 683 |
% \cs{vbox_unpack:N} \meta{box} |
| 684 |
% \end{syntax} |
| 685 |
% Unpacks the content of the vertical \meta{box}, retaining any stretching |
| 686 |
% or shrinking applied when the \meta{box} was set. |
| 687 |
% \begin{texnote} |
| 688 |
% This is the \TeX{} primitive \tn{unvcopy}. |
| 689 |
% \end{texnote} |
| 690 |
% \end{function} |
| 691 |
% |
| 692 |
% \section{Using boxes efficiently} |
| 693 |
% |
| 694 |
% The functions above for using box contents work in exactly the same |
| 695 |
% way as for any other \pkg{expl3} variable. However, for efficiency |
| 696 |
% reasons, it is also useful to have functions which \emph{drop} box |
| 697 |
% contents on use. When a box is dropped, the box becomes empty at the group |
| 698 |
% level \emph{where the box was originally set} rather than necessarily |
| 699 |
% \emph{at the current group level}. For example, with |
| 700 |
% \begin{verbatim} |
| 701 |
% \hbox_set:Nn \l_tmpa_box { A } |
| 702 |
% \group_begin: |
| 703 |
% \hbox_set:Nn \l_tmpa_box { B } |
| 704 |
% \group_begin: |
| 705 |
% \box_use_drop:N \l_tmpa_box |
| 706 |
% \group_end: |
| 707 |
% \box_show:N \l_tmpa_box |
| 708 |
% \group_end: |
| 709 |
% \box_show:N \l_tmpa_box |
| 710 |
% \end{verbatim} |
| 711 |
% the first use of \cs{box_show:N} will show an entirely cleared (void) box, and the |
| 712 |
% second will show the letter |A| in the box. |
| 713 |
% |
| 714 |
% These functions should be preferred when the content of the box is no |
| 715 |
% longer required after use. Note that due to the unusual scoping behavior of |
| 716 |
% \texttt{drop} functions they may be applied to both local and global boxes: |
| 717 |
% the latter will naturally be set and thus cleared at a global level. |
| 718 |
% |
| 719 |
% \begin{function}{\box_use_drop:N, \box_use_drop:c} |
| 720 |
% \begin{syntax} |
| 721 |
% \cs{box_use_drop:N} \meta{box} |
| 722 |
% \end{syntax} |
| 723 |
% Inserts the current content of the \meta{box} onto the current |
| 724 |
% list for typesetting then drops the box content. An error is raised if the |
| 725 |
% variable does not exist or if it is invalid. This function may be applied to |
| 726 |
% local or global boxes. |
| 727 |
% \begin{texnote} |
| 728 |
% This is the \TeX{} primitive \tn{box}. |
| 729 |
% \end{texnote} |
| 730 |
% \end{function} |
| 731 |
% |
| 732 |
% \begin{function}[added = 2019-01-17] |
| 733 |
% { |
| 734 |
% \box_set_eq_drop:NN, \box_set_eq_drop:cN, |
| 735 |
% \box_set_eq_drop:Nc, \box_set_eq_drop:cc |
| 736 |
% } |
| 737 |
% \begin{syntax} |
| 738 |
% \cs{box_set_eq_drop:NN} \meta{box_1} \meta{box_2} |
| 739 |
% \end{syntax} |
| 740 |
% Sets the content of \meta{box_1} equal to that of \meta{box_2}, then |
| 741 |
% drops \meta{box_2}. |
| 742 |
% \end{function} |
| 743 |
% |
| 744 |
% \begin{function}[added = 2019-01-17] |
| 745 |
% { |
| 746 |
% \box_gset_eq_drop:NN, \box_gset_eq_drop:cN, |
| 747 |
% \box_gset_eq_drop:Nc, \box_gset_eq_drop:cc |
| 748 |
% } |
| 749 |
% \begin{syntax} |
| 750 |
% \cs{box_gset_eq_drop:NN} \meta{box_1} \meta{box_2} |
| 751 |
% \end{syntax} |
| 752 |
% Sets the content of \meta{box_1} globally equal to that of \meta{box_2}, |
| 753 |
% then drops \meta{box_2}. |
| 754 |
% \end{function} |
| 755 |
% |
| 756 |
% \begin{function}[added = 2019-01-17] |
| 757 |
% {\hbox_unpack_drop:N, \hbox_unpack_drop:c} |
| 758 |
% \begin{syntax} |
| 759 |
% \cs{hbox_unpack_drop:N} \meta{box} |
| 760 |
% \end{syntax} |
| 761 |
% Unpacks the content of the horizontal \meta{box}, retaining any stretching |
| 762 |
% or shrinking applied when the \meta{box} was set. The original \meta{box} |
| 763 |
% is then dropped. |
| 764 |
% \begin{texnote} |
| 765 |
% This is the \TeX{} primitive \tn{unhbox}. |
| 766 |
% \end{texnote} |
| 767 |
% \end{function} |
| 768 |
% |
| 769 |
% \begin{function}[added = 2019-01-17] |
| 770 |
% {\vbox_unpack_drop:N, \vbox_unpack_drop:c} |
| 771 |
% \begin{syntax} |
| 772 |
% \cs{vbox_unpack_drop:N} \meta{box} |
| 773 |
% \end{syntax} |
| 774 |
% Unpacks the content of the vertical \meta{box}, retaining any stretching |
| 775 |
% or shrinking applied when the \meta{box} was set. The original \meta{box} |
| 776 |
% is then dropped. |
| 777 |
% \begin{texnote} |
| 778 |
% This is the \TeX{} primitive \tn{unvbox}. |
| 779 |
% \end{texnote} |
| 780 |
% \end{function} |
| 781 |
% |
| 782 |
% \section{Affine transformations} |
| 783 |
% |
| 784 |
% Affine transformations are changes which (informally) preserve straight |
| 785 |
% lines. Simple translations are affine transformations, but are better handled |
| 786 |
% in \TeX{} by doing the translation first, then inserting an unmodified box. |
| 787 |
% On the other hand, rotation and resizing of boxed material can best be |
| 788 |
% handled by modifying boxes. These transformations are described here. |
| 789 |
% |
| 790 |
% \begin{function}[added = 2017-04-04, updated = 2019-01-22] |
| 791 |
% { |
| 792 |
% \box_autosize_to_wd_and_ht:Nnn, \box_autosize_to_wd_and_ht:cnn, |
| 793 |
% \box_gautosize_to_wd_and_ht:Nnn, \box_gautosize_to_wd_and_ht:cnn, |
| 794 |
% } |
| 795 |
% \begin{syntax} |
| 796 |
% \cs{box_autosize_to_wd_and_ht:Nnn} \meta{box} \Arg{x-size} \Arg{y-size} |
| 797 |
% \end{syntax} |
| 798 |
% Resizes the \meta{box} to fit within the given \meta{x-size} (horizontally) |
| 799 |
% and \meta{y-size} (vertically); both of the sizes are dimension |
| 800 |
% expressions. The \meta{y-size} is the height only: it does not include any |
| 801 |
% depth. The updated \meta{box} is an |hbox|, irrespective of the nature |
| 802 |
% of the \meta{box} before the resizing is applied. The final size of the |
| 803 |
% \meta{box} is the smaller of \Arg{x-size} and \Arg{y-size}, |
| 804 |
% i.e., the result fits within the dimensions specified. Negative |
| 805 |
% sizes cause the material in the \meta{box} to be reversed in direction, |
| 806 |
% but the reference point of the \meta{box} is unchanged. Thus a negative |
| 807 |
% \meta{y-size} results in the \meta{box} having a depth dependent on the |
| 808 |
% height of the original and \emph{vice versa}. |
| 809 |
% \end{function} |
| 810 |
% |
| 811 |
% \begin{function}[added = 2017-04-04, updated = 2019-01-22] |
| 812 |
% { |
| 813 |
% \box_autosize_to_wd_and_ht_plus_dp:Nnn, |
| 814 |
% \box_autosize_to_wd_and_ht_plus_dp:cnn, |
| 815 |
% \box_gautosize_to_wd_and_ht_plus_dp:Nnn, |
| 816 |
% \box_gautosize_to_wd_and_ht_plus_dp:cnn |
| 817 |
% } |
| 818 |
% \begin{syntax} |
| 819 |
% \cs{box_autosize_to_wd_and_ht_plus_dp:Nnn} \meta{box} \Arg{x-size} \Arg{y-size} |
| 820 |
% \end{syntax} |
| 821 |
% Resizes the \meta{box} to fit within the given \meta{x-size} (horizontally) |
| 822 |
% and \meta{y-size} (vertically); both of the sizes are dimension |
| 823 |
% expressions. The \meta{y-size} is the total vertical size (height plus |
| 824 |
% depth). The updated \meta{box} is an |hbox|, irrespective of the nature |
| 825 |
% of the \meta{box} before the resizing is applied. The final size of the |
| 826 |
% \meta{box} is the smaller of \Arg{x-size} and \Arg{y-size}, |
| 827 |
% i.e., the result fits within the dimensions specified. Negative |
| 828 |
% sizes cause the material in the \meta{box} to be reversed in direction, |
| 829 |
% but the reference point of the \meta{box} is unchanged. Thus a negative |
| 830 |
% \meta{y-size} results in the \meta{box} having a depth dependent on the |
| 831 |
% height of the original and \emph{vice versa}. |
| 832 |
% \end{function} |
| 833 |
% |
| 834 |
% \begin{function}[updated = 2019-01-22] |
| 835 |
% { |
| 836 |
% \box_resize_to_ht:Nn, \box_resize_to_ht:cn, |
| 837 |
% \box_gresize_to_ht:Nn, \box_gresize_to_ht:cn |
| 838 |
% } |
| 839 |
% \begin{syntax} |
| 840 |
% \cs{box_resize_to_ht:Nn} \meta{box} \Arg{y-size} |
| 841 |
% \end{syntax} |
| 842 |
% Resizes the \meta{box} to \meta{y-size} (vertically), scaling the horizontal |
| 843 |
% size by the same amount; \meta{y-size} is a dimension expression. The |
| 844 |
% \meta{y-size} is the height only: it does not include any depth. The updated |
| 845 |
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box} |
| 846 |
% before the resizing is applied. A negative \meta{y-size} causes the |
| 847 |
% material in the \meta{box} to be reversed in direction, but the reference |
| 848 |
% point of the \meta{box} is unchanged. Thus a negative \meta{y-size} |
| 849 |
% results in the \meta{box} having a depth dependent on the height of the |
| 850 |
% original and \emph{vice versa}. |
| 851 |
% \end{function} |
| 852 |
% |
| 853 |
% \begin{function}[updated = 2019-01-22] |
| 854 |
% { |
| 855 |
% \box_resize_to_ht_plus_dp:Nn, \box_resize_to_ht_plus_dp:cn, |
| 856 |
% \box_gresize_to_ht_plus_dp:Nn, \box_gresize_to_ht_plus_dp:cn, |
| 857 |
% } |
| 858 |
% \begin{syntax} |
| 859 |
% \cs{box_resize_to_ht_plus_dp:Nn} \meta{box} \Arg{y-size} |
| 860 |
% \end{syntax} |
| 861 |
% Resizes the \meta{box} to \meta{y-size} (vertically), scaling the horizontal |
| 862 |
% size by the same amount; \meta{y-size} is a dimension expression. The |
| 863 |
% \meta{y-size} is the total vertical size (height plus depth). The updated |
| 864 |
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box} |
| 865 |
% before the resizing is applied. A negative \meta{y-size} causes |
| 866 |
% the material in the \meta{box} to be reversed in direction, but the |
| 867 |
% reference point of the \meta{box} is unchanged. Thus a negative |
| 868 |
% \meta{y-size} results in the \meta{box} having a depth dependent on the |
| 869 |
% height of the original and \emph{vice versa}. |
| 870 |
% \end{function} |
| 871 |
% |
| 872 |
% \begin{function}[updated = 2019-01-22] |
| 873 |
% { |
| 874 |
% \box_resize_to_wd:Nn, \box_resize_to_wd:cn, |
| 875 |
% \box_gresize_to_wd:Nn, \box_gresize_to_wd:cn |
| 876 |
% } |
| 877 |
% \begin{syntax} |
| 878 |
% \cs{box_resize_to_wd:Nn} \meta{box} \Arg{x-size} |
| 879 |
% \end{syntax} |
| 880 |
% Resizes the \meta{box} to \meta{x-size} (horizontally), scaling the vertical |
| 881 |
% size by the same amount; \meta{x-size} is a dimension expression. The updated |
| 882 |
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box} |
| 883 |
% before the resizing is applied. A negative \meta{x-size} causes the |
| 884 |
% material in the \meta{box} to be reversed in direction, but the reference |
| 885 |
% point of the \meta{box} is unchanged. Thus a negative \meta{x-size} |
| 886 |
% results in the \meta{box} having a depth dependent on the height of the |
| 887 |
% original and \emph{vice versa}. |
| 888 |
% \end{function} |
| 889 |
% |
| 890 |
% \begin{function}[added = 2014-07-03, updated = 2019-01-22] |
| 891 |
% { |
| 892 |
% \box_resize_to_wd_and_ht:Nnn, \box_resize_to_wd_and_ht:cnn, |
| 893 |
% \box_gresize_to_wd_and_ht:Nnn, \box_gresize_to_wd_and_ht:cnn |
| 894 |
% } |
| 895 |
% \begin{syntax} |
| 896 |
% \cs{box_resize_to_wd_and_ht:Nnn} \meta{box} \Arg{x-size} \Arg{y-size} |
| 897 |
% \end{syntax} |
| 898 |
% Resizes the \meta{box} to \meta{x-size} (horizontally) and \meta{y-size} |
| 899 |
% (vertically): both of the sizes are dimension expressions. The |
| 900 |
% \meta{y-size} is the height only and does not include any depth. The updated |
| 901 |
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box} |
| 902 |
% before the resizing is applied. Negative sizes cause the material in |
| 903 |
% the \meta{box} to be reversed in direction, but the reference point of the |
| 904 |
% \meta{box} is unchanged. Thus a negative \meta{y-size} results in |
| 905 |
% the \meta{box} having a depth dependent on the height of the original and |
| 906 |
% \emph{vice versa}. |
| 907 |
% \end{function} |
| 908 |
% |
| 909 |
% \begin{function}[added = 2017-04-06, updated = 2019-01-22] |
| 910 |
% { |
| 911 |
% \box_resize_to_wd_and_ht_plus_dp:Nnn, |
| 912 |
% \box_resize_to_wd_and_ht_plus_dp:cnn, |
| 913 |
% \box_gresize_to_wd_and_ht_plus_dp:Nnn, |
| 914 |
% \box_gresize_to_wd_and_ht_plus_dp:cnn |
| 915 |
% } |
| 916 |
% \begin{syntax} |
| 917 |
% \cs{box_resize_to_wd_and_ht_plus_dp:Nnn} \meta{box} \Arg{x-size} \Arg{y-size} |
| 918 |
% \end{syntax} |
| 919 |
% Resizes the \meta{box} to \meta{x-size} (horizontally) and \meta{y-size} |
| 920 |
% (vertically): both of the sizes are dimension expressions. The |
| 921 |
% \meta{y-size} is the total vertical size (height plus depth). The updated |
| 922 |
% \meta{box} is an |hbox|, irrespective of the nature of the \meta{box} |
| 923 |
% before the resizing is applied. Negative sizes cause the material in |
| 924 |
% the \meta{box} to be reversed in direction, but the reference point of the |
| 925 |
% \meta{box} is unchanged. Thus a negative \meta{y-size} results in |
| 926 |
% the \meta{box} having a depth dependent on the height of the original and |
| 927 |
% \emph{vice versa}. |
| 928 |
% \end{function} |
| 929 |
% |
| 930 |
% \begin{function}[updated = 2019-01-22] |
| 931 |
% { |
| 932 |
% \box_rotate:Nn, \box_rotate:cn, |
| 933 |
% \box_grotate:Nn, \box_grotate:cn |
| 934 |
% } |
| 935 |
% \begin{syntax} |
| 936 |
% \cs{box_rotate:Nn} \meta{box} \Arg{angle} |
| 937 |
% \end{syntax} |
| 938 |
% Rotates the \meta{box} by \meta{angle} (a \meta{fp expr} in degrees) |
| 939 |
% anti-clockwise about |
| 940 |
% its reference point. The reference point of the updated box is moved |
| 941 |
% horizontally such that it is at the left side of the smallest rectangle |
| 942 |
% enclosing the rotated material. The updated \meta{box} is an |hbox|, |
| 943 |
% irrespective of the nature of the \meta{box} before the rotation is applied. |
| 944 |
% \end{function} |
| 945 |
% |
| 946 |
% \begin{function}[updated = 2019-01-22] |
| 947 |
% { |
| 948 |
% \box_scale:Nnn, \box_scale:cnn, |
| 949 |
% \box_gscale:Nnn, \box_gscale:cnn |
| 950 |
% } |
| 951 |
% \begin{syntax} |
| 952 |
% \cs{box_scale:Nnn} \meta{box} \Arg{x-scale} \Arg{y-scale} |
| 953 |
% \end{syntax} |
| 954 |
% Scales the \meta{box} by factors \meta{x-scale} and \meta{y-scale} in |
| 955 |
% the horizontal and vertical directions, respectively (both scales are |
| 956 |
% \meta{fp expr}). The updated \meta{box} is an |hbox|, irrespective |
| 957 |
% of the nature of the \meta{box} before the scaling is applied. Negative |
| 958 |
% scalings cause the material in the \meta{box} to be reversed in |
| 959 |
% direction, but the reference point of the \meta{box} is unchanged. |
| 960 |
% Thus a negative \meta{y-scale} results in the \meta{box} having a depth |
| 961 |
% dependent on the height of the original and \emph{vice versa}. |
| 962 |
% \end{function} |
| 963 |
% |
| 964 |
% \section{Framing boxes} |
| 965 |
% |
| 966 |
% \begin{function}[added = 2026-03-16] |
| 967 |
% { |
| 968 |
% \box_frame:Nnn, \box_frame:cnn, |
| 969 |
% \box_gframe:Nnn, \box_gframe:cnn |
| 970 |
% } |
| 971 |
% \begin{syntax} |
| 972 |
% \cs{box_frame:Nnn} \meta{box} \Arg{separation} \Arg{thickness} \\ |
| 973 |
% \end{syntax} |
| 974 |
% Adds a frame of \meta{thickness} (a \meta{dimexpr}) to the \meta{box}. |
| 975 |
% The \meta{separation} (a \meta{dimexpr}) is left between the existing content |
| 976 |
% and the frame. The updated \meta{box} is an |hbox|, irrespective |
| 977 |
% of the nature of the \meta{box} before the frame is applied. |
| 978 |
% The frame will overprint any part of the content which |
| 979 |
% lies outside of the bounding box at natural size (i.e., the frame is |
| 980 |
% printed \enquote{after} the content). The apparent size of the |
| 981 |
% inserted box includes the frame and the border, i.e., the width |
| 982 |
% of the inserted material is $\mathrm{width}(\meta{content}) + |
| 983 |
% 2(\meta{thickness} + \meta{separation})$. |
| 984 |
% The vertical position of the reference point of the box is unchanged |
| 985 |
% by this function; the horizontal reference point is at the left of |
| 986 |
% the box, i.e., the original content is displaced rightward by the |
| 987 |
% \Arg{separation} and the \Arg{thickness}. |
| 988 |
% \end{function} |
| 989 |
% |
| 990 |
% \begin{function}[added = 2026-03-16] |
| 991 |
% { |
| 992 |
% \box_underline:Nnn, \box_underline:cnn, |
| 993 |
% \box_gunderline:Nnn, \box_gunderline:cnn |
| 994 |
% } |
| 995 |
% \begin{syntax} |
| 996 |
% \cs{box_underline:Nnn} \meta{box} \Arg{separation} \Arg{thickness} \\ |
| 997 |
% \end{syntax} |
| 998 |
% Adds an underline of \meta{thickness} (a \meta{dimexpr}) to the \meta{box}. |
| 999 |
% The \meta{separation} (a \meta{dimexpr}) is left between the existing content |
| 1000 |
% and the line. The updated \meta{box} is an |hbox|, irrespective |
| 1001 |
% of the nature of the \meta{box} before the line is applied. |
| 1002 |
% The underline will overprint any part of the content which |
| 1003 |
% lies outside of the bounding box at natural size (i.e., the line is |
| 1004 |
% printed \enquote{after} the content). The apparent size of the inserted |
| 1005 |
% box includes the underline and the border, this affects only the depth. |
| 1006 |
% The vertical and horizontal positions of the reference point of the box |
| 1007 |
% are unchanged by this function. |
| 1008 |
% \end{function} |
| 1009 |
% |
| 1010 |
% \section{Viewing part of a box} |
| 1011 |
% |
| 1012 |
% \begin{function}[updated = 2023-04-14] |
| 1013 |
% { |
| 1014 |
% \box_set_clipped:N, \box_set_clipped:c, |
| 1015 |
% \box_gset_clipped:N, \box_gset_clipped:c |
| 1016 |
% } |
| 1017 |
% \begin{syntax} |
| 1018 |
% \cs{box_set_clipped:N} \meta{box} |
| 1019 |
% \end{syntax} |
| 1020 |
% Clips the \meta{box} in the output so that only material inside the |
| 1021 |
% bounding box is displayed in the output. The updated \meta{box} is an |
| 1022 |
% hbox, irrespective of the nature of the \meta{box} before the clipping is |
| 1023 |
% applied. Additional box levels are also generated by this operation. |
| 1024 |
% |
| 1025 |
% \begin{texnote} |
| 1026 |
% Clipping is implemented by the driver, and as such the full content of |
| 1027 |
% the box is placed in the output file. Thus clipping does not remove |
| 1028 |
% any information from the raw output, and hidden material can therefore |
| 1029 |
% be viewed by direct examination of the file. |
| 1030 |
% \end{texnote} |
| 1031 |
% \end{function} |
| 1032 |
% |
| 1033 |
% \begin{function}[added = 2019-01-23] |
| 1034 |
% { |
| 1035 |
% \box_set_trim:Nnnnn, \box_set_trim:cnnnn, |
| 1036 |
% \box_gset_trim:Nnnnn, \box_gset_trim:cnnnn |
| 1037 |
% } |
| 1038 |
% \begin{syntax} |
| 1039 |
% \cs{box_set_trim:Nnnnn} \meta{box} \Arg{left} \Arg{bottom} \Arg{right} \Arg{top} |
| 1040 |
% \end{syntax} |
| 1041 |
% Adjusts the bounding box of the \meta{box}: \meta{left} is removed from |
| 1042 |
% the left-hand edge of the bounding box, \meta{right} from the right-hand |
| 1043 |
% edge, and so forth. All adjustments are \meta{dim exprs}. |
| 1044 |
% Material outside of the bounding box is still displayed in the output |
| 1045 |
% unless \cs{box_set_clipped:N} is subsequently applied. |
| 1046 |
% The updated \meta{box} is an |
| 1047 |
% hbox, irrespective of the nature of the \meta{box} before the trim |
| 1048 |
% operation is applied. |
| 1049 |
% Additional box levels are also generated by this operation. |
| 1050 |
% The behavior of the operation where the trims requested is |
| 1051 |
% greater than the size of the box is undefined. |
| 1052 |
% \end{function} |
| 1053 |
% |
| 1054 |
% \begin{function}[added = 2019-01-23] |
| 1055 |
% { |
| 1056 |
% \box_set_viewport:Nnnnn, \box_set_viewport:cnnnn, |
| 1057 |
% \box_gset_viewport:Nnnnn, \box_gset_viewport:cnnnn |
| 1058 |
% } |
| 1059 |
% \begin{syntax} |
| 1060 |
% \cs{box_set_viewport:Nnnnn} \meta{box} \Arg{llx} \Arg{lly} \Arg{urx} \Arg{ury} |
| 1061 |
% \end{syntax} |
| 1062 |
% Adjusts the bounding box of the \meta{box} such that it has lower-left |
| 1063 |
% coordinates (\meta{llx}, \meta{lly}) and upper-right coordinates |
| 1064 |
% (\meta{urx}, \meta{ury}). All four coordinate positions are |
| 1065 |
% \meta{dim exprs}. Material outside of the bounding box is |
| 1066 |
% still displayed in the output unless \cs{box_set_clipped:N} is |
| 1067 |
% subsequently applied. |
| 1068 |
% The updated \meta{box} is an |
| 1069 |
% hbox, irrespective of the nature of the \meta{box} before the viewport |
| 1070 |
% operation is applied. |
| 1071 |
% Additional box levels are also generated by this operation. |
| 1072 |
% \end{function} |
| 1073 |
% |
| 1074 |
% \section{Primitive box conditionals} |
| 1075 |
% |
| 1076 |
% \begin{function}[EXP]{\if_hbox:N} |
| 1077 |
% \begin{syntax} |
| 1078 |
% \cs{if_hbox:N} \meta{box} |
| 1079 |
% ~~\meta{true code} |
| 1080 |
% \cs{else:} |
| 1081 |
% ~~\meta{false code} |
| 1082 |
% \cs{fi:} |
| 1083 |
% \end{syntax} |
| 1084 |
% Tests if \meta{box} is a horizontal box. |
| 1085 |
% \begin{texnote} |
| 1086 |
% This is the \TeX{} primitive \tn{ifhbox}. |
| 1087 |
% \end{texnote} |
| 1088 |
% \end{function} |
| 1089 |
% |
| 1090 |
% \begin{function}[EXP]{\if_vbox:N} |
| 1091 |
% \begin{syntax} |
| 1092 |
% \cs{if_vbox:N} \meta{box} |
| 1093 |
% ~~\meta{true code} |
| 1094 |
% \cs{else:} |
| 1095 |
% ~~\meta{false code} |
| 1096 |
% \cs{fi:} |
| 1097 |
% \end{syntax} |
| 1098 |
% Tests if \meta{box} is a vertical box. |
| 1099 |
% \begin{texnote} |
| 1100 |
% This is the \TeX{} primitive \tn{ifvbox}. |
| 1101 |
% \end{texnote} |
| 1102 |
% \end{function} |
| 1103 |
% |
| 1104 |
% \begin{function}[EXP]{\if_box_empty:N} |
| 1105 |
% \begin{syntax} |
| 1106 |
% \cs{if_box_empty:N} \meta{box} |
| 1107 |
% ~~\meta{true code} |
| 1108 |
% \cs{else:} |
| 1109 |
% ~~\meta{false code} |
| 1110 |
% \cs{fi:} |
| 1111 |
% \end{syntax} |
| 1112 |
% Tests if \meta{box} is an empty (void) box. |
| 1113 |
% \begin{texnote} |
| 1114 |
% This is the \TeX{} primitive \tn{ifvoid}. |
| 1115 |
% \end{texnote} |
| 1116 |
% \end{function} |
| 1117 |
% |
| 1118 |
% \end{documentation} |
| 1119 |
% |
| 1120 |
% \begin{implementation} |
| 1121 |
% |
| 1122 |
% \section{\pkg{l3box} implementation} |
| 1123 |
% |
| 1124 |
% \begin{macrocode} |
| 1125 |
%<*code> |
| 1126 |
% \end{macrocode} |
| 1127 |
% |
| 1128 |
% \begin{macrocode} |
| 1129 |
%<@@=box> |
| 1130 |
% \end{macrocode} |
| 1131 |
% |
| 1132 |
% \subsection{Support code} |
| 1133 |
% |
| 1134 |
% \begin{macro}{\@@_dim_eval:w} |
| 1135 |
% \begin{macro}{\@@_dim_eval:n} |
| 1136 |
% Evaluating a dimension expression expandably. The only |
| 1137 |
% difference with \cs{dim_eval:n} is the lack of \cs{dim_use:N}, to |
| 1138 |
% produce an internal dimension rather than expand it into characters. |
| 1139 |
% \begin{macrocode} |
| 1140 |
\cs_new_eq:NN \@@_dim_eval:w \tex_dimexpr:D |
| 1141 |
\cs_new:Npn \@@_dim_eval:n #1 |
| 1142 |
{ \@@_dim_eval:w #1 \scan_stop: } |
| 1143 |
% \end{macrocode} |
| 1144 |
% \end{macro} |
| 1145 |
% \end{macro} |
| 1146 |
% |
| 1147 |
% \subsection{Creating and initializing boxes} |
| 1148 |
% |
| 1149 |
% \TestFiles{m3box001.lvt} |
| 1150 |
% |
| 1151 |
% \begin{macro}{\box_new:N, \box_new:c} |
| 1152 |
% Defining a new \meta{box} register: remember that box $255$ is not |
| 1153 |
% generally available. |
| 1154 |
% \begin{macrocode} |
| 1155 |
\cs_new_protected:Npn \box_new:N #1 |
| 1156 |
{ |
| 1157 |
\__kernel_chk_if_free_cs:N #1 |
| 1158 |
\cs:w newbox \cs_end: #1 |
| 1159 |
} |
| 1160 |
\cs_generate_variant:Nn \box_new:N { c } |
| 1161 |
% \end{macrocode} |
| 1162 |
% |
| 1163 |
% \begin{macro}{\box_clear:N, \box_clear:c} |
| 1164 |
% \begin{macro}{\box_gclear:N, \box_gclear:c} |
| 1165 |
% \testfile* |
| 1166 |
% Clear a \meta{box} register. |
| 1167 |
% \begin{macrocode} |
| 1168 |
\cs_new_protected:Npn \box_clear:N #1 |
| 1169 |
{ \box_set_eq:NN #1 \c_empty_box } |
| 1170 |
\cs_new_protected:Npn \box_gclear:N #1 |
| 1171 |
{ \box_gset_eq:NN #1 \c_empty_box } |
| 1172 |
\cs_generate_variant:Nn \box_clear:N { c } |
| 1173 |
\cs_generate_variant:Nn \box_gclear:N { c } |
| 1174 |
% \end{macrocode} |
| 1175 |
% \end{macro} |
| 1176 |
% \end{macro} |
| 1177 |
% |
| 1178 |
% \begin{macro}{\box_clear_new:N, \box_clear_new:c} |
| 1179 |
% \begin{macro}{\box_gclear_new:N, \box_gclear_new:c} |
| 1180 |
% \testfile* |
| 1181 |
% Clear or new. |
| 1182 |
% \begin{macrocode} |
| 1183 |
\cs_new_protected:Npn \box_clear_new:N #1 |
| 1184 |
{ \box_if_exist:NTF #1 { \box_clear:N #1 } { \box_new:N #1 } } |
| 1185 |
\cs_new_protected:Npn \box_gclear_new:N #1 |
| 1186 |
{ \box_if_exist:NTF #1 { \box_gclear:N #1 } { \box_new:N #1 } } |
| 1187 |
\cs_generate_variant:Nn \box_clear_new:N { c } |
| 1188 |
\cs_generate_variant:Nn \box_gclear_new:N { c } |
| 1189 |
% \end{macrocode} |
| 1190 |
% \end{macro} |
| 1191 |
% \end{macro} |
| 1192 |
% |
| 1193 |
% \begin{macro} |
| 1194 |
% {\box_set_eq:NN, \box_set_eq:cN, \box_set_eq:Nc, \box_set_eq:cc} |
| 1195 |
% \testfile* |
| 1196 |
% \begin{macro} |
| 1197 |
% {\box_gset_eq:NN, \box_gset_eq:cN, \box_gset_eq:Nc, \box_gset_eq:cc} |
| 1198 |
% \testfile* |
| 1199 |
% Assigning the contents of a box to be another box. |
| 1200 |
% \begin{macrocode} |
| 1201 |
\cs_new_protected:Npn \box_set_eq:NN #1#2 |
| 1202 |
{ \tex_setbox:D #1 \tex_copy:D #2 } |
| 1203 |
\cs_new_protected:Npn \box_gset_eq:NN #1#2 |
| 1204 |
{ \tex_global:D \tex_setbox:D #1 \tex_copy:D #2 } |
| 1205 |
\cs_generate_variant:Nn \box_set_eq:NN { c , Nc , cc } |
| 1206 |
\cs_generate_variant:Nn \box_gset_eq:NN { c , Nc , cc } |
| 1207 |
% \end{macrocode} |
| 1208 |
% \end{macro} |
| 1209 |
% \end{macro} |
| 1210 |
% |
| 1211 |
% \begin{macro} |
| 1212 |
% { |
| 1213 |
% \box_set_eq_drop:NN, \box_set_eq_drop:cN, |
| 1214 |
% \box_set_eq_drop:Nc, \box_set_eq_drop:cc |
| 1215 |
% } |
| 1216 |
% \begin{macro} |
| 1217 |
% { |
| 1218 |
% \box_gset_eq_drop:NN, \box_gset_eq_drop:cN, |
| 1219 |
% \box_gset_eq_drop:Nc, \box_gset_eq_drop:cc |
| 1220 |
% } |
| 1221 |
% Assigning the contents of a box to be another box, then drops the |
| 1222 |
% original box. |
| 1223 |
% \begin{macrocode} |
| 1224 |
\cs_new_protected:Npn \box_set_eq_drop:NN #1#2 |
| 1225 |
{ \tex_setbox:D #1 \tex_box:D #2 } |
| 1226 |
\cs_new_protected:Npn \box_gset_eq_drop:NN #1#2 |
| 1227 |
{ \tex_global:D \tex_setbox:D #1 \tex_box:D #2 } |
| 1228 |
\cs_generate_variant:Nn \box_set_eq_drop:NN { c , Nc , cc } |
| 1229 |
\cs_generate_variant:Nn \box_gset_eq_drop:NN { c , Nc , cc } |
| 1230 |
% \end{macrocode} |
| 1231 |
% \end{macro} |
| 1232 |
% \end{macro} |
| 1233 |
% |
| 1234 |
% \begin{macro}[pTF]{\box_if_exist:N, \box_if_exist:c} |
| 1235 |
% Copies of the \texttt{cs} functions defined in \pkg{l3basics}. |
| 1236 |
% \begin{macrocode} |
| 1237 |
\prg_new_eq_conditional:NNn \box_if_exist:N \cs_if_exist:N |
| 1238 |
{ TF , T , F , p } |
| 1239 |
\prg_new_eq_conditional:NNn \box_if_exist:c \cs_if_exist:c |
| 1240 |
{ TF , T , F , p } |
| 1241 |
% \end{macrocode} |
| 1242 |
% \end{macro} |
| 1243 |
% |
| 1244 |
% \subsection{Measuring and setting box dimensions} |
| 1245 |
% |
| 1246 |
% \begin{macro}{\box_ht:N, \box_ht:c} |
| 1247 |
% \begin{macro}{\box_dp:N, \box_dp:c} |
| 1248 |
% \begin{macro}{\box_wd:N, \box_wd:c} |
| 1249 |
% \testfile* |
| 1250 |
% Accessing the height, depth, and width of a \meta{box} register. |
| 1251 |
% \begin{macrocode} |
| 1252 |
\cs_new_eq:NN \box_ht:N \tex_ht:D |
| 1253 |
\cs_new_eq:NN \box_dp:N \tex_dp:D |
| 1254 |
\cs_new_eq:NN \box_wd:N \tex_wd:D |
| 1255 |
\cs_generate_variant:Nn \box_ht:N { c } |
| 1256 |
\cs_generate_variant:Nn \box_dp:N { c } |
| 1257 |
\cs_generate_variant:Nn \box_wd:N { c } |
| 1258 |
% \end{macrocode} |
| 1259 |
% \end{macro} |
| 1260 |
% \end{macro} |
| 1261 |
% \end{macro} |
| 1262 |
% |
| 1263 |
% \begin{macro}{\box_ht_plus_dp:N} |
| 1264 |
% The \cs{box_ht:N} and \cs{box_dp:N} primitives do not expand but |
| 1265 |
% rather are suitable for use after \tn{the} or inside dimension |
| 1266 |
% expressions. Here we obtain the same behavior by using |
| 1267 |
% \cs{@@_dim_eval:n} (basically \tn{dimexpr}) rather than |
| 1268 |
% \cs{dim_eval:n} (basically \tn{the} \tn{dimexpr}). |
| 1269 |
% \begin{macrocode} |
| 1270 |
\cs_new_protected:Npn \box_ht_plus_dp:N #1 |
| 1271 |
{ \@@_dim_eval:n { \box_ht:N #1 + \box_dp:N #1 } } |
| 1272 |
\cs_generate_variant:Nn \box_ht_plus_dp:N { c } |
| 1273 |
% \end{macrocode} |
| 1274 |
% \end{macro} |
| 1275 |
% |
| 1276 |
% \begin{macro}{\box_set_ht:Nn, \box_set_ht:cn, \box_gset_ht:Nn, \box_gset_ht:cn} |
| 1277 |
% \begin{macro}{\box_set_dp:Nn, \box_set_dp:cn, \box_gset_dp:Nn, \box_gset_dp:cn} |
| 1278 |
% \begin{macro}{\box_set_wd:Nn, \box_set_wd:cn, \box_gset_wd:Nn, \box_gset_wd:cn} |
| 1279 |
% Setting the size whilst respecting local scope requires copying; |
| 1280 |
% the same issue does not come up when working globally. |
| 1281 |
% When debugging, the dimension expression |#2| is surrounded by |
| 1282 |
% parentheses to catch early termination. |
| 1283 |
% \begin{macrocode} |
| 1284 |
\cs_new_protected:Npn \box_set_dp:Nn #1#2 |
| 1285 |
{ |
| 1286 |
\tex_setbox:D #1 = \tex_copy:D #1 |
| 1287 |
\box_dp:N #1 \@@_dim_eval:n {#2} |
| 1288 |
} |
| 1289 |
\cs_generate_variant:Nn \box_set_dp:Nn { c } |
| 1290 |
\cs_new_protected:Npn \box_gset_dp:Nn #1#2 |
| 1291 |
{ \box_dp:N #1 \@@_dim_eval:n {#2} } |
| 1292 |
\cs_generate_variant:Nn \box_gset_dp:Nn { c } |
| 1293 |
\cs_new_protected:Npn \box_set_ht:Nn #1#2 |
| 1294 |
{ |
| 1295 |
\tex_setbox:D #1 = \tex_copy:D #1 |
| 1296 |
\box_ht:N #1 \@@_dim_eval:n {#2} |
| 1297 |
} |
| 1298 |
\cs_generate_variant:Nn \box_set_ht:Nn { c } |
| 1299 |
\cs_new_protected:Npn \box_gset_ht:Nn #1#2 |
| 1300 |
{ \box_ht:N #1 \@@_dim_eval:n {#2} } |
| 1301 |
\cs_generate_variant:Nn \box_gset_ht:Nn { c } |
| 1302 |
\cs_new_protected:Npn \box_set_wd:Nn #1#2 |
| 1303 |
{ |
| 1304 |
\tex_setbox:D #1 = \tex_copy:D #1 |
| 1305 |
\box_wd:N #1 \@@_dim_eval:n {#2} |
| 1306 |
} |
| 1307 |
\cs_generate_variant:Nn \box_set_wd:Nn { c } |
| 1308 |
\cs_new_protected:Npn \box_gset_wd:Nn #1#2 |
| 1309 |
{ \box_wd:N #1 \@@_dim_eval:n {#2} } |
| 1310 |
\cs_generate_variant:Nn \box_gset_wd:Nn { c } |
| 1311 |
% \end{macrocode} |
| 1312 |
% \end{macro} |
| 1313 |
% \end{macro} |
| 1314 |
% \end{macro} |
| 1315 |
% |
| 1316 |
% \subsection{Using boxes} |
| 1317 |
% |
| 1318 |
% \begin{macro}{\box_use_drop:N, \box_use_drop:c} |
| 1319 |
% \begin{macro}{\box_use:N, \box_use:c} |
| 1320 |
% Using a \meta{box}. These are just \TeX{} primitives with meaningful |
| 1321 |
% names. |
| 1322 |
% \begin{macrocode} |
| 1323 |
\cs_new_eq:NN \box_use_drop:N \tex_box:D |
| 1324 |
\cs_new_eq:NN \box_use:N \tex_copy:D |
| 1325 |
\cs_generate_variant:Nn \box_use_drop:N { c } |
| 1326 |
\cs_generate_variant:Nn \box_use:N { c } |
| 1327 |
% \end{macrocode} |
| 1328 |
% \end{macro} |
| 1329 |
% \end{macro} |
| 1330 |
% |
| 1331 |
% \begin{macro}{\box_move_left:nn, \box_move_right:nn} |
| 1332 |
% \begin{macro}{\box_move_up:nn, \box_move_down:nn} |
| 1333 |
% \testfile* |
| 1334 |
% Move box material in different directions. |
| 1335 |
% When debugging, the dimension expression |#1| is surrounded by |
| 1336 |
% parentheses to catch early termination. |
| 1337 |
% \begin{macrocode} |
| 1338 |
\cs_new_protected:Npn \box_move_left:nn #1#2 |
| 1339 |
{ \tex_moveleft:D \@@_dim_eval:n {#1} #2 } |
| 1340 |
\cs_new_protected:Npn \box_move_right:nn #1#2 |
| 1341 |
{ \tex_moveright:D \@@_dim_eval:n {#1} #2 } |
| 1342 |
\cs_new_protected:Npn \box_move_up:nn #1#2 |
| 1343 |
{ \tex_raise:D \@@_dim_eval:n {#1} #2 } |
| 1344 |
\cs_new_protected:Npn \box_move_down:nn #1#2 |
| 1345 |
{ \tex_lower:D \@@_dim_eval:n {#1} #2 } |
| 1346 |
% \end{macrocode} |
| 1347 |
% \end{macro} |
| 1348 |
% \end{macro} |
| 1349 |
% |
| 1350 |
% \subsection{Box conditionals} |
| 1351 |
% |
| 1352 |
% \begin{macro}{\if_hbox:N} |
| 1353 |
% \begin{macro}{\if_vbox:N} |
| 1354 |
% \begin{macro}{\if_box_empty:N} |
| 1355 |
% \testfile* |
| 1356 |
% The primitives for testing if a \meta{box} is empty/void or which |
| 1357 |
% type of box it is. |
| 1358 |
% \begin{macrocode} |
| 1359 |
\cs_new_eq:NN \if_hbox:N \tex_ifhbox:D |
| 1360 |
\cs_new_eq:NN \if_vbox:N \tex_ifvbox:D |
| 1361 |
\cs_new_eq:NN \if_box_empty:N \tex_ifvoid:D |
| 1362 |
% \end{macrocode} |
| 1363 |
% \end{macro} |
| 1364 |
% \end{macro} |
| 1365 |
% \end{macro} |
| 1366 |
% |
| 1367 |
% \begin{macro}[pTF]{\box_if_horizontal:N, \box_if_horizontal:c} |
| 1368 |
% \testfile* |
| 1369 |
% \begin{macro}[pTF]{\box_if_vertical:N, \box_if_vertical:c} |
| 1370 |
% \testfile* |
| 1371 |
% \begin{macrocode} |
| 1372 |
\prg_new_conditional:Npnn \box_if_horizontal:N #1 { p , T , F , TF } |
| 1373 |
{ \if_hbox:N #1 \prg_return_true: \else: \prg_return_false: \fi: } |
| 1374 |
\prg_new_conditional:Npnn \box_if_vertical:N #1 { p , T , F , TF } |
| 1375 |
{ \if_vbox:N #1 \prg_return_true: \else: \prg_return_false: \fi: } |
| 1376 |
\prg_generate_conditional_variant:Nnn \box_if_horizontal:N |
| 1377 |
{ c } { p , T , F , TF } |
| 1378 |
\prg_generate_conditional_variant:Nnn \box_if_vertical:N |
| 1379 |
{ c } { p , T , F , TF } |
| 1380 |
% \end{macrocode} |
| 1381 |
% \end{macro} |
| 1382 |
% \end{macro} |
| 1383 |
% |
| 1384 |
% \begin{macro}[pTF]{\box_if_empty:N, \box_if_empty:c} |
| 1385 |
% \testfile* |
| 1386 |
% Testing if a \meta{box} is empty/void. |
| 1387 |
% \begin{macrocode} |
| 1388 |
\prg_new_conditional:Npnn \box_if_empty:N #1 { p , T , F , TF } |
| 1389 |
{ \if_box_empty:N #1 \prg_return_true: \else: \prg_return_false: \fi: } |
| 1390 |
\prg_generate_conditional_variant:Nnn \box_if_empty:N |
| 1391 |
{ c } { p , T , F , TF } |
| 1392 |
% \end{macrocode} |
| 1393 |
% \end{macro} |
| 1394 |
% \end{macro} |
| 1395 |
% |
| 1396 |
% \subsection{The last box inserted} |
| 1397 |
% |
| 1398 |
% \begin{macro}{\box_set_to_last:N, \box_set_to_last:c} |
| 1399 |
% \begin{macro}{\box_gset_to_last:N, \box_gset_to_last:c} |
| 1400 |
% \testfile* |
| 1401 |
% Set a box to the previous box. |
| 1402 |
% \begin{macrocode} |
| 1403 |
\cs_new_protected:Npn \box_set_to_last:N #1 |
| 1404 |
{ \tex_setbox:D #1 \tex_lastbox:D } |
| 1405 |
\cs_new_protected:Npn \box_gset_to_last:N #1 |
| 1406 |
{ \tex_global:D \tex_setbox:D #1 \tex_lastbox:D } |
| 1407 |
\cs_generate_variant:Nn \box_set_to_last:N { c } |
| 1408 |
\cs_generate_variant:Nn \box_gset_to_last:N { c } |
| 1409 |
% \end{macrocode} |
| 1410 |
% \end{macro} |
| 1411 |
% \end{macro} |
| 1412 |
% |
| 1413 |
% \subsection{Constant boxes} |
| 1414 |
% |
| 1415 |
% \begin{variable}{\c_empty_box} |
| 1416 |
% A box we never use. |
| 1417 |
% \begin{macrocode} |
| 1418 |
\box_new:N \c_empty_box |
| 1419 |
% \end{macrocode} |
| 1420 |
% \end{variable} |
| 1421 |
% |
| 1422 |
% \subsection{Scratch boxes} |
| 1423 |
% |
| 1424 |
% \begin{variable}{\l_tmpa_box, \l_tmpb_box, \g_tmpa_box, \g_tmpb_box} |
| 1425 |
% Scratch boxes. |
| 1426 |
% \begin{macrocode} |
| 1427 |
\box_new:N \l_tmpa_box |
| 1428 |
\box_new:N \l_tmpb_box |
| 1429 |
\box_new:N \g_tmpa_box |
| 1430 |
\box_new:N \g_tmpb_box |
| 1431 |
% \end{macrocode} |
| 1432 |
% \end{variable} |
| 1433 |
% |
| 1434 |
% \subsection{Viewing box contents} |
| 1435 |
% |
| 1436 |
% \TeX{}'s \tn{showbox} is not really that helpful in many cases, and |
| 1437 |
% it is also inconsistent with other \LaTeX3{} \texttt{show} functions as it |
| 1438 |
% does not actually shows material in the terminal. So we provide a richer |
| 1439 |
% set of functionality. |
| 1440 |
% |
| 1441 |
% \begin{macro}{\box_show:N, \box_show:c} |
| 1442 |
% \begin{macro}{\box_show:Nnn, \box_show:cnn} |
| 1443 |
% Essentially a wrapper around the internal function, but evaluating |
| 1444 |
% the breadth and depth arguments now outside the group. |
| 1445 |
% \begin{macrocode} |
| 1446 |
\cs_new_protected:Npn \box_show:N #1 |
| 1447 |
{ \box_show:Nnn #1 \c_max_int \c_max_int } |
| 1448 |
\cs_generate_variant:Nn \box_show:N { c } |
| 1449 |
\cs_new_protected:Npn \box_show:Nnn #1#2#3 |
| 1450 |
{ \@@_show:NNff 1 #1 { \int_eval:n {#2} } { \int_eval:n {#3} } } |
| 1451 |
\cs_generate_variant:Nn \box_show:Nnn { c } |
| 1452 |
% \end{macrocode} |
| 1453 |
% \end{macro} |
| 1454 |
% \end{macro} |
| 1455 |
% |
| 1456 |
% \begin{macro}{\box_log:N, \box_log:c} |
| 1457 |
% \begin{macro}{\box_log:Nnn, \box_log:cnn} |
| 1458 |
% \begin{macro}{\@@_log:nNnn} |
| 1459 |
% Getting \TeX{} to write to the log without interruption the run is done by |
| 1460 |
% altering the interaction mode. For that, the \eTeX{} extensions are needed. |
| 1461 |
% \begin{macrocode} |
| 1462 |
\cs_new_protected:Npn \box_log:N #1 |
| 1463 |
{ \box_log:Nnn #1 \c_max_int \c_max_int } |
| 1464 |
\cs_generate_variant:Nn \box_log:N { c } |
| 1465 |
\cs_new_protected:Npn \box_log:Nnn |
| 1466 |
{ \exp_args:No \@@_log:nNnn { \tex_the:D \tex_interactionmode:D } } |
| 1467 |
\cs_new_protected:Npn \@@_log:nNnn #1#2#3#4 |
| 1468 |
{ |
| 1469 |
\int_gset:Nn \tex_interactionmode:D { 0 } |
| 1470 |
\@@_show:NNff 0 #2 { \int_eval:n {#3} } { \int_eval:n {#4} } |
| 1471 |
\int_gset:Nn \tex_interactionmode:D {#1} |
| 1472 |
} |
| 1473 |
\cs_generate_variant:Nn \box_log:Nnn { c } |
| 1474 |
% \end{macrocode} |
| 1475 |
% \end{macro} |
| 1476 |
% \end{macro} |
| 1477 |
% \end{macro} |
| 1478 |
% |
| 1479 |
% \begin{macro}{\@@_show:NNnn, \@@_show:NNff} |
| 1480 |
% The internal auxiliary to actually do the output uses a group to deal |
| 1481 |
% with breadth and depth values. The \cs{use:n} here gives better output |
| 1482 |
% appearance. Setting \tn{tracingonline} and \tn{errorcontextlines} is |
| 1483 |
% used to control what appears in the terminal. |
| 1484 |
% \begin{macrocode} |
| 1485 |
\cs_new_protected:Npn \@@_show:NNnn #1#2#3#4 |
| 1486 |
{ |
| 1487 |
\box_if_exist:NTF #2 |
| 1488 |
{ |
| 1489 |
\group_begin: |
| 1490 |
\int_set:Nn \tex_showboxbreadth:D {#3} |
| 1491 |
\int_set:Nn \tex_showboxdepth:D {#4} |
| 1492 |
\int_set:Nn \tex_tracingonline:D {#1} |
| 1493 |
\int_set:Nn \tex_errorcontextlines:D { -1 } |
| 1494 |
\tex_showbox:D \use:n {#2} |
| 1495 |
\group_end: |
| 1496 |
} |
| 1497 |
{ |
| 1498 |
\msg_error:nne { kernel } { variable-not-defined } |
| 1499 |
{ \token_to_str:N #2 } |
| 1500 |
} |
| 1501 |
} |
| 1502 |
\cs_generate_variant:Nn \@@_show:NNnn { NNff } |
| 1503 |
% \end{macrocode} |
| 1504 |
% \end{macro} |
| 1505 |
% |
| 1506 |
% \subsection{Horizontal mode boxes} |
| 1507 |
% |
| 1508 |
% \begin{macro}{\hbox:n} |
| 1509 |
% \testfile{m3box002.lvt} |
| 1510 |
% Put a horizontal box directly into the input stream. |
| 1511 |
% \begin{macrocode} |
| 1512 |
\cs_new_protected:Npn \hbox:n #1 |
| 1513 |
{ \tex_hbox:D \scan_stop: { \color_group_begin: #1 \color_group_end: } } |
| 1514 |
% \end{macrocode} |
| 1515 |
% \end{macro} |
| 1516 |
% |
| 1517 |
% \begin{macro}{\hbox_set:Nn, \hbox_set:cn} |
| 1518 |
% \begin{macro}{\hbox_gset:Nn, \hbox_gset:cn} |
| 1519 |
% \testfile* |
| 1520 |
% \begin{macrocode} |
| 1521 |
\cs_new_protected:Npn \hbox_set:Nn #1#2 |
| 1522 |
{ |
| 1523 |
\tex_setbox:D #1 \tex_hbox:D |
| 1524 |
{ \color_group_begin: #2 \color_group_end: } |
| 1525 |
} |
| 1526 |
\cs_new_protected:Npn \hbox_gset:Nn #1#2 |
| 1527 |
{ |
| 1528 |
\tex_global:D \tex_setbox:D #1 \tex_hbox:D |
| 1529 |
{ \color_group_begin: #2 \color_group_end: } |
| 1530 |
} |
| 1531 |
\cs_generate_variant:Nn \hbox_set:Nn { c } |
| 1532 |
\cs_generate_variant:Nn \hbox_gset:Nn { c } |
| 1533 |
% \end{macrocode} |
| 1534 |
% \end{macro} |
| 1535 |
% \end{macro} |
| 1536 |
% |
| 1537 |
% \begin{macro}{\hbox_set_to_wd:Nnn, \hbox_set_to_wd:cnn} |
| 1538 |
% \begin{macro}{\hbox_gset_to_wd:Nnn, \hbox_gset_to_wd:cnn} |
| 1539 |
% \testfile* |
| 1540 |
% Storing material in a horizontal box with a specified width. |
| 1541 |
% Again, put the dimension expression in parentheses when debugging. |
| 1542 |
% \begin{macrocode} |
| 1543 |
\cs_new_protected:Npn \hbox_set_to_wd:Nnn #1#2#3 |
| 1544 |
{ |
| 1545 |
\tex_setbox:D #1 \tex_hbox:D to \@@_dim_eval:n {#2} |
| 1546 |
{ \color_group_begin: #3 \color_group_end: } |
| 1547 |
} |
| 1548 |
\cs_new_protected:Npn \hbox_gset_to_wd:Nnn #1#2#3 |
| 1549 |
{ |
| 1550 |
\tex_global:D \tex_setbox:D #1 \tex_hbox:D to \@@_dim_eval:n {#2} |
| 1551 |
{ \color_group_begin: #3 \color_group_end: } |
| 1552 |
} |
| 1553 |
\cs_generate_variant:Nn \hbox_set_to_wd:Nnn { c } |
| 1554 |
\cs_generate_variant:Nn \hbox_gset_to_wd:Nnn { c } |
| 1555 |
% \end{macrocode} |
| 1556 |
% \end{macro} |
| 1557 |
% \end{macro} |
| 1558 |
% |
| 1559 |
% \begin{macro}{\hbox_set:Nw, \hbox_set:cw} |
| 1560 |
% \begin{macro}{\hbox_gset:Nw, \hbox_gset:cw} |
| 1561 |
% \begin{macro}{\hbox_set_end:, \hbox_gset_end:} |
| 1562 |
% \testfile* |
| 1563 |
% Storing material in a horizontal box. This type is useful in |
| 1564 |
% environment definitions. |
| 1565 |
% \begin{macrocode} |
| 1566 |
\cs_new_protected:Npn \hbox_set:Nw #1 |
| 1567 |
{ |
| 1568 |
\tex_setbox:D #1 \tex_hbox:D |
| 1569 |
\c_group_begin_token |
| 1570 |
\color_group_begin: |
| 1571 |
} |
| 1572 |
\cs_new_protected:Npn \hbox_gset:Nw #1 |
| 1573 |
{ |
| 1574 |
\tex_global:D \tex_setbox:D #1 \tex_hbox:D |
| 1575 |
\c_group_begin_token |
| 1576 |
\color_group_begin: |
| 1577 |
} |
| 1578 |
\cs_generate_variant:Nn \hbox_set:Nw { c } |
| 1579 |
\cs_generate_variant:Nn \hbox_gset:Nw { c } |
| 1580 |
\cs_new_protected:Npn \hbox_set_end: |
| 1581 |
{ |
| 1582 |
\color_group_end: |
| 1583 |
\c_group_end_token |
| 1584 |
} |
| 1585 |
\cs_new_eq:NN \hbox_gset_end: \hbox_set_end: |
| 1586 |
% \end{macrocode} |
| 1587 |
% \end{macro} |
| 1588 |
% \end{macro} |
| 1589 |
% \end{macro} |
| 1590 |
% |
| 1591 |
% \begin{macro}{\hbox_set_to_wd:Nnw, \hbox_set_to_wd:cnw} |
| 1592 |
% \begin{macro}{\hbox_gset_to_wd:Nnw, \hbox_gset_to_wd:cnw} |
| 1593 |
% Combining the above ideas. |
| 1594 |
% \begin{macrocode} |
| 1595 |
\cs_new_protected:Npn \hbox_set_to_wd:Nnw #1#2 |
| 1596 |
{ |
| 1597 |
\tex_setbox:D #1 \tex_hbox:D to \@@_dim_eval:n {#2} |
| 1598 |
\c_group_begin_token |
| 1599 |
\color_group_begin: |
| 1600 |
} |
| 1601 |
\cs_new_protected:Npn \hbox_gset_to_wd:Nnw #1#2 |
| 1602 |
{ |
| 1603 |
\tex_global:D \tex_setbox:D #1 \tex_hbox:D to \@@_dim_eval:n {#2} |
| 1604 |
\c_group_begin_token |
| 1605 |
\color_group_begin: |
| 1606 |
} |
| 1607 |
\cs_generate_variant:Nn \hbox_set_to_wd:Nnw { c } |
| 1608 |
\cs_generate_variant:Nn \hbox_gset_to_wd:Nnw { c } |
| 1609 |
% \end{macrocode} |
| 1610 |
% \end{macro} |
| 1611 |
% \end{macro} |
| 1612 |
% |
| 1613 |
% \begin{macro}{\hbox_to_wd:nn} |
| 1614 |
% \begin{macro}{\hbox_to_zero:n} |
| 1615 |
% \testfile* |
| 1616 |
% Put a horizontal box directly into the input stream. |
| 1617 |
% \begin{macrocode} |
| 1618 |
\cs_new_protected:Npn \hbox_to_wd:nn #1#2 |
| 1619 |
{ |
| 1620 |
\tex_hbox:D to \@@_dim_eval:n {#1} |
| 1621 |
{ \color_group_begin: #2 \color_group_end: } |
| 1622 |
} |
| 1623 |
\cs_new_protected:Npn \hbox_to_zero:n #1 |
| 1624 |
{ |
| 1625 |
\tex_hbox:D to \c_zero_dim |
| 1626 |
{ \color_group_begin: #1 \color_group_end: } |
| 1627 |
} |
| 1628 |
% \end{macrocode} |
| 1629 |
% \end{macro} |
| 1630 |
% \end{macro} |
| 1631 |
% |
| 1632 |
% \begin{macro}{\hbox_overlap_center:n, \hbox_overlap_left:n, \hbox_overlap_right:n} |
| 1633 |
% Put a zero-sized box with the contents pushed against one side (which |
| 1634 |
% makes it stick out on the other) directly into the input stream. |
| 1635 |
% \begin{macrocode} |
| 1636 |
\cs_new_protected:Npn \hbox_overlap_center:n #1 |
| 1637 |
{ \hbox_to_zero:n { \tex_hss:D #1 \tex_hss:D } } |
| 1638 |
\cs_new_protected:Npn \hbox_overlap_left:n #1 |
| 1639 |
{ \hbox_to_zero:n { \tex_hss:D #1 } } |
| 1640 |
\cs_new_protected:Npn \hbox_overlap_right:n #1 |
| 1641 |
{ \hbox_to_zero:n { #1 \tex_hss:D } } |
| 1642 |
% \end{macrocode} |
| 1643 |
% \end{macro} |
| 1644 |
% |
| 1645 |
% \begin{macro}{\hbox_unpack:N, \hbox_unpack:c} |
| 1646 |
% \begin{macro}{\hbox_unpack_drop:N, \hbox_unpack_drop:c} |
| 1647 |
% \testfile* |
| 1648 |
% Unpacking a box and if requested also clear it. |
| 1649 |
% \begin{macrocode} |
| 1650 |
\cs_new_eq:NN \hbox_unpack:N \tex_unhcopy:D |
| 1651 |
\cs_new_eq:NN \hbox_unpack_drop:N \tex_unhbox:D |
| 1652 |
\cs_generate_variant:Nn \hbox_unpack:N { c } |
| 1653 |
\cs_generate_variant:Nn \hbox_unpack_drop:N { c } |
| 1654 |
% \end{macrocode} |
| 1655 |
% \end{macro} |
| 1656 |
% \end{macro} |
| 1657 |
% |
| 1658 |
% \subsection{Vertical mode boxes} |
| 1659 |
% |
| 1660 |
% \TeX{} ends these boxes directly with the internal \emph{end_graf} |
| 1661 |
% routine. This means that there is no \cs{par} at the end of vertical |
| 1662 |
% boxes unless we insert one. Thus all vertical boxes include a \cs{par} |
| 1663 |
% just before closing the color group. |
| 1664 |
% |
| 1665 |
% \begin{macro}{\vbox:n, \vbox_top:n} |
| 1666 |
% \begin{macro}{\vbox:w, \vbox_top:w} |
| 1667 |
% \begin{macro}{\vbox_end:} |
| 1668 |
% Put a vertical box directly into the input stream. |
| 1669 |
% \begin{macrocode} |
| 1670 |
\cs_new_protected:Npn \vbox:n #1 |
| 1671 |
{ \tex_vbox:D { \color_group_begin: #1 \par \color_group_end: } } |
| 1672 |
\cs_new_protected:Npn \vbox_top:n #1 |
| 1673 |
{ \tex_vtop:D { \color_group_begin: #1 \par \color_group_end: } } |
| 1674 |
\cs_new_protected:Npn \vbox:w |
| 1675 |
{ \tex_vbox:D \c_group_begin_token \color_group_begin: } |
| 1676 |
\cs_new_protected:Npn \vbox_top:w |
| 1677 |
{ \tex_vtop:D \c_group_begin_token \color_group_begin: } |
| 1678 |
\cs_new_protected:Npn \vbox_end: |
| 1679 |
{ |
| 1680 |
\par |
| 1681 |
\color_group_end: |
| 1682 |
\c_group_end_token |
| 1683 |
} |
| 1684 |
% \end{macrocode} |
| 1685 |
% \end{macro} |
| 1686 |
% \end{macro} |
| 1687 |
% \end{macro} |
| 1688 |
% |
| 1689 |
% \begin{variable}{\l_@@_delta_dim, \l_@@_voffset_dim} |
| 1690 |
% Needed for the vertical centering calc. |
| 1691 |
% \begin{macrocode} |
| 1692 |
\dim_new:N \l_@@_delta_dim |
| 1693 |
\dim_new:N \l_@@_voffset_dim |
| 1694 |
% \end{macrocode} |
| 1695 |
% \end{variable} |
| 1696 |
% |
| 1697 |
% \begin{macro}{\vbox_center:nw} |
| 1698 |
% \begin{macro}{\vbox_center:w} |
| 1699 |
% \begin{macro}{\vbox_center_to_ht:nw} |
| 1700 |
% \begin{macro}{\@@_vcenter:nnw} |
| 1701 |
% \begin{macro}{\@@_vcenter_aux:} |
| 1702 |
% \begin{macro}{\vbox_center:nn} |
| 1703 |
% \begin{macro}{\vbox_center:n} |
| 1704 |
% \begin{macro}{\vbox_center_to_ht:nn} |
| 1705 |
% \begin{macro}{\@@_vcenter:Nnnn} |
| 1706 |
% \begin{macro}{\@@_vcenter_calc:n} |
| 1707 |
% This is set up first as the |:nw|/|:nn| version as that's \emph{required} |
| 1708 |
% to implement the |:n| one; contrast with the other two vertical |
| 1709 |
% placements, where we start with the simple case then build the more involved |
| 1710 |
% one. To avoid reading content multiple times, we use two internals for the |
| 1711 |
% |w| and |n| versions, then use a common auxiliary at the calculation stage. |
| 1712 |
% \begin{macrocode} |
| 1713 |
\cs_new_protected:Npn \vbox_center:nw |
| 1714 |
{ \@@_vcenter:nnw { } } |
| 1715 |
\cs_new_protected:Npn \vbox_center:w |
| 1716 |
{ \@@_vcenter:nnw { } \c_zero_dim } |
| 1717 |
\cs_new_protected:Npn \vbox_center_to_ht:nw #1 |
| 1718 |
{ \@@_vcenter:nnw { to \@@_dim_eval:n {#1} } \c_zero_dim } |
| 1719 |
% \end{macrocode} |
| 1720 |
% Starting the box with \cs{c_group_begin_token} avoids needing |
| 1721 |
% \tn{afterassignment} to get the end-of-group tokens in the correct |
| 1722 |
% place. |
| 1723 |
% \begin{macrocode} |
| 1724 |
\cs_new_protected:Npn \@@_vcenter:nnw #1#2 |
| 1725 |
{ |
| 1726 |
\dim_set:Nn \l_@@_voffset_dim {#2} |
| 1727 |
\tex_setbox:D \l_@@_tmp_box \tex_vbox:D #1 |
| 1728 |
\c_group_begin_token |
| 1729 |
\group_insert_after:N \@@_vcenter_aux: |
| 1730 |
\color_group_begin: |
| 1731 |
} |
| 1732 |
\cs_new_protected:Npn \@@_vcenter_aux: |
| 1733 |
{ \@@_vcenter_calc:n \l_@@_voffset_dim } |
| 1734 |
\cs_new_protected:Npn \vbox_center:nn |
| 1735 |
{ \@@_vcenter:Nnnn \vbox_set:Nn { } } |
| 1736 |
\cs_new_protected:Npn \vbox_center:n |
| 1737 |
{ \@@_vcenter:Nnnn \vbox_set:Nn { } \c_zero_dim } |
| 1738 |
\cs_new_protected:Npn \vbox_center_to_ht:nn #1 |
| 1739 |
{ \@@_vcenter:Nnnn \vbox_set_to_ht:Nnn { {#1} } \c_zero_dim } |
| 1740 |
\cs_new_protected:Npn \@@_vcenter:Nnnn #1#2#3#4 |
| 1741 |
{ |
| 1742 |
#1 \l_@@_tmp_box #2 {#4} |
| 1743 |
\@@_vcenter_calc:n {#3} |
| 1744 |
} |
| 1745 |
% \end{macrocode} |
| 1746 |
% To get exactly the same outcomes as \tn{vcenter}, we need to implement |
| 1747 |
% \emph{exactly} the approach used in \texttt{tex.web}: |
| 1748 |
% \begin{Verbatim}[gobble = 5] |
| 1749 |
% delta:=height(v)+depth(v); |
| 1750 |
% height(v):=axis_height(cur_size)+half(delta); |
| 1751 |
% depth(v):=delta-height(v); |
| 1752 |
% \end{Verbatim} |
| 1753 |
% where |
| 1754 |
% \begin{Verbatim}[gobble = 5] |
| 1755 |
% @p function half(@!x:integer):integer; |
| 1756 |
% begin if odd(x) then half:=(x+1) div 2 |
| 1757 |
% else half:=x @!div 2; |
| 1758 |
% end; |
| 1759 |
% \end{Verbatim} |
| 1760 |
% \begin{macrocode} |
| 1761 |
\cs_new_protected:Npn \@@_vcenter_calc:n #1 |
| 1762 |
{ |
| 1763 |
\dim_set:Nn \l_@@_delta_dim |
| 1764 |
{ \box_ht:N \l_@@_tmp_box + \box_dp:N \l_@@_tmp_box } |
| 1765 |
\tex_ht:D \l_@@_tmp_box \@@_dim_eval:n |
| 1766 |
{ |
| 1767 |
\@@_dim_eval:n |
| 1768 |
{ \tex_ifodd:D \l_@@_delta_dim 1sp + \tex_fi:D \l_@@_delta_dim } |
| 1769 |
/ 2 |
| 1770 |
+ (#1) |
| 1771 |
} |
| 1772 |
\tex_dp:D \l_@@_tmp_box \@@_dim_eval:n |
| 1773 |
{ \l_@@_delta_dim - \box_ht:N \l_@@_tmp_box } |
| 1774 |
\box_use_drop:N \l_@@_tmp_box |
| 1775 |
} |
| 1776 |
% \end{macrocode} |
| 1777 |
% \end{macro} |
| 1778 |
% \end{macro} |
| 1779 |
% \end{macro} |
| 1780 |
% \end{macro} |
| 1781 |
% \end{macro} |
| 1782 |
% \end{macro} |
| 1783 |
% \end{macro} |
| 1784 |
% \end{macro} |
| 1785 |
% \end{macro} |
| 1786 |
% \end{macro} |
| 1787 |
% |
| 1788 |
% \begin{macro}{\vbox_to_ht:nn, \vbox_top_to_ht:nn} |
| 1789 |
% \begin{macro}{\@@_to_ht:Nnn} |
| 1790 |
% \begin{macro}{\vbox_to_ht:nw, \vbox_top_to_ht:nw} |
| 1791 |
% \begin{macro}{\@@_to_ht:Nnw} |
| 1792 |
% \begin{macro}{\vbox_to_zero:n} |
| 1793 |
% \testfile* |
| 1794 |
% Put a vertical box directly into the input stream. |
| 1795 |
% \begin{macrocode} |
| 1796 |
\cs_new_protected:Npn \vbox_to_ht:nn #1#2 |
| 1797 |
{ \@@_to_ht:Nnn \tex_vbox:D {#1} {#2} } |
| 1798 |
\cs_new_protected:Npn \vbox_top_to_ht:nn #1#2 |
| 1799 |
{ \@@_to_ht:Nnn \tex_vtop:D {#1} {#2} } |
| 1800 |
\cs_new_protected:Npn \@@_to_ht:Nnn #1#2#3 |
| 1801 |
{ |
| 1802 |
#1 to \@@_dim_eval:n {#2} |
| 1803 |
{ \color_group_begin: #3 \par \color_group_end: } |
| 1804 |
} |
| 1805 |
\cs_new_protected:Npn \vbox_to_ht:nw #1 |
| 1806 |
{ \@@_to_ht:Nnw \tex_vbox:D {#1} } |
| 1807 |
\cs_new_protected:Npn \vbox_top_to_ht:nw #1 |
| 1808 |
{ \@@_to_ht:Nnw \tex_vtop:D {#1} } |
| 1809 |
\cs_new_protected:Npn \@@_to_ht:Nnw #1#2 |
| 1810 |
{ |
| 1811 |
#1 to \@@_dim_eval:n {#2} |
| 1812 |
\c_group_begin_token |
| 1813 |
\color_group_begin: |
| 1814 |
} |
| 1815 |
\cs_new_protected:Npn \vbox_to_zero:n #1 |
| 1816 |
{ \vbox_to_ht:nn { 0pt } {#1} } |
| 1817 |
% \end{macrocode} |
| 1818 |
% \end{macro} |
| 1819 |
% \end{macro} |
| 1820 |
% \end{macro} |
| 1821 |
% \end{macro} |
| 1822 |
% \end{macro} |
| 1823 |
% |
| 1824 |
% \begin{macro}{\vbox:nw, \vbox_top:nw} |
| 1825 |
% \begin{macro}{\@@_voffset:Nnnw} |
| 1826 |
% \begin{macro}{\@@_voffset_aux:} |
| 1827 |
% \begin{macro}{\vbox:nn, \vbox_top:nn} |
| 1828 |
% \begin{macro}{\@@_voffset:Nnnn} |
| 1829 |
% \begin{macro}{\@@_voffset_calc:n} |
| 1830 |
% Mainly for consistency of language. |
| 1831 |
% \begin{macrocode} |
| 1832 |
\cs_new_protected:Npn \vbox:nw |
| 1833 |
{ \@@_voffset:Nnnw \tex_vbox:D { } } |
| 1834 |
\cs_new_protected:Npn \vbox_top:nw |
| 1835 |
{ \@@_voffset:Nnnw \tex_vtop:D { } } |
| 1836 |
\cs_new_protected:Npn \@@_voffset:Nnnw #1#2#3 |
| 1837 |
{ |
| 1838 |
\dim_set:Nn \l_@@_voffset_dim {#3} |
| 1839 |
\tex_setbox:D \l_@@_tmp_box #1 #2 |
| 1840 |
\c_group_begin_token |
| 1841 |
\group_insert_after:N \@@_voffset_aux: |
| 1842 |
\color_group_begin: |
| 1843 |
} |
| 1844 |
\cs_new_protected:Npn \@@_voffset_aux: |
| 1845 |
{ \@@_voffset_calc:n \l_@@_voffset_dim } |
| 1846 |
\cs_new_protected:Npn \vbox:nn |
| 1847 |
{ \@@_voffset:Nnnn \vbox_set:Nn { } } |
| 1848 |
\cs_new_protected:Npn \vbox_top:nn |
| 1849 |
{ \@@_voffset:Nnnn \vbox_set_top:Nn { } } |
| 1850 |
\cs_new_protected:Npn \@@_voffset:Nnnn #1#2#3#4 |
| 1851 |
{ |
| 1852 |
#1 \l_@@_tmp_box #2 {#4} |
| 1853 |
\@@_voffset_calc:n {#3} |
| 1854 |
} |
| 1855 |
\cs_new_protected:Npn \@@_voffset_calc:n #1 |
| 1856 |
{ |
| 1857 |
\box_set_ht:Nn \l_@@_tmp_box |
| 1858 |
{ \box_ht:N \l_@@_tmp_box + (#1) } |
| 1859 |
\box_set_dp:Nn \l_@@_tmp_box |
| 1860 |
{ \box_dp:N \l_@@_tmp_box - (#1) } |
| 1861 |
\box_use_drop:N \l_@@_tmp_box |
| 1862 |
} |
| 1863 |
% \end{macrocode} |
| 1864 |
% \end{macro} |
| 1865 |
% \end{macro} |
| 1866 |
% \end{macro} |
| 1867 |
% \end{macro} |
| 1868 |
% \end{macro} |
| 1869 |
% \end{macro} |
| 1870 |
% |
| 1871 |
% \begin{macro}{\vbox_set:Nn, \vbox_set:cn} |
| 1872 |
% \begin{macro}{\vbox_gset:Nn, \vbox_gset:cn} |
| 1873 |
% \testfile* |
| 1874 |
% Storing material in a vertical box with a natural height. |
| 1875 |
% \begin{macrocode} |
| 1876 |
\cs_new_protected:Npn \vbox_set:Nn #1#2 |
| 1877 |
{ |
| 1878 |
\tex_setbox:D #1 \tex_vbox:D |
| 1879 |
{ \color_group_begin: #2 \par \color_group_end: } |
| 1880 |
} |
| 1881 |
\cs_new_protected:Npn \vbox_gset:Nn #1#2 |
| 1882 |
{ |
| 1883 |
\tex_global:D \tex_setbox:D #1 \tex_vbox:D |
| 1884 |
{ \color_group_begin: #2 \par \color_group_end: } |
| 1885 |
} |
| 1886 |
\cs_generate_variant:Nn \vbox_set:Nn { c } |
| 1887 |
\cs_generate_variant:Nn \vbox_gset:Nn { c } |
| 1888 |
% \end{macrocode} |
| 1889 |
% \end{macro} |
| 1890 |
% \end{macro} |
| 1891 |
% |
| 1892 |
% \begin{macro}{\vbox_set_top:Nn, \vbox_set_top:cn} |
| 1893 |
% \begin{macro}{\vbox_gset_top:Nn, \vbox_gset_top:cn} |
| 1894 |
% \testfile* |
| 1895 |
% Storing material in a vertical box with a natural height and reference |
| 1896 |
% point at the baseline of the first object in the box. |
| 1897 |
% \begin{macrocode} |
| 1898 |
\cs_new_protected:Npn \vbox_set_top:Nn #1#2 |
| 1899 |
{ |
| 1900 |
\tex_setbox:D #1 \tex_vtop:D |
| 1901 |
{ \color_group_begin: #2 \par \color_group_end: } |
| 1902 |
} |
| 1903 |
\cs_new_protected:Npn \vbox_gset_top:Nn #1#2 |
| 1904 |
{ |
| 1905 |
\tex_global:D \tex_setbox:D #1 \tex_vtop:D |
| 1906 |
{ \color_group_begin: #2 \par \color_group_end: } |
| 1907 |
} |
| 1908 |
\cs_generate_variant:Nn \vbox_set_top:Nn { c } |
| 1909 |
\cs_generate_variant:Nn \vbox_gset_top:Nn { c } |
| 1910 |
% \end{macrocode} |
| 1911 |
% \end{macro} |
| 1912 |
% \end{macro} |
| 1913 |
% |
| 1914 |
% \begin{macro}{\vbox_set_to_ht:Nnn, \vbox_set_to_ht:cnn} |
| 1915 |
% \begin{macro}{\vbox_gset_to_ht:Nnn, \vbox_gset_to_ht:cnn} |
| 1916 |
% \testfile* |
| 1917 |
% \begin{macrocode} |
| 1918 |
\cs_new_protected:Npn \vbox_set_to_ht:Nnn #1#2#3 |
| 1919 |
{ |
| 1920 |
\tex_setbox:D #1 \tex_vbox:D to \@@_dim_eval:n {#2} |
| 1921 |
{ \color_group_begin: #3 \par \color_group_end: } |
| 1922 |
} |
| 1923 |
\cs_new_protected:Npn \vbox_gset_to_ht:Nnn #1#2#3 |
| 1924 |
{ |
| 1925 |
\tex_global:D \tex_setbox:D #1 \tex_vbox:D to \@@_dim_eval:n {#2} |
| 1926 |
{ \color_group_begin: #3 \par \color_group_end: } |
| 1927 |
} |
| 1928 |
\cs_generate_variant:Nn \vbox_set_to_ht:Nnn { c } |
| 1929 |
\cs_generate_variant:Nn \vbox_gset_to_ht:Nnn { c } |
| 1930 |
% \end{macrocode} |
| 1931 |
% \end{macro} |
| 1932 |
% \end{macro} |
| 1933 |
% |
| 1934 |
% \begin{macro}{\vbox_set:Nw, \vbox_set:cw} |
| 1935 |
% \begin{macro}{\vbox_gset:Nw, \vbox_gset:cw} |
| 1936 |
% \begin{macro}{\vbox_set_end:, \vbox_gset_end:} |
| 1937 |
% \testfile* |
| 1938 |
% Storing material in a vertical box. This type is useful in |
| 1939 |
% environment definitions. |
| 1940 |
% \begin{macrocode} |
| 1941 |
\cs_new_protected:Npn \vbox_set:Nw #1 |
| 1942 |
{ |
| 1943 |
\tex_setbox:D #1 \tex_vbox:D |
| 1944 |
\c_group_begin_token |
| 1945 |
\color_group_begin: |
| 1946 |
} |
| 1947 |
\cs_new_protected:Npn \vbox_gset:Nw #1 |
| 1948 |
{ |
| 1949 |
\tex_global:D \tex_setbox:D #1 \tex_vbox:D |
| 1950 |
\c_group_begin_token |
| 1951 |
\color_group_begin: |
| 1952 |
} |
| 1953 |
\cs_generate_variant:Nn \vbox_set:Nw { c } |
| 1954 |
\cs_generate_variant:Nn \vbox_gset:Nw { c } |
| 1955 |
\cs_new_eq:NN \vbox_set_end: \vbox_end: |
| 1956 |
\cs_new_eq:NN \vbox_gset_end: \vbox_end: |
| 1957 |
% \end{macrocode} |
| 1958 |
% \end{macro} |
| 1959 |
% \end{macro} |
| 1960 |
% \end{macro} |
| 1961 |
% |
| 1962 |
% \begin{macro}{\vbox_set_to_ht:Nnw, \vbox_set_to_ht:cnw} |
| 1963 |
% \begin{macro}{\vbox_gset_to_ht:Nnw, \vbox_gset_to_ht:cnw} |
| 1964 |
% A combination of the above ideas. |
| 1965 |
% \begin{macrocode} |
| 1966 |
\cs_new_protected:Npn \vbox_set_to_ht:Nnw #1#2 |
| 1967 |
{ |
| 1968 |
\tex_setbox:D #1 \tex_vbox:D to \@@_dim_eval:n {#2} |
| 1969 |
\c_group_begin_token |
| 1970 |
\color_group_begin: |
| 1971 |
} |
| 1972 |
\cs_new_protected:Npn \vbox_gset_to_ht:Nnw #1#2 |
| 1973 |
{ |
| 1974 |
\tex_global:D \tex_setbox:D #1 \tex_vbox:D to \@@_dim_eval:n {#2} |
| 1975 |
\c_group_begin_token |
| 1976 |
\color_group_begin: |
| 1977 |
} |
| 1978 |
\cs_generate_variant:Nn \vbox_set_to_ht:Nnw { c } |
| 1979 |
\cs_generate_variant:Nn \vbox_gset_to_ht:Nnw { c } |
| 1980 |
% \end{macrocode} |
| 1981 |
% \end{macro} |
| 1982 |
% \end{macro} |
| 1983 |
% |
| 1984 |
% \begin{macro}{\vbox_unpack:N, \vbox_unpack:c} |
| 1985 |
% \begin{macro}{\vbox_unpack_drop:N, \vbox_unpack_drop:c} |
| 1986 |
% \testfile* |
| 1987 |
% Unpacking a box and if requested also clear it. |
| 1988 |
% \begin{macrocode} |
| 1989 |
\cs_new_eq:NN \vbox_unpack:N \tex_unvcopy:D |
| 1990 |
\cs_new_eq:NN \vbox_unpack_drop:N \tex_unvbox:D |
| 1991 |
\cs_generate_variant:Nn \vbox_unpack:N { c } |
| 1992 |
\cs_generate_variant:Nn \vbox_unpack_drop:N { c } |
| 1993 |
% \end{macrocode} |
| 1994 |
% \end{macro} |
| 1995 |
% \end{macro} |
| 1996 |
% |
| 1997 |
% \begin{macro} |
| 1998 |
% { |
| 1999 |
% \vbox_set_split_to_ht:NNn, \vbox_set_split_to_ht:cNn, |
| 2000 |
% \vbox_set_split_to_ht:Ncn, \vbox_set_split_to_ht:ccn, |
| 2001 |
% \vbox_gset_split_to_ht:NNn, \vbox_gset_split_to_ht:cNn, |
| 2002 |
% \vbox_gset_split_to_ht:Ncn, \vbox_gset_split_to_ht:ccn, |
| 2003 |
% } |
| 2004 |
% \testfile* |
| 2005 |
% Splitting a vertical box in two. |
| 2006 |
% \begin{macrocode} |
| 2007 |
\cs_new_protected:Npn \vbox_set_split_to_ht:NNn #1#2#3 |
| 2008 |
{ \tex_setbox:D #1 \tex_vsplit:D #2 to \@@_dim_eval:n {#3} } |
| 2009 |
\cs_generate_variant:Nn \vbox_set_split_to_ht:NNn { c , Nc , cc } |
| 2010 |
\cs_new_protected:Npn \vbox_gset_split_to_ht:NNn #1#2#3 |
| 2011 |
{ |
| 2012 |
\tex_global:D \tex_setbox:D #1 |
| 2013 |
\tex_vsplit:D #2 to \@@_dim_eval:n {#3} |
| 2014 |
} |
| 2015 |
\cs_generate_variant:Nn \vbox_gset_split_to_ht:NNn { c , Nc , cc } |
| 2016 |
% \end{macrocode} |
| 2017 |
% \end{macro} |
| 2018 |
% |
| 2019 |
% \subsection{Affine transformations} |
| 2020 |
% |
| 2021 |
% \begin{variable}{\l_@@_angle_fp} |
| 2022 |
% When rotating boxes, the angle itself may be needed by the |
| 2023 |
% engine-dependent code. This is done using the \pkg{fp} module so |
| 2024 |
% that the value is tidied up properly. |
| 2025 |
% \begin{macrocode} |
| 2026 |
\fp_new:N \l_@@_angle_fp |
| 2027 |
% \end{macrocode} |
| 2028 |
% \end{variable} |
| 2029 |
% |
| 2030 |
% \begin{variable}{\l_@@_cos_fp, \l_@@_sin_fp} |
| 2031 |
% These are used to hold the calculated sine and cosine values while |
| 2032 |
% carrying out a rotation. |
| 2033 |
% \begin{macrocode} |
| 2034 |
\fp_new:N \l_@@_cos_fp |
| 2035 |
\fp_new:N \l_@@_sin_fp |
| 2036 |
% \end{macrocode} |
| 2037 |
% \end{variable} |
| 2038 |
% |
| 2039 |
% \begin{variable} |
| 2040 |
% {\l_@@_top_dim, \l_@@_bottom_dim, \l_@@_left_dim, \l_@@_right_dim} |
| 2041 |
% These are the positions of the four edges of a box before |
| 2042 |
% manipulation. |
| 2043 |
% \begin{macrocode} |
| 2044 |
\dim_new:N \l_@@_top_dim |
| 2045 |
\dim_new:N \l_@@_bottom_dim |
| 2046 |
\dim_new:N \l_@@_left_dim |
| 2047 |
\dim_new:N \l_@@_right_dim |
| 2048 |
% \end{macrocode} |
| 2049 |
% \end{variable} |
| 2050 |
% |
| 2051 |
% \begin{variable} |
| 2052 |
% { |
| 2053 |
% \l_@@_top_new_dim, \l_@@_bottom_new_dim , |
| 2054 |
% \l_@@_left_new_dim, \l_@@_right_new_dim |
| 2055 |
% } |
| 2056 |
% These are the positions of the four edges of a box after |
| 2057 |
% manipulation. |
| 2058 |
% \begin{macrocode} |
| 2059 |
\dim_new:N \l_@@_top_new_dim |
| 2060 |
\dim_new:N \l_@@_bottom_new_dim |
| 2061 |
\dim_new:N \l_@@_left_new_dim |
| 2062 |
\dim_new:N \l_@@_right_new_dim |
| 2063 |
% \end{macrocode} |
| 2064 |
% \end{variable} |
| 2065 |
% |
| 2066 |
% \begin{variable}{\l_@@_tmp_box} |
| 2067 |
% Scratch space, but also needed by some parts of the driver. |
| 2068 |
% \begin{macrocode} |
| 2069 |
\box_new:N \l_@@_tmp_box |
| 2070 |
% \end{macrocode} |
| 2071 |
% \end{variable} |
| 2072 |
% |
| 2073 |
% \begin{macro} |
| 2074 |
% { |
| 2075 |
% \box_rotate:Nn, \box_rotate:cn, |
| 2076 |
% \box_grotate:Nn, \box_grotate:cn |
| 2077 |
% } |
| 2078 |
% \begin{macro}{\@@_rotate:NnN} |
| 2079 |
% \begin{macro}{\@@_rotate:N} |
| 2080 |
% \begin{macro}{\@@_rotate_xdir:nnN, \@@_rotate_ydir:nnN} |
| 2081 |
% \begin{macro} |
| 2082 |
% { |
| 2083 |
% \@@_rotate_quadrant_one:, \@@_rotate_quadrant_two:, |
| 2084 |
% \@@_rotate_quadrant_three:, \@@_rotate_quadrant_four: |
| 2085 |
% } |
| 2086 |
% Rotation of a box starts with working out the relevant sine and |
| 2087 |
% cosine. The actual rotation is in an auxiliary to keep the flow slightly |
| 2088 |
% clearer |
| 2089 |
% \begin{macrocode} |
| 2090 |
\cs_new_protected:Npn \box_rotate:Nn #1#2 |
| 2091 |
{ \@@_rotate:NnN #1 {#2} \hbox_set:Nn } |
| 2092 |
\cs_generate_variant:Nn \box_rotate:Nn { c } |
| 2093 |
\cs_new_protected:Npn \box_grotate:Nn #1#2 |
| 2094 |
{ \@@_rotate:NnN #1 {#2} \hbox_gset:Nn } |
| 2095 |
\cs_generate_variant:Nn \box_grotate:Nn { c } |
| 2096 |
\cs_new_protected:Npn \@@_rotate:NnN #1#2#3 |
| 2097 |
{ |
| 2098 |
#3 #1 |
| 2099 |
{ |
| 2100 |
\fp_set:Nn \l_@@_angle_fp {#2} |
| 2101 |
\fp_set:Nn \l_@@_sin_fp { sind ( \l_@@_angle_fp ) } |
| 2102 |
\fp_set:Nn \l_@@_cos_fp { cosd ( \l_@@_angle_fp ) } |
| 2103 |
\@@_rotate:N #1 |
| 2104 |
} |
| 2105 |
} |
| 2106 |
% \end{macrocode} |
| 2107 |
% The edges of the box are then recorded: the left edge is |
| 2108 |
% always at zero. Rotation of the four edges then takes place: this is |
| 2109 |
% most efficiently done on a quadrant by quadrant basis. |
| 2110 |
% \begin{macrocode} |
| 2111 |
\cs_new_protected:Npn \@@_rotate:N #1 |
| 2112 |
{ |
| 2113 |
\dim_set:Nn \l_@@_top_dim { \box_ht:N #1 } |
| 2114 |
\dim_set:Nn \l_@@_bottom_dim { -\box_dp:N #1 } |
| 2115 |
\dim_set:Nn \l_@@_right_dim { \box_wd:N #1 } |
| 2116 |
\dim_zero:N \l_@@_left_dim |
| 2117 |
% \end{macrocode} |
| 2118 |
% The next step is to work out the $x$ and $y$ coordinates of vertices of |
| 2119 |
% the rotated box in relation to its original coordinates. The box can be |
| 2120 |
% visualized with vertices $B$, $C$, $D$ and $E$ is illustrated |
| 2121 |
% (Figure~\ref{fig:l3box:rotation}). The vertex $O$ is the reference point |
| 2122 |
% on the baseline, and in this implementation is also the center of rotation. |
| 2123 |
% \begin{figure} |
| 2124 |
% \centering |
| 2125 |
% \setlength{\unitlength}{3pt}^^A |
| 2126 |
% \begin{picture}(34,36)(12,44) |
| 2127 |
% \thicklines |
| 2128 |
% \put(20,52){\dashbox{1}(20,21){}} |
| 2129 |
% \put(20,80){\line(0,-1){36}} |
| 2130 |
% \put(12,58){\line(1, 0){34}} |
| 2131 |
% \put(41,59){A} |
| 2132 |
% \put(40,74){B} |
| 2133 |
% \put(21,74){C} |
| 2134 |
% \put(21,49){D} |
| 2135 |
% \put(40,49){E} |
| 2136 |
% \put(21,59){O} |
| 2137 |
% \end{picture} |
| 2138 |
% \caption{Coordinates of a box prior to rotation.} |
| 2139 |
% \label{fig:l3box:rotation} |
| 2140 |
% \end{figure} |
| 2141 |
% The formulae are, for a point $P$ and angle $\alpha$: |
| 2142 |
% \[ |
| 2143 |
% \begin{array}{l} |
| 2144 |
% P'_x = P_x - O_x \\ |
| 2145 |
% P'_y = P_y - O_y \\ |
| 2146 |
% P''_x = ( P'_x \cos(\alpha)) - ( P'_y \sin(\alpha) ) \\ |
| 2147 |
% P''_y = ( P'_x \sin(\alpha)) + ( P'_y \cos(\alpha) ) \\ |
| 2148 |
% P'''_x = P''_x + O_x + L_x \\ |
| 2149 |
% P'''_y = P''_y + O_y |
| 2150 |
% \end{array} |
| 2151 |
% \] |
| 2152 |
% The \enquote{extra} horizontal translation $L_x$ at the end is calculated |
| 2153 |
% so that the leftmost point of the resulting box has $x$-coordinate $0$. |
| 2154 |
% This is desirable as \TeX{} boxes must have the reference point at |
| 2155 |
% the left edge of the box. (As $O$ is always $(0,0)$, this part of the |
| 2156 |
% calculation is omitted here.) |
| 2157 |
% \begin{macrocode} |
| 2158 |
\fp_compare:nNnTF \l_@@_sin_fp > \c_zero_fp |
| 2159 |
{ |
| 2160 |
\fp_compare:nNnTF \l_@@_cos_fp > \c_zero_fp |
| 2161 |
{ \@@_rotate_quadrant_one: } |
| 2162 |
{ \@@_rotate_quadrant_two: } |
| 2163 |
} |
| 2164 |
{ |
| 2165 |
\fp_compare:nNnTF \l_@@_cos_fp < \c_zero_fp |
| 2166 |
{ \@@_rotate_quadrant_three: } |
| 2167 |
{ \@@_rotate_quadrant_four: } |
| 2168 |
} |
| 2169 |
% \end{macrocode} |
| 2170 |
% The position of the box edges are now known, but the box at this |
| 2171 |
% stage be misplaced relative to the current \TeX{} reference point. So the |
| 2172 |
% content of the box is moved such that the reference point of the |
| 2173 |
% rotated box is in the same place as the original. |
| 2174 |
% \begin{macrocode} |
| 2175 |
\hbox_set:Nn \l_@@_tmp_box { \box_use:N #1 } |
| 2176 |
\hbox_set:Nn \l_@@_tmp_box |
| 2177 |
{ |
| 2178 |
\dim_horizontal:n { -\l_@@_left_new_dim } |
| 2179 |
\hbox:n |
| 2180 |
{ |
| 2181 |
\@@_backend_rotate:Nn |
| 2182 |
\l_@@_tmp_box |
| 2183 |
\l_@@_angle_fp |
| 2184 |
} |
| 2185 |
} |
| 2186 |
% \end{macrocode} |
| 2187 |
% Tidy up the size of the box so that the material is actually inside |
| 2188 |
% the bounding box. The result can then be used to reset the original |
| 2189 |
% box. |
| 2190 |
% \begin{macrocode} |
| 2191 |
\box_set_ht:Nn \l_@@_tmp_box { \l_@@_top_new_dim } |
| 2192 |
\box_set_dp:Nn \l_@@_tmp_box { -\l_@@_bottom_new_dim } |
| 2193 |
\box_set_wd:Nn \l_@@_tmp_box |
| 2194 |
{ \l_@@_right_new_dim - \l_@@_left_new_dim } |
| 2195 |
\box_use_drop:N \l_@@_tmp_box |
| 2196 |
} |
| 2197 |
% \end{macrocode} |
| 2198 |
% \end{macro} |
| 2199 |
% \end{macro} |
| 2200 |
% These functions take a general point $(|#1|, |#2|)$ and rotate its |
| 2201 |
% location about the origin, using the previously-set sine and cosine |
| 2202 |
% values. Each function gives only one component of the location of the |
| 2203 |
% updated point. This is because for rotation of a box each step needs |
| 2204 |
% only one value, and so performance is gained by avoiding working |
| 2205 |
% out both $x'$ and $y'$ at the same time. Contrast this with |
| 2206 |
% the equivalent function in the \pkg{l3coffins} module, where both parts |
| 2207 |
% are needed. |
| 2208 |
% \begin{macrocode} |
| 2209 |
\cs_new_protected:Npn \@@_rotate_xdir:nnN #1#2#3 |
| 2210 |
{ |
| 2211 |
\dim_set:Nn #3 |
| 2212 |
{ |
| 2213 |
\fp_to_dim:n |
| 2214 |
{ |
| 2215 |
\l_@@_cos_fp * \dim_to_fp:n {#1} |
| 2216 |
- \l_@@_sin_fp * \dim_to_fp:n {#2} |
| 2217 |
} |
| 2218 |
} |
| 2219 |
} |
| 2220 |
\cs_new_protected:Npn \@@_rotate_ydir:nnN #1#2#3 |
| 2221 |
{ |
| 2222 |
\dim_set:Nn #3 |
| 2223 |
{ |
| 2224 |
\fp_to_dim:n |
| 2225 |
{ |
| 2226 |
\l_@@_sin_fp * \dim_to_fp:n {#1} |
| 2227 |
+ \l_@@_cos_fp * \dim_to_fp:n {#2} |
| 2228 |
} |
| 2229 |
} |
| 2230 |
} |
| 2231 |
% \end{macrocode} |
| 2232 |
% Rotation of the edges is done using a different formula for each |
| 2233 |
% quadrant. In every case, the top and bottom edges only need the |
| 2234 |
% resulting $y$-values, whereas the left and right edges need the |
| 2235 |
% $x$-values. Each case is a question of picking out which corner |
| 2236 |
% ends up at with the maximum top, bottom, left and right value. Doing |
| 2237 |
% this by hand means a lot less calculating and avoids lots of |
| 2238 |
% comparisons. |
| 2239 |
% \begin{macrocode} |
| 2240 |
\cs_new_protected:Npn \@@_rotate_quadrant_one: |
| 2241 |
{ |
| 2242 |
\@@_rotate_ydir:nnN \l_@@_right_dim \l_@@_top_dim |
| 2243 |
\l_@@_top_new_dim |
| 2244 |
\@@_rotate_ydir:nnN \l_@@_left_dim \l_@@_bottom_dim |
| 2245 |
\l_@@_bottom_new_dim |
| 2246 |
\@@_rotate_xdir:nnN \l_@@_left_dim \l_@@_top_dim |
| 2247 |
\l_@@_left_new_dim |
| 2248 |
\@@_rotate_xdir:nnN \l_@@_right_dim \l_@@_bottom_dim |
| 2249 |
\l_@@_right_new_dim |
| 2250 |
} |
| 2251 |
\cs_new_protected:Npn \@@_rotate_quadrant_two: |
| 2252 |
{ |
| 2253 |
\@@_rotate_ydir:nnN \l_@@_right_dim \l_@@_bottom_dim |
| 2254 |
\l_@@_top_new_dim |
| 2255 |
\@@_rotate_ydir:nnN \l_@@_left_dim \l_@@_top_dim |
| 2256 |
\l_@@_bottom_new_dim |
| 2257 |
\@@_rotate_xdir:nnN \l_@@_right_dim \l_@@_top_dim |
| 2258 |
\l_@@_left_new_dim |
| 2259 |
\@@_rotate_xdir:nnN \l_@@_left_dim \l_@@_bottom_dim |
| 2260 |
\l_@@_right_new_dim |
| 2261 |
} |
| 2262 |
\cs_new_protected:Npn \@@_rotate_quadrant_three: |
| 2263 |
{ |
| 2264 |
\@@_rotate_ydir:nnN \l_@@_left_dim \l_@@_bottom_dim |
| 2265 |
\l_@@_top_new_dim |
| 2266 |
\@@_rotate_ydir:nnN \l_@@_right_dim \l_@@_top_dim |
| 2267 |
\l_@@_bottom_new_dim |
| 2268 |
\@@_rotate_xdir:nnN \l_@@_right_dim \l_@@_bottom_dim |
| 2269 |
\l_@@_left_new_dim |
| 2270 |
\@@_rotate_xdir:nnN \l_@@_left_dim \l_@@_top_dim |
| 2271 |
\l_@@_right_new_dim |
| 2272 |
} |
| 2273 |
\cs_new_protected:Npn \@@_rotate_quadrant_four: |
| 2274 |
{ |
| 2275 |
\@@_rotate_ydir:nnN \l_@@_left_dim \l_@@_top_dim |
| 2276 |
\l_@@_top_new_dim |
| 2277 |
\@@_rotate_ydir:nnN \l_@@_right_dim \l_@@_bottom_dim |
| 2278 |
\l_@@_bottom_new_dim |
| 2279 |
\@@_rotate_xdir:nnN \l_@@_left_dim \l_@@_bottom_dim |
| 2280 |
\l_@@_left_new_dim |
| 2281 |
\@@_rotate_xdir:nnN \l_@@_right_dim \l_@@_top_dim |
| 2282 |
\l_@@_right_new_dim |
| 2283 |
} |
| 2284 |
% \end{macrocode} |
| 2285 |
% \end{macro} |
| 2286 |
% \end{macro} |
| 2287 |
% \end{macro} |
| 2288 |
% |
| 2289 |
% \begin{variable}{\l_@@_scale_x_fp, \l_@@_scale_y_fp} |
| 2290 |
% Scaling is potentially-different in the two axes. |
| 2291 |
% \begin{macrocode} |
| 2292 |
\fp_new:N \l_@@_scale_x_fp |
| 2293 |
\fp_new:N \l_@@_scale_y_fp |
| 2294 |
% \end{macrocode} |
| 2295 |
% \end{variable} |
| 2296 |
% |
| 2297 |
% \begin{macro} |
| 2298 |
% { |
| 2299 |
% \box_resize_to_wd_and_ht_plus_dp:Nnn, |
| 2300 |
% \box_resize_to_wd_and_ht_plus_dp:cnn, |
| 2301 |
% \box_gresize_to_wd_and_ht_plus_dp:Nnn, |
| 2302 |
% \box_gresize_to_wd_and_ht_plus_dp:cnn |
| 2303 |
% } |
| 2304 |
% \begin{macro}{\@@_resize_to_wd_and_ht_plus_dp:NnnN} |
| 2305 |
% \begin{macro}{\@@_resize_set_corners:N} |
| 2306 |
% \begin{macro}{\@@_resize:N} |
| 2307 |
% \begin{macro}{\@@_resize:NNN} |
| 2308 |
% Resizing a box starts by working out the various dimensions of the |
| 2309 |
% existing box. |
| 2310 |
% \begin{macrocode} |
| 2311 |
\cs_new_protected:Npn \box_resize_to_wd_and_ht_plus_dp:Nnn #1#2#3 |
| 2312 |
{ |
| 2313 |
\@@_resize_to_wd_and_ht_plus_dp:NnnN #1 {#2} {#3} |
| 2314 |
\hbox_set:Nn |
| 2315 |
} |
| 2316 |
\cs_generate_variant:Nn \box_resize_to_wd_and_ht_plus_dp:Nnn { c } |
| 2317 |
\cs_new_protected:Npn \box_gresize_to_wd_and_ht_plus_dp:Nnn #1#2#3 |
| 2318 |
{ |
| 2319 |
\@@_resize_to_wd_and_ht_plus_dp:NnnN #1 {#2} {#3} |
| 2320 |
\hbox_gset:Nn |
| 2321 |
} |
| 2322 |
\cs_generate_variant:Nn \box_gresize_to_wd_and_ht_plus_dp:Nnn { c } |
| 2323 |
\cs_new_protected:Npn \@@_resize_to_wd_and_ht_plus_dp:NnnN #1#2#3#4 |
| 2324 |
{ |
| 2325 |
#4 #1 |
| 2326 |
{ |
| 2327 |
\@@_resize_set_corners:N #1 |
| 2328 |
% \end{macrocode} |
| 2329 |
% The $x$-scaling and resulting box size is easy enough to work |
| 2330 |
% out: the dimension is that given as |#2|, and the scale is simply the |
| 2331 |
% new width divided by the old one. |
| 2332 |
% \begin{macrocode} |
| 2333 |
\fp_set:Nn \l_@@_scale_x_fp |
| 2334 |
{ \dim_to_fp:n {#2} / \dim_to_fp:n { \l_@@_right_dim } } |
| 2335 |
% \end{macrocode} |
| 2336 |
% The $y$-scaling needs both the height and the depth of the current box. |
| 2337 |
% \begin{macrocode} |
| 2338 |
\fp_set:Nn \l_@@_scale_y_fp |
| 2339 |
{ |
| 2340 |
\dim_to_fp:n {#3} |
| 2341 |
/ \dim_to_fp:n { \l_@@_top_dim - \l_@@_bottom_dim } |
| 2342 |
} |
| 2343 |
% \end{macrocode} |
| 2344 |
% Hand off to the auxiliary which does the rest of the work. |
| 2345 |
% \begin{macrocode} |
| 2346 |
\@@_resize:N #1 |
| 2347 |
} |
| 2348 |
} |
| 2349 |
\cs_new_protected:Npn \@@_resize_set_corners:N #1 |
| 2350 |
{ |
| 2351 |
\dim_set:Nn \l_@@_top_dim { \box_ht:N #1 } |
| 2352 |
\dim_set:Nn \l_@@_bottom_dim { -\box_dp:N #1 } |
| 2353 |
\dim_set:Nn \l_@@_right_dim { \box_wd:N #1 } |
| 2354 |
\dim_zero:N \l_@@_left_dim |
| 2355 |
} |
| 2356 |
% \end{macrocode} |
| 2357 |
% With at least one real scaling to do, the next phase is to find the new |
| 2358 |
% edge coordinates. In the $x$~direction this is relatively easy: just |
| 2359 |
% scale the right edge. In the $y$~direction, both dimensions have to be |
| 2360 |
% scaled, and this again needs the absolute scale value. |
| 2361 |
% Once that is all done, the common resize/rescale code can be employed. |
| 2362 |
% \begin{macrocode} |
| 2363 |
\cs_new_protected:Npn \@@_resize:N #1 |
| 2364 |
{ |
| 2365 |
\@@_resize:NNN \l_@@_right_new_dim |
| 2366 |
\l_@@_scale_x_fp \l_@@_right_dim |
| 2367 |
\@@_resize:NNN \l_@@_bottom_new_dim |
| 2368 |
\l_@@_scale_y_fp \l_@@_bottom_dim |
| 2369 |
\@@_resize:NNN \l_@@_top_new_dim |
| 2370 |
\l_@@_scale_y_fp \l_@@_top_dim |
| 2371 |
\@@_resize_common:N #1 |
| 2372 |
} |
| 2373 |
\cs_new_protected:Npn \@@_resize:NNN #1#2#3 |
| 2374 |
{ |
| 2375 |
\dim_set:Nn #1 |
| 2376 |
{ \fp_to_dim:n { \fp_abs:n { #2 } * \dim_to_fp:n { #3 } } } |
| 2377 |
} |
| 2378 |
% \end{macrocode} |
| 2379 |
% \end{macro} |
| 2380 |
% \end{macro} |
| 2381 |
% \end{macro} |
| 2382 |
% \end{macro} |
| 2383 |
% \end{macro} |
| 2384 |
% |
| 2385 |
% \begin{macro} |
| 2386 |
% { |
| 2387 |
% \box_resize_to_ht:Nn, \box_resize_to_ht:cn, |
| 2388 |
% \box_gresize_to_ht:Nn, \box_gresize_to_ht:cn |
| 2389 |
% } |
| 2390 |
% \begin{macro}{\@@_resize_to_ht:NnN} |
| 2391 |
% \begin{macro} |
| 2392 |
% { |
| 2393 |
% \box_resize_to_ht_plus_dp:Nn, \box_resize_to_ht_plus_dp:cn, |
| 2394 |
% \box_gresize_to_ht_plus_dp:Nn, \box_gresize_to_ht_plus_dp:cn |
| 2395 |
% } |
| 2396 |
% \begin{macro}{\@@_resize_to_ht_plus_dp:NnN} |
| 2397 |
% \begin{macro} |
| 2398 |
% { |
| 2399 |
% \box_resize_to_wd:Nn, \box_resize_to_wd:cn, |
| 2400 |
% \box_gresize_to_wd:Nn, \box_gresize_to_wd:cn |
| 2401 |
% } |
| 2402 |
% \begin{macro}{\@@_resize_to_wd:NnN} |
| 2403 |
% \begin{macro} |
| 2404 |
% { |
| 2405 |
% \box_resize_to_wd_and_ht:Nnn, \box_resize_to_wd_and_ht:cnn, |
| 2406 |
% \box_gresize_to_wd_and_ht:Nnn, \box_gresize_to_wd_and_ht:cnn |
| 2407 |
% } |
| 2408 |
% \begin{macro}{\@@_resize_to_wd_ht:NnnN} |
| 2409 |
% Scaling to a (total) height or to a width is a simplified version of the main |
| 2410 |
% resizing operation, with the scale simply copied between the two parts. The |
| 2411 |
% internal auxiliary is called using the scaling value twice, as the sign for |
| 2412 |
% both parts is needed (as this allows the same internal code to be used as |
| 2413 |
% for the general case). |
| 2414 |
% \begin{macrocode} |
| 2415 |
\cs_new_protected:Npn \box_resize_to_ht:Nn #1#2 |
| 2416 |
{ \@@_resize_to_ht:NnN #1 {#2} \hbox_set:Nn } |
| 2417 |
\cs_generate_variant:Nn \box_resize_to_ht:Nn { c } |
| 2418 |
\cs_new_protected:Npn \box_gresize_to_ht:Nn #1#2 |
| 2419 |
{ \@@_resize_to_ht:NnN #1 {#2} \hbox_gset:Nn } |
| 2420 |
\cs_generate_variant:Nn \box_gresize_to_ht:Nn { c } |
| 2421 |
\cs_new_protected:Npn \@@_resize_to_ht:NnN #1#2#3 |
| 2422 |
{ |
| 2423 |
#3 #1 |
| 2424 |
{ |
| 2425 |
\@@_resize_set_corners:N #1 |
| 2426 |
\fp_set:Nn \l_@@_scale_y_fp |
| 2427 |
{ |
| 2428 |
\dim_to_fp:n {#2} |
| 2429 |
/ \dim_to_fp:n { \l_@@_top_dim } |
| 2430 |
} |
| 2431 |
\fp_set_eq:NN \l_@@_scale_x_fp \l_@@_scale_y_fp |
| 2432 |
\@@_resize:N #1 |
| 2433 |
} |
| 2434 |
} |
| 2435 |
\cs_new_protected:Npn \box_resize_to_ht_plus_dp:Nn #1#2 |
| 2436 |
{ \@@_resize_to_ht_plus_dp:NnN #1 {#2} \hbox_set:Nn } |
| 2437 |
\cs_generate_variant:Nn \box_resize_to_ht_plus_dp:Nn { c } |
| 2438 |
\cs_new_protected:Npn \box_gresize_to_ht_plus_dp:Nn #1#2 |
| 2439 |
{ \@@_resize_to_ht_plus_dp:NnN #1 {#2} \hbox_gset:Nn } |
| 2440 |
\cs_generate_variant:Nn \box_gresize_to_ht_plus_dp:Nn { c } |
| 2441 |
\cs_new_protected:Npn \@@_resize_to_ht_plus_dp:NnN #1#2#3 |
| 2442 |
{ |
| 2443 |
#3 #1 |
| 2444 |
{ |
| 2445 |
\@@_resize_set_corners:N #1 |
| 2446 |
\fp_set:Nn \l_@@_scale_y_fp |
| 2447 |
{ |
| 2448 |
\dim_to_fp:n {#2} |
| 2449 |
/ \dim_to_fp:n { \l_@@_top_dim - \l_@@_bottom_dim } |
| 2450 |
} |
| 2451 |
\fp_set_eq:NN \l_@@_scale_x_fp \l_@@_scale_y_fp |
| 2452 |
\@@_resize:N #1 |
| 2453 |
} |
| 2454 |
} |
| 2455 |
\cs_new_protected:Npn \box_resize_to_wd:Nn #1#2 |
| 2456 |
{ \@@_resize_to_wd:NnN #1 {#2} \hbox_set:Nn } |
| 2457 |
\cs_generate_variant:Nn \box_resize_to_wd:Nn { c } |
| 2458 |
\cs_new_protected:Npn \box_gresize_to_wd:Nn #1#2 |
| 2459 |
{ \@@_resize_to_wd:NnN #1 {#2} \hbox_gset:Nn } |
| 2460 |
\cs_generate_variant:Nn \box_gresize_to_wd:Nn { c } |
| 2461 |
\cs_new_protected:Npn \@@_resize_to_wd:NnN #1#2#3 |
| 2462 |
{ |
| 2463 |
#3 #1 |
| 2464 |
{ |
| 2465 |
\@@_resize_set_corners:N #1 |
| 2466 |
\fp_set:Nn \l_@@_scale_x_fp |
| 2467 |
{ \dim_to_fp:n {#2} / \dim_to_fp:n { \l_@@_right_dim } } |
| 2468 |
\fp_set_eq:NN \l_@@_scale_y_fp \l_@@_scale_x_fp |
| 2469 |
\@@_resize:N #1 |
| 2470 |
} |
| 2471 |
} |
| 2472 |
\cs_new_protected:Npn \box_resize_to_wd_and_ht:Nnn #1#2#3 |
| 2473 |
{ \@@_resize_to_wd_and_ht:NnnN #1 {#2} {#3} \hbox_set:Nn } |
| 2474 |
\cs_generate_variant:Nn \box_resize_to_wd_and_ht:Nnn { c } |
| 2475 |
\cs_new_protected:Npn \box_gresize_to_wd_and_ht:Nnn #1#2#3 |
| 2476 |
{ \@@_resize_to_wd_and_ht:NnnN #1 {#2} {#3} \hbox_gset:Nn } |
| 2477 |
\cs_generate_variant:Nn \box_gresize_to_wd_and_ht:Nnn { c } |
| 2478 |
\cs_new_protected:Npn \@@_resize_to_wd_and_ht:NnnN #1#2#3#4 |
| 2479 |
{ |
| 2480 |
#4 #1 |
| 2481 |
{ |
| 2482 |
\@@_resize_set_corners:N #1 |
| 2483 |
\fp_set:Nn \l_@@_scale_x_fp |
| 2484 |
{ \dim_to_fp:n {#2} / \dim_to_fp:n { \l_@@_right_dim } } |
| 2485 |
\fp_set:Nn \l_@@_scale_y_fp |
| 2486 |
{ |
| 2487 |
\dim_to_fp:n {#3} |
| 2488 |
/ \dim_to_fp:n { \l_@@_top_dim } |
| 2489 |
} |
| 2490 |
\@@_resize:N #1 |
| 2491 |
} |
| 2492 |
} |
| 2493 |
% \end{macrocode} |
| 2494 |
% \end{macro} |
| 2495 |
% \end{macro} |
| 2496 |
% \end{macro} |
| 2497 |
% \end{macro} |
| 2498 |
% \end{macro} |
| 2499 |
% \end{macro} |
| 2500 |
% \end{macro} |
| 2501 |
% \end{macro} |
| 2502 |
% |
| 2503 |
% \begin{macro} |
| 2504 |
% { |
| 2505 |
% \box_scale:Nnn, \box_scale:cnn, |
| 2506 |
% \box_gscale:Nnn, \box_gscale:cnn |
| 2507 |
% } |
| 2508 |
% \begin{macro}{\@@_scale:NnnN} |
| 2509 |
% \begin{macro}{\@@_scale:N} |
| 2510 |
% When scaling a box, setting the scaling itself is easy enough. The |
| 2511 |
% new dimensions are also relatively easy to find, allowing only for |
| 2512 |
% the need to keep them positive in all cases. Once that is done then |
| 2513 |
% after a check for the trivial scaling a hand-off can be made to the |
| 2514 |
% common code. The code here is split into two as this allows sharing |
| 2515 |
% with the auto-resizing functions. |
| 2516 |
% \begin{macrocode} |
| 2517 |
\cs_new_protected:Npn \box_scale:Nnn #1#2#3 |
| 2518 |
{ \@@_scale:NnnN #1 {#2} {#3} \hbox_set:Nn } |
| 2519 |
\cs_generate_variant:Nn \box_scale:Nnn { c } |
| 2520 |
\cs_new_protected:Npn \box_gscale:Nnn #1#2#3 |
| 2521 |
{ \@@_scale:NnnN #1 {#2} {#3} \hbox_gset:Nn } |
| 2522 |
\cs_generate_variant:Nn \box_gscale:Nnn { c } |
| 2523 |
\cs_new_protected:Npn \@@_scale:NnnN #1#2#3#4 |
| 2524 |
{ |
| 2525 |
#4 #1 |
| 2526 |
{ |
| 2527 |
\fp_set:Nn \l_@@_scale_x_fp {#2} |
| 2528 |
\fp_set:Nn \l_@@_scale_y_fp {#3} |
| 2529 |
\@@_scale:N #1 |
| 2530 |
} |
| 2531 |
} |
| 2532 |
\cs_new_protected:Npn \@@_scale:N #1 |
| 2533 |
{ |
| 2534 |
\dim_set:Nn \l_@@_top_dim { \box_ht:N #1 } |
| 2535 |
\dim_set:Nn \l_@@_bottom_dim { -\box_dp:N #1 } |
| 2536 |
\dim_set:Nn \l_@@_right_dim { \box_wd:N #1 } |
| 2537 |
\dim_zero:N \l_@@_left_dim |
| 2538 |
\dim_set:Nn \l_@@_top_new_dim |
| 2539 |
{ \fp_abs:n { \l_@@_scale_y_fp } \l_@@_top_dim } |
| 2540 |
\dim_set:Nn \l_@@_bottom_new_dim |
| 2541 |
{ \fp_abs:n { \l_@@_scale_y_fp } \l_@@_bottom_dim } |
| 2542 |
\dim_set:Nn \l_@@_right_new_dim |
| 2543 |
{ \fp_abs:n { \l_@@_scale_x_fp } \l_@@_right_dim } |
| 2544 |
\@@_resize_common:N #1 |
| 2545 |
} |
| 2546 |
% \end{macrocode} |
| 2547 |
% \end{macro} |
| 2548 |
% \end{macro} |
| 2549 |
% \end{macro} |
| 2550 |
% |
| 2551 |
% \begin{macro} |
| 2552 |
% { |
| 2553 |
% \box_autosize_to_wd_and_ht:Nnn , |
| 2554 |
% \box_autosize_to_wd_and_ht:cnn , |
| 2555 |
% \box_gautosize_to_wd_and_ht:Nnn , |
| 2556 |
% \box_gautosize_to_wd_and_ht:cnn , |
| 2557 |
% \box_autosize_to_wd_and_ht_plus_dp:Nnn , |
| 2558 |
% \box_autosize_to_wd_and_ht_plus_dp:cnn , |
| 2559 |
% \box_gautosize_to_wd_and_ht_plus_dp:Nnn , |
| 2560 |
% \box_gautosize_to_wd_and_ht_plus_dp:cnn |
| 2561 |
% } |
| 2562 |
% \begin{macro}{\@@_autosize:NnnnN} |
| 2563 |
% Although autosizing a box uses dimensions, it has more in common in |
| 2564 |
% implementation with scaling. As such, most of the real work here is |
| 2565 |
% done elsewhere. |
| 2566 |
% \begin{macrocode} |
| 2567 |
\cs_new_protected:Npn \box_autosize_to_wd_and_ht:Nnn #1#2#3 |
| 2568 |
{ \@@_autosize:NnnnN #1 {#2} {#3} { \box_ht:N #1 } \hbox_set:Nn } |
| 2569 |
\cs_generate_variant:Nn \box_autosize_to_wd_and_ht:Nnn { c } |
| 2570 |
\cs_new_protected:Npn \box_gautosize_to_wd_and_ht:Nnn #1#2#3 |
| 2571 |
{ \@@_autosize:NnnnN #1 {#2} {#3} { \box_ht:N #1 } \hbox_gset:Nn } |
| 2572 |
\cs_generate_variant:Nn \box_gautosize_to_wd_and_ht:Nnn { c } |
| 2573 |
\cs_new_protected:Npn \box_autosize_to_wd_and_ht_plus_dp:Nnn #1#2#3 |
| 2574 |
{ |
| 2575 |
\@@_autosize:NnnnN #1 {#2} {#3} { \box_ht:N #1 + \box_dp:N #1 } |
| 2576 |
\hbox_set:Nn |
| 2577 |
} |
| 2578 |
\cs_generate_variant:Nn \box_autosize_to_wd_and_ht_plus_dp:Nnn { c } |
| 2579 |
\cs_new_protected:Npn \box_gautosize_to_wd_and_ht_plus_dp:Nnn #1#2#3 |
| 2580 |
{ |
| 2581 |
\@@_autosize:NnnnN #1 {#2} {#3} { \box_ht:N #1 + \box_dp:N #1 } |
| 2582 |
\hbox_gset:Nn |
| 2583 |
} |
| 2584 |
\cs_generate_variant:Nn \box_gautosize_to_wd_and_ht_plus_dp:Nnn { c } |
| 2585 |
\cs_new_protected:Npn \@@_autosize:NnnnN #1#2#3#4#5 |
| 2586 |
{ |
| 2587 |
#5 #1 |
| 2588 |
{ |
| 2589 |
\fp_set:Nn \l_@@_scale_x_fp { ( \dim_to_fp:n {#2} ) / \box_wd:N #1 } |
| 2590 |
\fp_set:Nn \l_@@_scale_y_fp |
| 2591 |
{ ( \dim_to_fp:n {#3} ) / ( \dim_to_fp:n {#4} ) } |
| 2592 |
\fp_compare:nNnTF \l_@@_scale_x_fp > \l_@@_scale_y_fp |
| 2593 |
{ \fp_set_eq:NN \l_@@_scale_x_fp \l_@@_scale_y_fp } |
| 2594 |
{ \fp_set_eq:NN \l_@@_scale_y_fp \l_@@_scale_x_fp } |
| 2595 |
\@@_scale:N #1 |
| 2596 |
} |
| 2597 |
} |
| 2598 |
% \end{macrocode} |
| 2599 |
% \end{macro} |
| 2600 |
% \end{macro} |
| 2601 |
% |
| 2602 |
% \begin{macro}{\@@_resize_common:N} |
| 2603 |
% The main resize function places its input into a box which start |
| 2604 |
% off with zero width, and includes the handles for engine rescaling. |
| 2605 |
% \begin{macrocode} |
| 2606 |
\cs_new_protected:Npn \@@_resize_common:N #1 |
| 2607 |
{ |
| 2608 |
\hbox_set:Nn \l_@@_tmp_box |
| 2609 |
{ |
| 2610 |
\@@_backend_scale:Nnn |
| 2611 |
#1 |
| 2612 |
\l_@@_scale_x_fp |
| 2613 |
\l_@@_scale_y_fp |
| 2614 |
} |
| 2615 |
% \end{macrocode} |
| 2616 |
% The new height and depth can be applied directly. |
| 2617 |
% \begin{macrocode} |
| 2618 |
\fp_compare:nNnTF \l_@@_scale_y_fp > \c_zero_fp |
| 2619 |
{ |
| 2620 |
\box_set_ht:Nn \l_@@_tmp_box { \l_@@_top_new_dim } |
| 2621 |
\box_set_dp:Nn \l_@@_tmp_box { -\l_@@_bottom_new_dim } |
| 2622 |
} |
| 2623 |
{ |
| 2624 |
\box_set_dp:Nn \l_@@_tmp_box { \l_@@_top_new_dim } |
| 2625 |
\box_set_ht:Nn \l_@@_tmp_box { -\l_@@_bottom_new_dim } |
| 2626 |
} |
| 2627 |
% \end{macrocode} |
| 2628 |
% Things are not quite as obvious for the width, as the reference point |
| 2629 |
% needs to remain unchanged. For positive scaling factors resizing the |
| 2630 |
% box is all that is needed. However, for case of a negative scaling |
| 2631 |
% the material must be shifted such that the reference point ends up in |
| 2632 |
% the right place. |
| 2633 |
% \begin{macrocode} |
| 2634 |
\fp_compare:nNnTF \l_@@_scale_x_fp < \c_zero_fp |
| 2635 |
{ |
| 2636 |
\hbox_to_wd:nn { \l_@@_right_new_dim } |
| 2637 |
{ |
| 2638 |
\dim_horizontal:N \l_@@_right_new_dim |
| 2639 |
\box_use_drop:N \l_@@_tmp_box |
| 2640 |
\tex_hss:D |
| 2641 |
} |
| 2642 |
} |
| 2643 |
{ |
| 2644 |
\box_set_wd:Nn \l_@@_tmp_box { \l_@@_right_new_dim } |
| 2645 |
\hbox:n |
| 2646 |
{ |
| 2647 |
\dim_horizontal:n{ 0pt } |
| 2648 |
\box_use_drop:N \l_@@_tmp_box |
| 2649 |
\tex_hss:D |
| 2650 |
} |
| 2651 |
} |
| 2652 |
} |
| 2653 |
% \end{macrocode} |
| 2654 |
% \end{macro} |
| 2655 |
% |
| 2656 |
% \subsection{Adding frames to boxes} |
| 2657 |
% |
| 2658 |
% \begin{macro}{\@@_rule_horizontal:nn} |
| 2659 |
% \begin{macro}{\@@_rule_vertical:n} |
| 2660 |
% Wrappers around the \TeX{} primitives for creating rules, with the usual |
| 2661 |
% dimension expression support. The non-expanding rule is set up in |
| 2662 |
% horizontal mode as that is usually the best plan. The \cs{scan_stop:} |
| 2663 |
% is needed here as \TeX{} continues to scan for keywords: multiple uses |
| 2664 |
% of the same word are permitted. (Thanks to Ruixi Zhang for pointing this |
| 2665 |
% out.) At some stage these will presumably move to a different (public) |
| 2666 |
% place. |
| 2667 |
% \begin{macrocode} |
| 2668 |
\cs_new_protected:Npn \@@_rule_horizontal:nn #1#2 |
| 2669 |
{ |
| 2670 |
\tex_hrule:D |
| 2671 |
height \@@_dim_eval:n {#1} |
| 2672 |
depth \@@_dim_eval:n {#2} |
| 2673 |
\scan_stop: |
| 2674 |
} |
| 2675 |
\cs_new_protected:Npn \@@_rule_vertical:n #1 |
| 2676 |
{ \tex_vrule:D width \@@_dim_eval:n {#1} \scan_stop: } |
| 2677 |
% \end{macrocode} |
| 2678 |
% \end{macro} |
| 2679 |
% \end{macro} |
| 2680 |
% |
| 2681 |
% \begin{macro} |
| 2682 |
% { |
| 2683 |
% \box_frame:Nnn, \box_frame:cnn, |
| 2684 |
% \box_gframe:Nnn, \box_gframe:cnn, |
| 2685 |
% } |
| 2686 |
% \begin{macro}{\@@_frame:nnNN, \@@_frame:eeNN} |
| 2687 |
% Framing a box requires the depth is known, so there has to be an |
| 2688 |
% assignment step first to allow this measurement. The actual |
| 2689 |
% insertion is done such that the content goes in \enquote{behind} |
| 2690 |
% the rules. That requires a bit of shuffling so that the final box is the |
| 2691 |
% correct size, including the necessary border, while keeping the reference |
| 2692 |
% point in the right place. |
| 2693 |
% \begin{macrocode} |
| 2694 |
\cs_new_protected:Npn \box_frame:Nnn #1#2#3 |
| 2695 |
{ |
| 2696 |
\@@_frame:eeNN { \dim_eval:n {#2} } { \dim_eval:n {#3} } |
| 2697 |
#1 \hbox_set:Nn |
| 2698 |
} |
| 2699 |
\cs_generate_variant:Nn \box_frame:Nnn { c } |
| 2700 |
\cs_new_protected:Npn \box_gframe:Nnn #1#2#3 |
| 2701 |
{ |
| 2702 |
\@@_frame:eeNN { \dim_eval:n {#2} } { \dim_eval:n {#3} } |
| 2703 |
#1 \hbox_gset:Nn |
| 2704 |
} |
| 2705 |
\cs_generate_variant:Nn \box_gframe:Nnn { c } |
| 2706 |
\cs_new_protected:Npn \@@_frame:nnNN #1#2#3#4 |
| 2707 |
{ |
| 2708 |
#4 #3 |
| 2709 |
{ |
| 2710 |
\dim_horizontal:n { #1 + #2 } |
| 2711 |
\box_use:N #3 |
| 2712 |
\dim_horizontal:n { -\box_wd:N #3 - #1 - #2 } |
| 2713 |
\box_move_down:nn { \box_dp:N #3 + #1 + #2 } |
| 2714 |
{ |
| 2715 |
\vbox:n |
| 2716 |
{ |
| 2717 |
\@@_rule_horizontal:nn {#2} { \c_zero_dim } |
| 2718 |
\hbox:n |
| 2719 |
{ |
| 2720 |
\@@_rule_vertical:n {#2} |
| 2721 |
\dim_horizontal:n { #1 * 2 + \box_wd:N #3 } |
| 2722 |
\vbox:n |
| 2723 |
{ |
| 2724 |
\dim_vertical:n |
| 2725 |
{ #1 * 2 + \box_dp:N #3 + \box_ht:N #3 } |
| 2726 |
} |
| 2727 |
\@@_rule_vertical:n {#2} |
| 2728 |
} |
| 2729 |
\@@_rule_horizontal:nn {#2} { \c_zero_dim } |
| 2730 |
} |
| 2731 |
} |
| 2732 |
} |
| 2733 |
} |
| 2734 |
\cs_generate_variant:Nn \@@_frame:nnNN { ee } |
| 2735 |
% \end{macrocode} |
| 2736 |
% \end{macro} |
| 2737 |
% \end{macro} |
| 2738 |
% |
| 2739 |
% \begin{macro} |
| 2740 |
% { |
| 2741 |
% \box_underline:Nnn, \box_underline:cnn, |
| 2742 |
% \box_gunderline:Nnn, \box_gunderline:cnn |
| 2743 |
% } |
| 2744 |
% \begin{macro}{\@@_underline:nnNN, \@@_underline:eeNN} |
| 2745 |
% A cut-down version of framing, with just one side marked. |
| 2746 |
% \begin{macrocode} |
| 2747 |
\cs_new_protected:Npn \box_underline:Nnn #1#2#3 |
| 2748 |
{ |
| 2749 |
\@@_underline:eeNN |
| 2750 |
{ \dim_eval:n {#2} } { \dim_eval:n {#3} } |
| 2751 |
#1 \hbox_set:Nn |
| 2752 |
} |
| 2753 |
\cs_generate_variant:Nn \box_underline:Nnn { c } |
| 2754 |
\cs_new_protected:Npn \box_gunderline:Nnn #1#2#3 |
| 2755 |
{ |
| 2756 |
\@@_underline:eeNN |
| 2757 |
{ \dim_eval:n {#2} } { \dim_eval:n {#3} } |
| 2758 |
#1 \hbox_gset:Nn |
| 2759 |
} |
| 2760 |
\cs_generate_variant:Nn \box_gunderline:Nnn { c } |
| 2761 |
\cs_new_protected:Npn \@@_underline:nnNN #1#2#3#4 |
| 2762 |
{ |
| 2763 |
#4 #3 |
| 2764 |
{ |
| 2765 |
\box_use:N #3 |
| 2766 |
\dim_horizontal:n { -\box_wd:N #3 } |
| 2767 |
\box_move_down:nn { \box_dp:N #3 + #1 + #2 } |
| 2768 |
{ |
| 2769 |
\vbox:n |
| 2770 |
{ |
| 2771 |
\hbox:n { \dim_horizontal:n { \box_wd:N #3 } } |
| 2772 |
\@@_rule_horizontal:nn {#2} { \c_zero_dim } |
| 2773 |
} |
| 2774 |
} |
| 2775 |
} |
| 2776 |
} |
| 2777 |
\cs_generate_variant:Nn \@@_underline:nnNN { ee } |
| 2778 |
% \end{macrocode} |
| 2779 |
% \end{macro} |
| 2780 |
% \end{macro} |
| 2781 |
% |
| 2782 |
% \subsection{Viewing part of a box} |
| 2783 |
% |
| 2784 |
% \begin{macro}{\box_set_clipped:N, \box_set_clipped:c, \box_gset_clipped:N, \box_gset_clipped:c} |
| 2785 |
% A wrapper around the driver-dependent code. |
| 2786 |
% \begin{macrocode} |
| 2787 |
\cs_new_protected:Npn \box_set_clipped:N #1 |
| 2788 |
{ \hbox_set:Nn #1 { \@@_backend_clip:N #1 } } |
| 2789 |
\cs_generate_variant:Nn \box_set_clipped:N { c } |
| 2790 |
\cs_new_protected:Npn \box_gset_clipped:N #1 |
| 2791 |
{ \hbox_gset:Nn #1 { \@@_backend_clip:N #1 } } |
| 2792 |
\cs_generate_variant:Nn \box_gset_clipped:N { c } |
| 2793 |
% \end{macrocode} |
| 2794 |
% \end{macro} |
| 2795 |
% |
| 2796 |
% \begin{macro} |
| 2797 |
% { |
| 2798 |
% \box_set_trim:Nnnnn, \box_set_trim:cnnnn, |
| 2799 |
% \box_gset_trim:Nnnnn, \box_gset_trim:cnnnn |
| 2800 |
% } |
| 2801 |
% \begin{macro}{\@@_set_trim:NnnnnN} |
| 2802 |
% Trimming from the left- and right-hand edges of the box is easy: kern the |
| 2803 |
% appropriate parts off each side. |
| 2804 |
% \begin{macrocode} |
| 2805 |
\cs_new_protected:Npn \box_set_trim:Nnnnn #1#2#3#4#5 |
| 2806 |
{ \@@_set_trim:NnnnnN #1 {#2} {#3} {#4} {#5} \box_set_eq:NN } |
| 2807 |
\cs_generate_variant:Nn \box_set_trim:Nnnnn { c } |
| 2808 |
\cs_new_protected:Npn \box_gset_trim:Nnnnn #1#2#3#4#5 |
| 2809 |
{ \@@_set_trim:NnnnnN #1 {#2} {#3} {#4} {#5} \box_gset_eq:NN } |
| 2810 |
\cs_generate_variant:Nn \box_gset_trim:Nnnnn { c } |
| 2811 |
\cs_new_protected:Npn \@@_set_trim:NnnnnN #1#2#3#4#5#6 |
| 2812 |
{ |
| 2813 |
\hbox_set:Nn \l_@@_tmp_box |
| 2814 |
{ |
| 2815 |
\dim_horizontal:n { -#2 } |
| 2816 |
\box_use:N #1 |
| 2817 |
\dim_horizontal:n { -#4 } |
| 2818 |
} |
| 2819 |
% \end{macrocode} |
| 2820 |
% For the height and depth, there is a need to watch the baseline is |
| 2821 |
% respected. Material always has to stay on the correct side, so trimming |
| 2822 |
% has to check that there is enough material to trim. First, the bottom |
| 2823 |
% edge. If there is enough depth, simply set the depth, or if not move |
| 2824 |
% down so the result is zero depth. \cs{box_move_down:nn} is used in both |
| 2825 |
% cases so the resulting box always contains a \tn{lower} primitive. |
| 2826 |
% The internal box is used here as it allows safe use of \cs{box_set_dp:Nn}. |
| 2827 |
% \begin{macrocode} |
| 2828 |
\dim_compare:nNnTF { \box_dp:N #1 } > {#3} |
| 2829 |
{ |
| 2830 |
\hbox_set:Nn \l_@@_tmp_box |
| 2831 |
{ |
| 2832 |
\box_move_down:nn \c_zero_dim |
| 2833 |
{ \box_use_drop:N \l_@@_tmp_box } |
| 2834 |
} |
| 2835 |
\box_set_dp:Nn \l_@@_tmp_box { \box_dp:N #1 - (#3) } |
| 2836 |
} |
| 2837 |
{ |
| 2838 |
\hbox_set:Nn \l_@@_tmp_box |
| 2839 |
{ |
| 2840 |
\box_move_down:nn { (#3) - \box_dp:N #1 } |
| 2841 |
{ \box_use_drop:N \l_@@_tmp_box } |
| 2842 |
} |
| 2843 |
\box_set_dp:Nn \l_@@_tmp_box \c_zero_dim |
| 2844 |
} |
| 2845 |
% \end{macrocode} |
| 2846 |
% Same thing, this time from the top of the box. |
| 2847 |
% \begin{macrocode} |
| 2848 |
\dim_compare:nNnTF { \box_ht:N \l_@@_tmp_box } > {#5} |
| 2849 |
{ |
| 2850 |
\hbox_set:Nn \l_@@_tmp_box |
| 2851 |
{ |
| 2852 |
\box_move_up:nn \c_zero_dim |
| 2853 |
{ \box_use_drop:N \l_@@_tmp_box } |
| 2854 |
} |
| 2855 |
\box_set_ht:Nn \l_@@_tmp_box |
| 2856 |
{ \box_ht:N \l_@@_tmp_box - (#5) } |
| 2857 |
} |
| 2858 |
{ |
| 2859 |
\hbox_set:Nn \l_@@_tmp_box |
| 2860 |
{ |
| 2861 |
\box_move_up:nn { (#5) - \box_ht:N \l_@@_tmp_box } |
| 2862 |
{ \box_use_drop:N \l_@@_tmp_box } |
| 2863 |
} |
| 2864 |
\box_set_ht:Nn \l_@@_tmp_box \c_zero_dim |
| 2865 |
} |
| 2866 |
#6 #1 \l_@@_tmp_box |
| 2867 |
} |
| 2868 |
% \end{macrocode} |
| 2869 |
% \end{macro} |
| 2870 |
% \end{macro} |
| 2871 |
% |
| 2872 |
% \begin{macro} |
| 2873 |
% { |
| 2874 |
% \box_set_viewport:Nnnnn, \box_set_viewport:cnnnn, |
| 2875 |
% \box_gset_viewport:Nnnnn, \box_gset_viewport:cnnnn |
| 2876 |
% } |
| 2877 |
% \begin{macro}{\@@_viewport:NnnnnN} |
| 2878 |
% The same general logic as for the trim operation, but with absolute |
| 2879 |
% dimensions. As a result, there are some things to watch out for in the |
| 2880 |
% vertical direction. |
| 2881 |
% \begin{macrocode} |
| 2882 |
\cs_new_protected:Npn \box_set_viewport:Nnnnn #1#2#3#4#5 |
| 2883 |
{ \@@_set_viewport:NnnnnN #1 {#2} {#3} {#4} {#5} \box_set_eq:NN } |
| 2884 |
\cs_generate_variant:Nn \box_set_viewport:Nnnnn { c } |
| 2885 |
\cs_new_protected:Npn \box_gset_viewport:Nnnnn #1#2#3#4#5 |
| 2886 |
{ \@@_set_viewport:NnnnnN #1 {#2} {#3} {#4} {#5} \box_gset_eq:NN } |
| 2887 |
\cs_generate_variant:Nn \box_gset_viewport:Nnnnn { c } |
| 2888 |
\cs_new_protected:Npn \@@_set_viewport:NnnnnN #1#2#3#4#5#6 |
| 2889 |
{ |
| 2890 |
\hbox_set:Nn \l_@@_tmp_box |
| 2891 |
{ |
| 2892 |
\dim_horizontal:n { -#2 } |
| 2893 |
\box_use:N #1 |
| 2894 |
\dim_horizontal:n { #4 - \box_wd:N #1 } |
| 2895 |
} |
| 2896 |
\dim_compare:nNnTF {#3} < \c_zero_dim |
| 2897 |
{ |
| 2898 |
\hbox_set:Nn \l_@@_tmp_box |
| 2899 |
{ |
| 2900 |
\box_move_down:nn \c_zero_dim |
| 2901 |
{ \box_use_drop:N \l_@@_tmp_box } |
| 2902 |
} |
| 2903 |
\box_set_dp:Nn \l_@@_tmp_box { - \@@_dim_eval:n {#3} } |
| 2904 |
} |
| 2905 |
{ |
| 2906 |
\hbox_set:Nn \l_@@_tmp_box |
| 2907 |
{ \box_move_down:nn {#3} { \box_use_drop:N \l_@@_tmp_box } } |
| 2908 |
\box_set_dp:Nn \l_@@_tmp_box \c_zero_dim |
| 2909 |
} |
| 2910 |
\dim_compare:nNnTF {#5} > \c_zero_dim |
| 2911 |
{ |
| 2912 |
\hbox_set:Nn \l_@@_tmp_box |
| 2913 |
{ |
| 2914 |
\box_move_up:nn \c_zero_dim |
| 2915 |
{ \box_use_drop:N \l_@@_tmp_box } |
| 2916 |
} |
| 2917 |
\box_set_ht:Nn \l_@@_tmp_box |
| 2918 |
{ |
| 2919 |
(#5) |
| 2920 |
\dim_compare:nNnT {#3} > \c_zero_dim |
| 2921 |
{ - (#3) } |
| 2922 |
} |
| 2923 |
} |
| 2924 |
{ |
| 2925 |
\hbox_set:Nn \l_@@_tmp_box |
| 2926 |
{ |
| 2927 |
\box_move_up:nn { - \@@_dim_eval:n {#5} } |
| 2928 |
{ \box_use_drop:N \l_@@_tmp_box } |
| 2929 |
} |
| 2930 |
\box_set_ht:Nn \l_@@_tmp_box \c_zero_dim |
| 2931 |
} |
| 2932 |
#6 #1 \l_@@_tmp_box |
| 2933 |
} |
| 2934 |
% \end{macrocode} |
| 2935 |
% \end{macro} |
| 2936 |
% \end{macro} |
| 2937 |
% |
| 2938 |
% \begin{macrocode} |
| 2939 |
%</code> |
| 2940 |
% \end{macrocode} |
| 2941 |
% |
| 2942 |
% \end{implementation} |
| 2943 |
% |
| 2944 |
% \PrintIndex |