| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: ltmarks.dtx |
| 4 |
%% Copyright (C) 2022-2025 |
| 5 |
%% Frank Mittelbach, 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 |
% |
| 15 |
%%% From File: ltmarks.dtx |
| 16 |
% |
| 17 |
%<*driver> |
| 18 |
% \fi |
| 19 |
\ProvidesFile{ltmarks.dtx} |
| 20 |
[2025/08/11 v1.1e LaTeX Kernel (Marks)] |
| 21 |
% \iffalse |
| 22 |
% |
| 23 |
\documentclass{l3doc} |
| 24 |
\GetFileInfo{ltmarks.dtx} |
| 25 |
|
| 26 |
\EnableCrossrefs |
| 27 |
\CodelineIndex |
| 28 |
\begin{document} |
| 29 |
\DocInput{ltmarks.dtx} |
| 30 |
\end{document} |
| 31 |
%</driver> |
| 32 |
% |
| 33 |
% \fi |
| 34 |
% |
| 35 |
% \providecommand\hook[1]{\texttt{#1}} |
| 36 |
% \providecommand\env[1]{\texttt{#1}} |
| 37 |
% |
| 38 |
% |
| 39 |
% |
| 40 |
% \title{The \texttt{ltmarks.dtx} code\thanks{This file has version |
| 41 |
% \fileversion\ dated \filedate, \copyright\ \LaTeX\ |
| 42 |
% Project.}} |
| 43 |
% \author{^^A |
| 44 |
% Frank Mittelbach, \LaTeX{} Project\thanks |
| 45 |
% {^^A |
| 46 |
% E-mail: |
| 47 |
% \href{mailto:[email protected]} |
| 48 |
% {[email protected]}^^A |
| 49 |
% }^^A |
| 50 |
% } |
| 51 |
% |
| 52 |
% \maketitle |
| 53 |
% |
| 54 |
% |
| 55 |
% \begin{abstract} |
| 56 |
% Marks are used to communicate information about the content of a |
| 57 |
% page to the output routine. For example, in order to construct |
| 58 |
% running headers, the output routine needs information about which |
| 59 |
% section names are present on a page, and this information is |
| 60 |
% passed to it through the mark system. However, marks may also be |
| 61 |
% used for other purposes. This module provides a generalized |
| 62 |
% mechanism for marks of independent classes. |
| 63 |
% \end{abstract} |
| 64 |
% |
| 65 |
% \tableofcontents |
| 66 |
% |
| 67 |
% ^^A \begin{documentation} |
| 68 |
% |
| 69 |
% \section{Introduction} |
| 70 |
% |
| 71 |
% The \TeX{} engines offer a low-level mark mechanism to |
| 72 |
% communicate information about the content of the current page to |
| 73 |
% the asynchronous operating output routine. It works by placing |
| 74 |
% \cs{mark} commands into the source document. When the material |
| 75 |
% for the current page is assembled in box 255, \TeX{} scans for |
| 76 |
% such marks and sets the commands \cs{topmark}, \cs{firstmark} and |
| 77 |
% \cs{botmark}. The \cs{firstmark} receives the content of the |
| 78 |
% first \cs{mark} seen in box 255 and \cs{botmark} the content of |
| 79 |
% the last mark seen. The \cs{topmark} holds the content of the |
| 80 |
% last mark seen on the previous page or more exactly the value of |
| 81 |
% \cs{botmark} from the previous page. If there are no marks on |
| 82 |
% the current page then all three are made equal to the |
| 83 |
% \cs{botmark} from the previous page. |
| 84 |
% |
| 85 |
% This mechanism works well for simple formats (such as plain \TeX) |
| 86 |
% whose output routines are only called to generate pages. It |
| 87 |
% fails, however, in \LaTeX{} (and other more complex formats), |
| 88 |
% because here the output routine is sometimes called without |
| 89 |
% producing a page, e.g., when encountering a float and placing it |
| 90 |
% into one of the float regions. In that case the output routine is |
| 91 |
% called, determines where to place the float, alters the goal for |
| 92 |
% assembling text material (if the float was added to the top or |
| 93 |
% bottom region) and then it resumes collecting textual material. |
| 94 |
% |
| 95 |
% As a result the \cs{botmark} gets updated and so \cs{topmark} no |
| 96 |
% longer reflects the situation at the top of the next page when that |
| 97 |
% page is finally boxed. |
| 98 |
% |
| 99 |
% Another problem for \LaTeX{} was that it wanted to use several |
| 100 |
% \enquote{independent} marks and in the early implementations of |
| 101 |
% \TeX{} there was only a single \cs{mark} command available. |
| 102 |
% For that reason \LaTeX{} implemented its own mark |
| 103 |
% mechanism where the marks always contained two parts with their |
| 104 |
% own interfaces: \cs{markboth} and \cs{markright} to set marks and |
| 105 |
% \cs{leftmark} and \cs{rightmark} to retrieve them. |
| 106 |
% |
| 107 |
% However, this extended mechanism (while supporting scenarios such |
| 108 |
% as chapter/section marks) was far from general. The mark |
| 109 |
% situation at the top of a page (i.e., \cs{topmark}) remained |
| 110 |
% unusable and the two marks offered were not really independent of |
| 111 |
% each other because \cs{markboth} (as the name indicates) was |
| 112 |
% always setting both. |
| 113 |
% |
| 114 |
% The new mechanism overcomes both |
| 115 |
% issues: |
| 116 |
% \begin{itemize} |
| 117 |
% \item |
| 118 |
% It provides arbitrarily many, fully independent named marks, that |
| 119 |
% can be allocated and, from that point onwards, used. |
| 120 |
% \item |
| 121 |
% It offers access for each such marks to retrieve its top, |
| 122 |
% first, and bottom values separately. |
| 123 |
% \item |
| 124 |
% Furthermore, the mechanism is augmented to give access to marks |
| 125 |
% in different \enquote{regions} which may not be just full pages. |
| 126 |
% \end{itemize} |
| 127 |
% |
| 128 |
% |
| 129 |
% \section{Design-level and code-level interfaces} |
| 130 |
% |
| 131 |
% The interfaces are mainly meant for package developers, but they |
| 132 |
% are usable (with appropriate care) also in the document |
| 133 |
% preamble, for example, when setting up special running headers |
| 134 |
% with \pkg{fancyhdr}, etc. They are therefore available both as |
| 135 |
% CamelCase commands as well as commands for use in the L3 |
| 136 |
% programming layer. Both are described together below. |
| 137 |
% |
| 138 |
% \begin{function}{\NewMarkClass,\mark_new_class:n} |
| 139 |
% \begin{syntax} |
| 140 |
% \cs{NewMarkClass} \Arg{class} |
| 141 |
% \cs{mark_new_class:n} \Arg{class} |
| 142 |
% \end{syntax} |
| 143 |
% Declares a new \meta{class} of marks to be tracked by \LaTeX{}. Each \meta{class} |
| 144 |
% must be declared before it is used. |
| 145 |
% |
| 146 |
% Mark classes can only be declared before \verb=\begin{document}=. |
| 147 |
% \end{function} |
| 148 |
% |
| 149 |
% \begin{function}{\InsertMark,\mark_insert:nn} |
| 150 |
% \begin{syntax} |
| 151 |
% \cs{InsertMark} \Arg{class} \Arg{text} |
| 152 |
% \cs{mark_insert:nn} \Arg{class} \Arg{text} |
| 153 |
% \end{syntax} |
| 154 |
% Adds a mark to the current galley for the \meta{class}, containing the |
| 155 |
% \meta{text}. |
| 156 |
% |
| 157 |
% It has no effect in places in which you can't place floats, e.g., |
| 158 |
% a mark inside a box or inside a footnote never shows up anywhere. |
| 159 |
% |
| 160 |
% If used in vertical mode it obeys \LaTeX's internal |
| 161 |
% \texttt{@nobreak} switch, i.e., it does not introduce a |
| 162 |
% breakpoint if used after a heading. If used in horizontal mode it |
| 163 |
% doesn't handle spacing (like, for example, \cs{index} or |
| 164 |
% \cs{label} does, so it should be attached to material that is |
| 165 |
% typeset. |
| 166 |
% \end{function} |
| 167 |
% |
| 168 |
% \begin{variable}{insertmark} |
| 169 |
% \begin{syntax} |
| 170 |
% \cs{AddToHook} \texttt{\{insertmark\}} \Arg{code} |
| 171 |
% \end{syntax} |
| 172 |
% When marks are inserted, the mark content may need some special |
| 173 |
% treatment, e.g., by default \cs{label}, \cs{index}, and |
| 174 |
% \cs{glossary} do not expand at this time (but only later if and when the |
| 175 |
% mark content is actually used. |
| 176 |
% In order to allow packages to augment or alter this setup there is |
| 177 |
% a public hook \hook{insertmark} that is executed at this point. It |
| 178 |
% runs in a group so local modification to commands are only applied |
| 179 |
% to the \meta{text} argument of \cs{InsertMark} or \cs{mark_insert:nn}. |
| 180 |
% \end{variable} |
| 181 |
% |
| 182 |
% \begin{function}[EXP]{\TopMark, \FirstMark, \LastMark, |
| 183 |
% \mark_use_top:nn,\mark_use_first:nn,\mark_use_last:nn,} |
| 184 |
% \begin{syntax} |
| 185 |
% \cs{TopMark} \oarg{region} \Arg{class} |
| 186 |
% \cs{FirstMark} \oarg{region} \Arg{class} |
| 187 |
% \cs{LastMark} \oarg{region} \Arg{class} |
| 188 |
% \cs{mark_use_top:nn} \Arg{region} \Arg{class} |
| 189 |
% \cs{mark_use_first:nn} \Arg{region} \Arg{class} |
| 190 |
% \cs{mark_use_last:nn} \Arg{region} \Arg{class} |
| 191 |
% \end{syntax} |
| 192 |
% These functions expand to the appropriate mark \meta{text} for |
| 193 |
% the given \meta{class} in the specified \meta{region}. |
| 194 |
% The default \meta{region} in the design-level commands is \texttt{page}. |
| 195 |
% Note that with the L3 layer commands there are no |
| 196 |
% optional arguments, i.e., both arguments have to be provided. |
| 197 |
% \begin{texnote} |
| 198 |
% The result is returned within the \tn{unexpanded} |
| 199 |
% primitive (\cs{exp_not:n}), which means that the \meta{text} |
| 200 |
% does not expand further when appearing in an \texttt{x}-type |
| 201 |
% or \texttt{e}-type argument expansion. |
| 202 |
% \end{texnote} |
| 203 |
% |
| 204 |
% The \enquote{first} and \enquote{last} marks are |
| 205 |
% those seen first and last in the current region/page, respectively. The |
| 206 |
% \enquote{top} mark is the last mark of the \meta{class} seen |
| 207 |
% in an earlier region, i.e., the \meta{text} what would be \enquote{current} at the |
| 208 |
% very top of the region. |
| 209 |
% |
| 210 |
% \noindent\llap{\bfseries Important!\qquad}\indent |
| 211 |
% The commands are only meaningful inside the output routine, in |
| 212 |
% other places their result is (while not random) unpredictable due |
| 213 |
% to the way \LaTeX{} cuts text material into pages. |
| 214 |
% There is, however, one exception: if you produce multiple columns |
| 215 |
% using the \pkg{multicol} package, it is possible to retrieve mark |
| 216 |
% values from the regions \texttt{first-column}, |
| 217 |
% \texttt{last-column}, \texttt{mcol-1}, |
| 218 |
% \texttt{mcol-2},\ldots\ directly after the environment has |
| 219 |
% ended. This can, for example, be useful if a \env{multicols} has |
| 220 |
% been be used inside a box. |
| 221 |
% \end{function} |
| 222 |
% |
| 223 |
% |
| 224 |
% |
| 225 |
% Currently, \meta{region} is one of |
| 226 |
% \texttt{page}, |
| 227 |
% \texttt{previous-page}, |
| 228 |
% \texttt{column}, |
| 229 |
% \texttt{previous-column}, |
| 230 |
% \texttt{first-column}, |
| 231 |
% \texttt{last-column}, and |
| 232 |
% \texttt{mcol-1} (first column in a \env{multicols}), |
| 233 |
% \texttt{mcol-2} (second column in a \env{multicols}), |
| 234 |
% up to |
| 235 |
% \texttt{mcol-20} (twentieth column in a \env{multicols}). |
| 236 |
% See section~\ref{sec:regions} for discussion of how these regions |
| 237 |
% behave and how one can make use of them. |
| 238 |
% |
| 239 |
% |
| 240 |
% \begin{function}[EXP]{\IfMarksEqualTF,\IfMarksEqualT,\IfMarksEqualF,\mark_if_eq:nnnnTF,\mark_if_eq:nnnnnnTF} |
| 241 |
% \begin{syntax} |
| 242 |
% \cs{IfMarksEqualTF} \oarg{region} \Arg{class} \Arg{pos_1} \Arg{pos_2} \Arg{true} \Arg{false} |
| 243 |
% \cs{mark_if_eq:nnnnTF} \Arg{region} \Arg{class} \Arg{pos_1} \Arg{pos_2} \Arg{true} \Arg{false} |
| 244 |
% \cs{mark_if_eq:nnnnnnTF} \Arg{region_1} \Arg{class_1} \Arg{pos_1} |
| 245 |
% \verb= = \Arg{region_2} \Arg{class_2} \Arg{pos_2} \Arg{true} \Arg{false} |
| 246 |
% \end{syntax} |
| 247 |
% These conditionals allow you to compare the content of two marks |
| 248 |
% and act based on the result. The commands work in an expansion |
| 249 |
% context, if necessary. |
| 250 |
% \end{function} |
| 251 |
% |
| 252 |
% It is quite common when programming with marks to need to |
| 253 |
% interrogate conditions such as whether marks have appeared on a |
| 254 |
% previous page, or if there are multiple marks present on the |
| 255 |
% current page, and so on. |
| 256 |
% The tests above allow for the construction of a variety of |
| 257 |
% typical test scenarios, with three examples presented below. |
| 258 |
% |
| 259 |
% The first two conditionals cover only the common scenarios. Both |
| 260 |
% marks are picked up from the same \meta{region} (by default |
| 261 |
% \texttt{page}) and they have to be of the same |
| 262 |
% \meta{class}.\footnote{If an undeclared mark class is used the |
| 263 |
% tests return \emph{true} (not an error).} |
| 264 |
% The \meta{pos\textsubscript{\itshape i}} argument can be either |
| 265 |
% \texttt{top}, \texttt{first}, or \texttt{last}. |
| 266 |
% |
| 267 |
% Important to note is that the comparison is not with respect to |
| 268 |
% the textual content of the marks but whether or not they |
| 269 |
% originated from the same \cs{InsertMark} command (or the L3 layer |
| 270 |
% version \cs{mark_insert:nn}). |
| 271 |
% |
| 272 |
% If you wish to compare marks across different regions or across |
| 273 |
% different classes, you have to do it using the generic test only |
| 274 |
% available in the L3 programming layer or do it manually, i.e., |
| 275 |
% get the marks and then compare the values yourself.\footnote{If |
| 276 |
% two undeclared mark classes are compared the result is always |
| 277 |
% \emph{true}; if a declared and an undeclared mark class is used |
| 278 |
% it is always \emph{false}.} |
| 279 |
% |
| 280 |
% \subsection{Use cases for conditionals} |
| 281 |
% |
| 282 |
% However, the basic version is enough for the following typical use cases: |
| 283 |
% \begin{description} |
| 284 |
% \item[Test for at most one mark of class \texttt{myclass} on current |
| 285 |
% page:] |
| 286 |
% |
| 287 |
% If the first and last mark in a region are the same then |
| 288 |
% either there was no mark at all, or there was at most one. To test |
| 289 |
% this on the current page: |
| 290 |
%\begin{verbatim} |
| 291 |
% \NewMarkClass{myclass} |
| 292 |
% \IfMarksEqualTF{myclass}{first}{last} |
| 293 |
% { <zero or one mark> }{ <two or more marks> } |
| 294 |
%\end{verbatim} |
| 295 |
% |
| 296 |
% \item[Test for no mark of class \texttt{myclass} in the previous |
| 297 |
% page:] |
| 298 |
% |
| 299 |
% If the top mark is the same as the first mark, there is no mark |
| 300 |
% in the region at all. If we wanted to do this test for the |
| 301 |
% previous page: |
| 302 |
%\begin{verbatim} |
| 303 |
% \IfMarksEqualTF[previous-page]{myclass}{top}{first} |
| 304 |
% { <no marks> }{ <at least one mark> } |
| 305 |
%\end{verbatim} |
| 306 |
% Comparing \texttt{top} and \texttt{last} would give you the |
| 307 |
% same result. |
| 308 |
% |
| 309 |
% \item[Test for zero, one, or more than one:] |
| 310 |
% |
| 311 |
% Combining the two tests from above you can test for zero, one |
| 312 |
% or more than one mark. |
| 313 |
%\begin{verbatim} |
| 314 |
% \IfMarksEqualTF{myclass}{top}{first} |
| 315 |
% { <no marks> } |
| 316 |
% {\IfMarksEqualTF{myclass}{first}{last} |
| 317 |
% { <exactly one mark> }{ <more than one mark> }} |
| 318 |
%\end{verbatim} |
| 319 |
% |
| 320 |
% \end{description} |
| 321 |
% |
| 322 |
% If you need one of such tests more often (or if you want a separate |
| 323 |
% command for it for readability), then consider defining: |
| 324 |
%\begin{verbatim} |
| 325 |
% \providecommand\IfNoMarkTF[2][page]{\IfMarksEqualTF[#1]{#2}{first}{last}} |
| 326 |
%\end{verbatim} |
| 327 |
% |
| 328 |
% |
| 329 |
% |
| 330 |
% \subsection{Understanding regions} |
| 331 |
% \label{sec:regions} |
| 332 |
% |
| 333 |
% If a page has just been finished then the region \texttt{page} |
| 334 |
% refers to the current page and \texttt{previous-page}, as the name |
| 335 |
% indicates, refers to the page before the current page. This |
| 336 |
% means you are able to access mark information for the current page |
| 337 |
% as well as for the page before (as long as you are inside the output |
| 338 |
% routine) without the need to explicitly save that information |
| 339 |
% beforehand. The \texttt{page} region is the region that is most |
| 340 |
% often queried, which is why commands like \cs{FirstMark} use that |
| 341 |
% region by default. |
| 342 |
% |
| 343 |
% In single column documents the \texttt{column} is the same as the |
| 344 |
% \texttt{page} region, but in two-column documents (if not produced |
| 345 |
% by \env{multicols}), \texttt{column} refers to the current column |
| 346 |
% that just got finished and \text{previous-column} to the one |
| 347 |
% previously finished. Code for running headers is (in standard |
| 348 |
% \LaTeX{}) evaluated only after both columns have been assembled, which is |
| 349 |
% another way of saying that in that case \texttt{previous-column} |
| 350 |
% refers to the left column and \texttt{column} to the right column. |
| 351 |
% However, to make these somewhat easier to use, there are also aliased names |
| 352 |
% for these two regions: \texttt{first-column} and |
| 353 |
% \texttt{last-column}.\footnote{The region is called \enquote{last-column} not |
| 354 |
% \enquote{second-column} in anticipation of extending the mechanism to |
| 355 |
% multiple columns, where first and last would still make sense. |
| 356 |
% There aren't any |
| 357 |
% \texttt{previous-first-column} and \texttt{previous-last-column} |
| 358 |
% regions to access the corresponding |
| 359 |
% columns from the previous page.} |
| 360 |
% |
| 361 |
% Note that you can only look backwards at already processed |
| 362 |
% regions, e.g., in a \texttt{twoside} document finishing a recto |
| 363 |
% (odd, right-hand) page you can access the data from the facing |
| 364 |
% verso (left-hand) page, but if you are finishing a left-hand page |
| 365 |
% you can't integrate data from the upcoming right-hand page. If |
| 366 |
% such a scenario needs to be realized then it is necessary to save |
| 367 |
% the left-hand page temporarily instead of finalizing it, process |
| 368 |
% material for the right-hand page and once both are ready, attach |
| 369 |
% running headers and footers and shipout out both in one |
| 370 |
% go.\footnote{As of now that scenario is not (yet) officially |
| 371 |
% supported but it would be possible to achieve this using the |
| 372 |
% shipout hooks to store the verso page and then on the next shipout |
| 373 |
% use the hook to shipout both with running headers and footers |
| 374 |
% attached.} |
| 375 |
% |
| 376 |
% The situation starts getting rather complex if you allow for |
| 377 |
% multiple columns in the way they are supported by the |
| 378 |
% \pkg{multicol} package. In this case you might have a variable |
| 379 |
% number of \enquote{columns} on a single page to be shipped |
| 380 |
% out. And even if not, then a \env{multicols} might start or end in |
| 381 |
% the middle of the page; in either case, the regions \texttt{column} and |
| 382 |
% \texttt{previous-column} become rather meaningless and you should |
| 383 |
% therefore not use them.\footnote{They return something, because |
| 384 |
% they represent the last two columns of the \env{multicols} when |
| 385 |
% you are inside the output routine, but that is obviously of little |
| 386 |
% use.} |
| 387 |
% Instead, the algorithm offers \texttt{mcol-1}, \texttt{mcol-2}, |
| 388 |
% \texttt{mcol-3}, etc., to represent the columns in the |
| 389 |
% \env{multicols} on the current page to be shipped out. If there is |
| 390 |
% more than one \env{multicols} on the current page then in the output routine |
| 391 |
% only the columns of the last one will be accessible. |
| 392 |
% |
| 393 |
% These provisions cover, out of the box, a number of layouts and use cases, but |
| 394 |
% obviously not all. However, more cases can be supported by storing away |
| 395 |
% mark information during the processing. Here is the full |
| 396 |
% algorithm: |
| 397 |
% \begin{itemize} |
| 398 |
% \item |
| 399 |
|
| 400 |
% The \texttt{column} region is used by the \enquote{current |
| 401 |
% column} that is being built (moving through all columns with |
| 402 |
% \texttt{previous-column} trailing behind (to handle top marks |
| 403 |
% properly). |
| 404 |
% |
| 405 |
% \item |
| 406 |
|
| 407 |
% When the \env{multicols} starts, the \texttt{column} region is |
| 408 |
% cleared, i.e., from that point on it looks as if there have not |
| 409 |
% been any marks so far. This will make sure that the top mark in |
| 410 |
% the first column is always empty. |
| 411 |
% |
| 412 |
% \item |
| 413 |
% |
| 414 |
% If the \env{multicols} extends beyond the current page, then the |
| 415 |
% material designated for the current page is split into columns. |
| 416 |
% The \texttt{column} region is used to represent each column in |
| 417 |
% turn. |
| 418 |
|
| 419 |
% \begin{itemize} |
| 420 |
% \item |
| 421 |
% |
| 422 |
% First we copy the current data from \texttt{column} to |
| 423 |
% \texttt{previous-column}. Then the mark data from the current |
| 424 |
% column is placed into the \texttt{column} region. Then we alias |
| 425 |
% \texttt{column} to \texttt{mcol-1}. |
| 426 |
% |
| 427 |
% \item These steps are repeated for all columns of the \env{multicols} |
| 428 |
% environment. |
| 429 |
% |
| 430 |
% \item Finally, the first and the last column of that page is also |
| 431 |
% made available as \texttt{first-column} and |
| 432 |
% \texttt{last-column}, respectively. |
| 433 |
% \end{itemize} |
| 434 |
% |
| 435 |
% \item |
| 436 |
% All those marks inside any of the columns are also available in the |
| 437 |
% \texttt{page} region. Thus, if you are interested in the top, |
| 438 |
% first, or last mark of a specific class on the whole page you |
| 439 |
% simply need to query for it in the \texttt{page} region. |
| 440 |
% |
| 441 |
% \item |
| 442 |
% If the \env{multicols} continues across several pages then |
| 443 |
% this algorithm above is repeated for each page, except that the \texttt{column} |
| 444 |
% region is not cleared again. This means that the top mark of |
| 445 |
% the first column of the next page will be the last mark of the |
| 446 |
% last column from the previous page. |
| 447 |
% |
| 448 |
% \item |
| 449 |
% When the \env{multicols} finishes the remaining material for the |
| 450 |
% current page is balanced to produce columns of roughly equal height. |
| 451 |
% |
| 452 |
% \item |
| 453 |
% Again \texttt{column} and \texttt{previous-column} are used |
| 454 |
% while this balancing happens and \texttt{mcol-1}, |
| 455 |
% \texttt{mcol-2}, etc., are used to represent the column |
| 456 |
% regions and \texttt{first-column} and \texttt{last-column} are |
| 457 |
% set appropriately. |
| 458 |
% |
| 459 |
% \item |
| 460 |
% Then the balanced set of columns is returned back to the page |
| 461 |
% (since there may be space for further material). In addition, all |
| 462 |
% marks inside that material are reinserted so that they become |
| 463 |
% available in the \texttt{page} region. |
| 464 |
% |
| 465 |
% \item As a side effect, it is possible (and useful in certain |
| 466 |
% circumstances) to query for mark classes directly after the |
| 467 |
% \env{multicols} has ended without the need to be inside the output |
| 468 |
% routine. The regions that can be queried this way are |
| 469 |
% \texttt{mcol-1}, \texttt{mcol-2}, etc.\ (up to the number of columns |
| 470 |
% the multicol had) and \texttt{first-column} and \text{last-column}. |
| 471 |
% |
| 472 |
% \end{itemize} |
| 473 |
% |
| 474 |
% |
| 475 |
% |
| 476 |
% \subsection{Debugging mark code} |
| 477 |
% |
| 478 |
% |
| 479 |
% \begin{function}{\DebugMarksOn,\DebugMarksOff, |
| 480 |
% \mark_debug_on:,\mark_debug_off:} |
| 481 |
% \begin{syntax} |
| 482 |
% \cs{DebugMarksOn} \ldots\ \cs{DebugMarksOff} |
| 483 |
% \end{syntax} |
| 484 |
% |
| 485 |
% Commands to turn the debugging of mark code on or off. The |
| 486 |
% debugging output is rather coarse and not really intended for |
| 487 |
% normal use at this point in time. |
| 488 |
% |
| 489 |
% \end{function} |
| 490 |
% |
| 491 |
% |
| 492 |
% |
| 493 |
% \section{Application examples} |
| 494 |
% |
| 495 |
% If you want to figure out if a break was taken at a specific point, |
| 496 |
% e.g., whether a heading appears at the top of the page, |
| 497 |
% you can do something like this: |
| 498 |
%\begin{verbatim} |
| 499 |
% \newcounter{breakcounter} |
| 500 |
% \NewMarkClass{break} |
| 501 |
% \newcommand\markedbreak[1]{\stepcounter{breakcounter}% |
| 502 |
% \InsertMark{break}{\arabic{breakcounter}% |
| 503 |
% \penalty #1\relax |
| 504 |
% \InsertMark{break}{-\arabic{breakcounter}} |
| 505 |
%\end{verbatim} |
| 506 |
% To test if the break was taken you can test if |
| 507 |
% \verb=\TopMark{break}= is positive (taken) or negative (not taken) |
| 508 |
% or zero (there was never any marked break so far). |
| 509 |
% The absolute value can be used to keep track of which break it |
| 510 |
% was (with some further coding). |
| 511 |
% |
| 512 |
% |
| 513 |
% \emph{to be extended with additional application examples} |
| 514 |
% |
| 515 |
% |
| 516 |
% |
| 517 |
% \section{Legacy \LaTeXe{} interface} |
| 518 |
% |
| 519 |
% Here we describe the interfaces that \LaTeXe{} offered since the |
| 520 |
% early nineties and some minor extensions. |
| 521 |
% |
| 522 |
% \subsection{Legacy design-level and document-level interfaces} |
| 523 |
% |
| 524 |
% \begin{function}{\markboth, \markright} |
| 525 |
% \begin{syntax} |
| 526 |
% \cs{markboth} \Arg{left} \Arg{right} |
| 527 |
% \cs{markright} \Arg{right} |
| 528 |
% \end{syntax} |
| 529 |
% \LaTeXe{} uses two marks which aren't fully independent. A |
| 530 |
% \enquote{left} mark generated by the first argument of \cs{markboth} |
| 531 |
% and a \enquote{right} mark generated by the second argument of |
| 532 |
% \cs{markboth} or by the only argument of \cs{markright}. The |
| 533 |
% command \cs{markboth} and \cs{markright} are in turn called from |
| 534 |
% heading commands such as \cs{chaptermark} or \cs{sectionmark} and |
| 535 |
% their behavior is controlled by the document class. |
| 536 |
% |
| 537 |
% For example, in the \cls{article} class with \texttt{twoside} in |
| 538 |
% force the \cs{sectionmark} will issue \cs{markboth} with an empty |
| 539 |
% second argument and \cs{subsectionmark} will issue |
| 540 |
% \cs{markright}. As a result the left mark will contain chapter |
| 541 |
% titles and the right mark subsection titles. |
| 542 |
% |
| 543 |
% Note, however, that in one-sided documents the standard behavior is |
| 544 |
% that only \cs{markright} is used, i.e., there will only be |
| 545 |
% right-marks but no left marks! |
| 546 |
% \end{function} |
| 547 |
% |
| 548 |
% \begin{function}[EXP]{\leftmark, \rightmark} |
| 549 |
% \begin{syntax} |
| 550 |
% \cs{leftmark} |
| 551 |
% \cs{rightmark} |
| 552 |
% \end{syntax} |
| 553 |
% These functions return the appropriate mark value from the current page |
| 554 |
% and work as before, that is \cs{leftmark} will get the last (!) |
| 555 |
% left mark from the page and \cs{rightmark} the first (!) right |
| 556 |
% mark. |
| 557 |
% |
| 558 |
% In other words they work reasonably well if you want to show the |
| 559 |
% section title that is current when you are about to turn the page and |
| 560 |
% also show the first subsection title on the current page (or the last |
| 561 |
% from the previous page if there wasn't one). Other combinations |
| 562 |
% can't be shown using this interface. |
| 563 |
% |
| 564 |
% The commands are fully expandable, because this is how they have |
| 565 |
% been always defined in \LaTeX{}. However, this is of course |
| 566 |
% only true if the content of the mark they return is itself |
| 567 |
% expandable and does not contain any fragile material. Given that |
| 568 |
% this can't be guaranteed for arbitrary content, a programmer using |
| 569 |
% them in this way should use \cs{protected@edef} and \emph{not} |
| 570 |
% \cs{edef} to avoid bad surprises as far as this is possible, or use |
| 571 |
% the new interfaces (\cs{TopMark}, \cs{FirstMark}, and \cs{LastMark}) |
| 572 |
% which return the \meta{text} in \cs{exp_not:n} to prevent |
| 573 |
% uncontrolled expansion. |
| 574 |
% \end{function} |
| 575 |
% |
| 576 |
% |
| 577 |
% \subsection{Legacy interface extensions} |
| 578 |
% |
| 579 |
% The new implementation adds three mark classes: \texttt{2e-left}, |
| 580 |
% \texttt{2e-right} and \texttt{2e-right-nonempty} and patches |
| 581 |
% \cs{markboth} and \cs{markright} slightly so that they also update |
| 582 |
% these new mark classes, so that the new classes work with existing |
| 583 |
% document classes. |
| 584 |
% |
| 585 |
% As a result you can use \verb=\LastMark{2e-left}= and |
| 586 |
% \verb=\FirstMark{2e-right}= instead of \cs{leftmark} and |
| 587 |
% \cs{rightmark}. But more importantly, you can use any of the other |
| 588 |
% retrieval commands to get a different status value from those |
| 589 |
% marks, e.g., \verb=\LastMark{2e-right}= would return the last |
| 590 |
% subsection on the page (instead of the first as |
| 591 |
% returned by \cs{rightmark}). |
| 592 |
% |
| 593 |
% The difference between \texttt{2e-right} and |
| 594 |
% \texttt{2e-right-nonempty} is that the latter will only be updated |
| 595 |
% if the material for the mark is not empty. Thus |
| 596 |
% \verb=\markboth{title}{}= as issued by, say, \cs{sectionmark}, |
| 597 |
% sets a \texttt{2e-left} mark with \texttt{title} and a |
| 598 |
% \texttt{2e-right} mark with the empty string but does not add a |
| 599 |
% \texttt{2e-right-nonempty} mark. |
| 600 |
% |
| 601 |
% Thus, if you have a section at the start of a page and you would |
| 602 |
% ask for \verb=\FirstMark{2e-right}= you would get an empty string |
| 603 |
% even if there are subsections on that page. But |
| 604 |
% \texttt{2e-right-nonempty} would then give you the first or last subsection |
| 605 |
% on that page. Of course, nothing is simple. If there are no |
| 606 |
% subsections it would tell you the last subsection from an earlier |
| 607 |
% page. We therefore need comparison tools, e.g., if top and |
| 608 |
% first are identical you know that the value is |
| 609 |
% bogus, i.e., a suitable implementation would be |
| 610 |
%\begin{verbatim} |
| 611 |
% \IfMarksEqualTF{2e-right-nonempty}{top}{first} |
| 612 |
% { <appropriate action if there was no real mark> } |
| 613 |
% {\FirstMark{2e-right-nonempty}} |
| 614 |
%\end{verbatim} |
| 615 |
% |
| 616 |
% |
| 617 |
% |
| 618 |
% \section{Notes on the mechanism} |
| 619 |
% |
| 620 |
% In contrast to vanilla \TeX, \eTeX{} extends the mark system to |
| 621 |
% allow multiple independent marks. However, it does not solve the |
| 622 |
% \cs{topmark} problem which means that \LaTeX{} still needs to manage |
| 623 |
% marks almost independently of \TeX{}. The reason for this is that |
| 624 |
% the more complex output routine used by \LaTeX{} to handle floats |
| 625 |
% (and related structures) means that \tn{topmark(s)} remain |
| 626 |
% unreliable. Each time the output routine is fired up, \TeX{} moves |
| 627 |
% \tn{botmark} to \tn{topmark}, and while \eTeX{} extends this to |
| 628 |
% multiple registers the fundamental concept remains the same. That |
| 629 |
% means that the state of marks needs to be tracked by \LaTeX{} |
| 630 |
% itself. An early implementation of this package used \TeX{}'s |
| 631 |
% \tn{botmark} only to ensure the correct interaction with the output |
| 632 |
% routine (this was before the \eTeX{} mechanism was even |
| 633 |
% available). However, other than in a prototype implementation for |
| 634 |
% \LaTeX3, this package was never made public. |
| 635 |
% |
| 636 |
% The new implementation now uses \eTeX{}'s marks as they have some |
| 637 |
% advantages, because with them we can leave the mark text within the |
| 638 |
% galley and only extract the marks during the output routine when we |
| 639 |
% are finally shipping out a page or storing away a column for use in |
| 640 |
% the next page. That means we do not have to maintain a global data |
| 641 |
% structure that we have to keep in sync with informational marks in |
| 642 |
% the galley but can rely on everything being in one place and thus |
| 643 |
% manipulations (e.g.~reordering of material) will take the marks with |
| 644 |
% them without a need for updating a fragile linkage. |
| 645 |
|
| 646 |
% To allow for completely independent marks we use the following |
| 647 |
% procedure: |
| 648 |
% \begin{itemize} |
| 649 |
% \item |
| 650 |
% |
| 651 |
% For every type of marks we allocate a mark class so |
| 652 |
% that in the output routine \TeX{} can calculate for each class |
| 653 |
% the current |
| 654 |
% top, first, and bottom mark independently. For this we use |
| 655 |
% \cs{newmarks}, i.e., one marks register per class. |
| 656 |
% |
| 657 |
% \item |
| 658 |
% |
| 659 |
% As already mentioned firing up an output routine without |
| 660 |
% shipping out a page means that \TeX's top marks get wrong so it |
| 661 |
% is impossible to rely on \TeX's approach directly. What we do |
| 662 |
% instead is to keep track of the real marks (for the last page or |
| 663 |
% more generally last region) in some global variables. |
| 664 |
% |
| 665 |
% \item |
| 666 |
% |
| 667 |
% These variables are updated in the output routine at defined |
| 668 |
% places, i.e., when we do real output processing but not if we |
| 669 |
% use special output routines to do internal housekeeping. |
| 670 |
% |
| 671 |
% \item |
| 672 |
% |
| 673 |
% The trick we use to get correctly updated variables is the |
| 674 |
% following: the material that contains new marks (for example the |
| 675 |
% page to be shipped out) is stored in a box. We then use \TeX{} |
| 676 |
% primitive box splitting functions by splitting off the largest |
| 677 |
% amount possible (which should be the whole box if nothing goes |
| 678 |
% really wrong). While that seems a rather pointless thing to do, it |
| 679 |
% has one important side effect: \TeX{} sets up first and bottom |
| 680 |
% marks for each mark class from the material it has split off. This |
| 681 |
% way we get the first and last marks (if there have been any) from |
| 682 |
% the material in the box. |
| 683 |
% |
| 684 |
% \item |
| 685 |
% |
| 686 |
% The top marks are simply the last marks from the previous |
| 687 |
% page or region. And if there hasn't been a first or bottom mark in |
| 688 |
% the box then the new top mark also becomes new first and last mark |
| 689 |
% for that class. |
| 690 |
% |
| 691 |
% \item |
| 692 |
% |
| 693 |
% That mark data is then stored in global token lists for use |
| 694 |
% during the output routine and legacy commands such as |
| 695 |
% \cs{leftmark} or new commands such as \cs{TopMark} simply access |
| 696 |
% the data stored in these token lists. |
| 697 |
% \end{itemize} |
| 698 |
% That's about it in a nutshell. Of course, there are some details to |
| 699 |
% be taken care of---those are discussed in the implementation sections. |
| 700 |
% |
| 701 |
% |
| 702 |
% |
| 703 |
% |
| 704 |
% \section{Public interfaces for packages such as \pkg{multicol}} |
| 705 |
% |
| 706 |
% The functions in this section are public so that packages can make |
| 707 |
% use of them. However, this must be done with great care, e.g., |
| 708 |
% \cs{mark_update_structure_from_material:nn} updates the global mark |
| 709 |
% structure and can therefore be used only in places where such an |
| 710 |
% update is meaningful, e.g., in special output routines. Elsewhere, a |
| 711 |
% change to the mark structure would break the whole mechanism and |
| 712 |
% querying the marks would return incorrect data. |
| 713 |
% |
| 714 |
% \begin{function}{\mark_update_structure_from_material:nn} |
| 715 |
% \begin{syntax} |
| 716 |
% \cs{mark_update_structure_from_material:nn} \Arg{region} \Arg{material with marks} |
| 717 |
% \end{syntax} |
| 718 |
% Helper function that inspects the marks |
| 719 |
% inside the second argument and assigns new mark values based on |
| 720 |
% that to the \meta{region} given in the first argument. |
| 721 |
% For this it first copies the mark structure from \meta{region} to |
| 722 |
% \texttt{previous-}\meta{region} and then takes all last mark |
| 723 |
% values currently in the region and makes them the new top mark |
| 724 |
% values. Finally it assigns new first and last values for all mark |
| 725 |
% classes based on what was found in the second argument. |
| 726 |
% |
| 727 |
% As a consequence, the allowed values for \meta{region} are |
| 728 |
% \texttt{page} and \texttt{column} because only they have |
| 729 |
% \texttt{previous-...} counterparts. |
| 730 |
% |
| 731 |
% Another important aspect to keep in mind is that marks are recognized |
| 732 |
% only if they appear on the top level, e.g., if we want to |
| 733 |
% process material stored in boxes we need to put it unboxed (using |
| 734 |
% \cs{unvcopy} etc.)\ into the second argument. |
| 735 |
% \end{function} |
| 736 |
% |
| 737 |
% |
| 738 |
% |
| 739 |
% \begin{function}{\mark_copy_structure:nn} |
| 740 |
% \begin{syntax} |
| 741 |
% \cs{mark_copy_structure:nn} \Arg{alias} \Arg{source} |
| 742 |
% \end{syntax} |
| 743 |
% Helper function that copies all mark values in the \meta{source} |
| 744 |
% region to \meta{alias}, i.e., make the structures identical. Used |
| 745 |
% to update the \texttt{previous-...} structures inside |
| 746 |
% \cs{mark_update_structure_from_material:nn} and \texttt{first-column} and |
| 747 |
% \texttt{last-column} structures inside the internal commands |
| 748 |
% \cs{__mark_update_singlecol_structures:} or |
| 749 |
% \cs{__mark__update_dblcol_structures:}. |
| 750 |
% \end{function} |
| 751 |
% |
| 752 |
% |
| 753 |
% |
| 754 |
% \begin{function}{\mark_set_structure_to_err:n} |
| 755 |
% \begin{syntax} |
| 756 |
% \cs{mark_set_structure_to_err:n} \Arg{region} |
| 757 |
% \end{syntax} |
| 758 |
% Helper function that sets all mark values in the \meta{region} to |
| 759 |
% an error message. This is currently used for \texttt{last-column} |
| 760 |
% at times where using marks from it would be questionable/wrong, i.e., |
| 761 |
% when we have just processed the first column in a two-column document. |
| 762 |
% \end{function} |
| 763 |
% |
| 764 |
% |
| 765 |
% |
| 766 |
% \begin{function}{\mark_clear_structure:n} |
| 767 |
% \begin{syntax} |
| 768 |
% \cs{mark_clear_structure:n} \Arg{region} |
| 769 |
% \end{syntax} |
| 770 |
% Helper function that sets all mark values in the \meta{region} to |
| 771 |
% empty. This is currently used for \texttt{column} when a multicol |
| 772 |
% environment starts; this is because it wouldn't make sense if the top mark |
| 773 |
% in the first column returned the last mark from a previous |
| 774 |
% multicol (which may have been much earlier, with intermediate |
| 775 |
% material). |
| 776 |
% \end{function} |
| 777 |
% |
| 778 |
% |
| 779 |
% \begin{function}{\mark_get_marks_for_reinsertion:nNN} |
| 780 |
% \begin{syntax} |
| 781 |
% \cs{mark_get_marks_for_reinsertion:nNN} \Arg{source} |
| 782 |
% \qquad \meta{token-list-var for collecting first marks} |
| 783 |
% \qquad \meta{token-list-var for collecting last marks} |
| 784 |
% \end{syntax} |
| 785 |
% Helper function for extracting marks that would otherwise get |
| 786 |
% lost, for example when they are hidden inside a box. This helper |
| 787 |
% does not update mark structures and can therefore be used outside |
| 788 |
% the output routine as well. |
| 789 |
% |
| 790 |
% It collects all the top-level marks from inside the \meta{source} |
| 791 |
% and then adds suitable \cs{mark_insert:nn} commands to each of the two token |
| 792 |
% lists. These token lists can then be executed at the right place |
| 793 |
% to reinsert the marks, e.g., directly after the box. This is, for |
| 794 |
% example, going to be used\footnote{Probably not before 2025, though.} |
| 795 |
% by \pkg{multicol} when a short balanced |
| 796 |
% \env{multicols} is returned to the galley for typesetting. |
| 797 |
% |
| 798 |
% If the \meta{source} consists of a single vertical box (plus |
| 799 |
% possibly followed by some glue but nothing else) then the box is |
| 800 |
% unpacked and the top-level marks are collected from its |
| 801 |
% content. However, if it is not a vertical box or there are |
| 802 |
% other data then nothing is unpacked and you have to do the |
| 803 |
% unpacking yourself to get at the marks inside. |
| 804 |
% |
| 805 |
% It is quite likely that one only needs a single token list for |
| 806 |
% returning the \cs{mark_insert:nn} statements. If that is the case |
| 807 |
% this command may change to take only two arguments. |
| 808 |
% \end{function} |
| 809 |
% |
| 810 |
% |
| 811 |
% \section{Internal functions for the standard output routine of \LaTeX{}} |
| 812 |
% |
| 813 |
% The functions in this section are tied to the output routine and used in the |
| 814 |
% interface to \LaTeXe{} and perhaps at some later time within a new |
| 815 |
% output routine |
| 816 |
% for \LaTeX. They are not (yet) meant for general use and are |
| 817 |
% therefore made internal, even though we already use them in |
| 818 |
% \pkg{multicol}. |
| 819 |
% Internal means that \verb|@@| automatically gets |
| 820 |
% replaced in the code (and in the documentation) so we have to give |
| 821 |
% it a suitable value. |
| 822 |
% \begin{macrocode} |
| 823 |
%<@@=mark> |
| 824 |
% \end{macrocode} |
| 825 |
% |
| 826 |
% \begin{function}{\@@_update_singlecol_structures:} |
| 827 |
% \begin{syntax} |
| 828 |
% \cs{@@_update_singlecol_structures:} |
| 829 |
% \end{syntax} |
| 830 |
% \LaTeXe{} integration function in case we are doing single column |
| 831 |
% layouts. It assumes that the page content is already stored in |
| 832 |
% \cs{@outputbox} and processes the marks inside that box. It is |
| 833 |
% called as part of \cs{@opcol}. |
| 834 |
% \end{function} |
| 835 |
% |
| 836 |
% |
| 837 |
% \begin{function}{\@@_update_dblcol_structures:} |
| 838 |
% \begin{syntax} |
| 839 |
% \cs{@@_update_singlecol_structures:} |
| 840 |
% \end{syntax} |
| 841 |
% \LaTeXe{} integration function mark used when we are doing double |
| 842 |
% column documents. It assumes that the page content is already |
| 843 |
% stored in \cs{@outputbox} and processes the marks inside that |
| 844 |
% box. It then does different post-processing depending on the start |
| 845 |
% of the switch \cs{if@firstcolumn}. If we are in the second column |
| 846 |
% it also has to update page marks, otherwise it only updates column |
| 847 |
% marks. It too is called as part of \cs{@opcol}. |
| 848 |
% \end{function} |
| 849 |
% |
| 850 |
% |
| 851 |
% ^^A \end{documentation} |
| 852 |
% |
| 853 |
% |
| 854 |
% |
| 855 |
% |
| 856 |
% |
| 857 |
% \StopEventually{\setlength\IndexMin{200pt} \PrintIndex } |
| 858 |
% |
| 859 |
% |
| 860 |
% \section{The Implementation} |
| 861 |
% |
| 862 |
% |
| 863 |
% |
| 864 |
% \begin{macrocode} |
| 865 |
%<*2ekernel|latexrelease> |
| 866 |
% \end{macrocode} |
| 867 |
% |
| 868 |
% \begin{macrocode} |
| 869 |
\ExplSyntaxOn |
| 870 |
% \end{macrocode} |
| 871 |
% |
| 872 |
% \begin{macrocode} |
| 873 |
%<latexrelease>\NewModuleRelease{2022/06/01}{ltmarks} |
| 874 |
%<latexrelease> {Marks~handling} |
| 875 |
% \end{macrocode} |
| 876 |
% |
| 877 |
% \subsection{Allocating new mark classes} |
| 878 |
% |
| 879 |
% |
| 880 |
% \begin{variable}{\g_@@_classes_seq} |
| 881 |
% A list holding all the mark classes that have been declared. |
| 882 |
% \begin{macrocode} |
| 883 |
\seq_new:N \g_@@_classes_seq |
| 884 |
% \end{macrocode} |
| 885 |
% \end{variable} |
| 886 |
% |
| 887 |
% |
| 888 |
% |
| 889 |
% |
| 890 |
% \begin{macro}{\mark_new_class:n,\@@_new_class:nn} |
| 891 |
% |
| 892 |
% A mark class is created by initializing a number of data |
| 893 |
% structures. First, we get a register number to refer to the mark |
| 894 |
% class. The new mark class is then added to the |
| 895 |
% \cs{g_@@_classes_seq} sequence to be able to easily loop over all |
| 896 |
% classes. Finally a number of top-level global token lists are |
| 897 |
% declared that hold various versions of the mark for access. |
| 898 |
% \begin{macrocode} |
| 899 |
\cs_new_protected:Npn \mark_new_class:n #1 |
| 900 |
{ |
| 901 |
\seq_if_in:NnTF \g_@@_classes_seq {#1} |
| 902 |
{ |
| 903 |
\msg_error:nnn { mark } { class-already-defined } |
| 904 |
{#1} |
| 905 |
} |
| 906 |
{ \@@_new_class:nn {#1} } |
| 907 |
} |
| 908 |
% \end{macrocode} |
| 909 |
% This is only available in the preamble. |
| 910 |
% \changes{v1.0c}{2022/05/06}{Wrong command made \cs{@onlypreamble}} |
| 911 |
% \begin{macrocode} |
| 912 |
\@onlypreamble \mark_new_class:n |
| 913 |
% \end{macrocode} |
| 914 |
% The internal command carries out the necessary allocations. |
| 915 |
% \begin{macrocode} |
| 916 |
\cs_new_protected:Npn \@@_new_class:nn #1 |
| 917 |
{ |
| 918 |
%<*trace> |
| 919 |
\@@_debug:n { \iow_term:x { Marks:~new~mark:~#1~\msg_line_context: } } |
| 920 |
%</trace> |
| 921 |
% \end{macrocode} |
| 922 |
% Use the \LaTeXe{} interface for now as the L3 programming layer |
| 923 |
% doesn't have one for marks yet. |
| 924 |
% \begin{macrocode} |
| 925 |
\exp_args:Nc \newmarks {c_@@_class_ #1 _mark} |
| 926 |
% \end{macrocode} |
| 927 |
% Remember the new class in the sequence. |
| 928 |
% \begin{macrocode} |
| 929 |
\seq_gput_right:Nn \g_@@_classes_seq {#1} |
| 930 |
% \end{macrocode} |
| 931 |
% \begin{macrocode} |
| 932 |
\@@_init_region:nn {page}{#1} |
| 933 |
% \end{macrocode} |
| 934 |
% For the \texttt{page} region we also keep track of the |
| 935 |
% \texttt{previous-page}. |
| 936 |
% \begin{macrocode} |
| 937 |
\@@_init_region:nn {previous-page}{#1} |
| 938 |
% \end{macrocode} |
| 939 |
% Same game for \texttt{column} and \texttt{previous-column} |
| 940 |
% \begin{macrocode} |
| 941 |
\@@_init_region:nn {column}{#1} |
| 942 |
\@@_init_region:nn {previous-column}{#1} |
| 943 |
% \end{macrocode} |
| 944 |
% But for columns we also allocate token lists for the alias |
| 945 |
% regions \texttt{first-column} and \texttt{last-column}. |
| 946 |
% \begin{macrocode} |
| 947 |
\@@_init_region:nn {first-column}{#1} |
| 948 |
\@@_init_region:nn {last-column}{#1} |
| 949 |
% \end{macrocode} |
| 950 |
% To support multiple columns produced by the \pkg{multicol} |
| 951 |
% package, we preallocate twenty alias regions (since this is the number of columns that |
| 952 |
% \pkg{multicol} supports as a maximum). They are filled by copying |
| 953 |
% the current \texttt{column} into the appropriate \texttt{mcol-...}. |
| 954 |
% \begin{macrocode} |
| 955 |
%fmi \@@_init_region:nn {mcol}{#1} |
| 956 |
%fmi \@@_init_region:nn {previous-mcol}{#1} |
| 957 |
\@@_init_region:nn {mcol-1}{#1} |
| 958 |
\@@_init_region:nn {mcol-2}{#1} |
| 959 |
\@@_init_region:nn {mcol-3}{#1} |
| 960 |
\@@_init_region:nn {mcol-4}{#1} |
| 961 |
\@@_init_region:nn {mcol-5}{#1} |
| 962 |
\@@_init_region:nn {mcol-6}{#1} |
| 963 |
\@@_init_region:nn {mcol-7}{#1} |
| 964 |
\@@_init_region:nn {mcol-8}{#1} |
| 965 |
\@@_init_region:nn {mcol-9}{#1} |
| 966 |
\@@_init_region:nn {mcol-10}{#1} |
| 967 |
\@@_init_region:nn {mcol-11}{#1} |
| 968 |
\@@_init_region:nn {mcol-12}{#1} |
| 969 |
\@@_init_region:nn {mcol-13}{#1} |
| 970 |
\@@_init_region:nn {mcol-14}{#1} |
| 971 |
\@@_init_region:nn {mcol-15}{#1} |
| 972 |
\@@_init_region:nn {mcol-16}{#1} |
| 973 |
\@@_init_region:nn {mcol-17}{#1} |
| 974 |
\@@_init_region:nn {mcol-18}{#1} |
| 975 |
\@@_init_region:nn {mcol-19}{#1} |
| 976 |
\@@_init_region:nn {mcol-20}{#1} |
| 977 |
% \end{macrocode} |
| 978 |
% We also have to initialize the \texttt{saved-column} region that |
| 979 |
% is used in \pkg{multicol}. Perhaps we should have a |
| 980 |
% \cs{NewMarkRegion} so that it would be possible for other |
| 981 |
% packages to add further regions. But let's wait and see if there is a real |
| 982 |
% use case for new regions before making the interface more general. |
| 983 |
% \changes{v1.1d}{2025/06/19}{Also initialize saved-column region (SX chat)} |
| 984 |
% \begin{macrocode} |
| 985 |
\@@_init_region:nn {saved-column}{#1} |
| 986 |
} |
| 987 |
% \end{macrocode} |
| 988 |
% \end{macro} |
| 989 |
% |
| 990 |
% |
| 991 |
% \begin{macro}{\@@_init_region:nn,\c_@@_empty_tl} |
| 992 |
% \changes{v1.1b}{2024/12/03}{Fix inconsistent local/global assignment (gh/1574)} |
| 993 |
% |
| 994 |
% For each class (\texttt{\#2}) and region (\texttt{\#1}), we need |
| 995 |
% three token lists: one for top, first, and last. The default value to be |
| 996 |
% returned is \enquote{empty}. |
| 997 |
% \begin{macrocode} |
| 998 |
\cs_new_protected:Npn \@@_init_region:nn #1 #2 { |
| 999 |
\tl_new:c { g_@@_#1_top_ #2 _tl } |
| 1000 |
\tl_new:c { g_@@_#1_first_ #2 _tl } |
| 1001 |
\tl_new:c { g_@@_#1_last_ #2 _tl } |
| 1002 |
\tl_gset_eq:cN { g_@@_#1_top_ #2 _tl } \c_@@_empty_tl |
| 1003 |
\tl_gset_eq:cN { g_@@_#1_first_ #2 _tl } \c_@@_empty_tl |
| 1004 |
\tl_gset_eq:cN { g_@@_#1_last_ #2 _tl } \c_@@_empty_tl |
| 1005 |
} |
| 1006 |
% \end{macrocode} |
| 1007 |
% |
| 1008 |
% All marks will have an identification in the form of a |
| 1009 |
% number\footnote{There are a few cases where special |
| 1010 |
% identification strings are used, e.g., \texttt{2.09-compat}.} that is |
| 1011 |
% incremented each time a mark insertion happens; therefore the |
| 1012 |
% initial empty values should also have such a number, so that data extraction |
| 1013 |
% will be uniform. |
| 1014 |
% \changes{v1.0g}{2024/05/31}{Initialize all marks with an id, use |
| 1015 |
% \texttt{0} when a new class is made (gh/1359)} |
| 1016 |
% \begin{macrocode} |
| 1017 |
\tl_const:Nn \c_@@_empty_tl { \@@_value:nn{0}{} } |
| 1018 |
% \end{macrocode} |
| 1019 |
% \end{macro} |
| 1020 |
% |
| 1021 |
% |
| 1022 |
% \subsection{Updating mark structures} |
| 1023 |
% |
| 1024 |
% |
| 1025 |
% \begin{macro}{\l_@@_box,\l_@@_ii_box,\g_@@_tmp_tl,\g_@@_new_top_tl} |
| 1026 |
% For some operations we need two temporary private boxes and two |
| 1027 |
% private global token lists. |
| 1028 |
% \begin{macrocode} |
| 1029 |
\box_new:N \l_@@_box |
| 1030 |
\box_new:N \l_@@_ii_box |
| 1031 |
\tl_new:N \g_@@_tmp_tl |
| 1032 |
\tl_new:N \g_@@_new_top_tl |
| 1033 |
% \end{macrocode} |
| 1034 |
% \end{macro} |
| 1035 |
% |
| 1036 |
% |
| 1037 |
% |
| 1038 |
% \begin{macro}{\@@_extract_and_handle_marks:nn} |
| 1039 |
% \changes{v1.0e}{2024/01/29}{Macro added} |
| 1040 |
% |
| 1041 |
% This is the main macro to extract and handle marks inside some |
| 1042 |
% vertical material. It is used by |
| 1043 |
% \cs{mark_update_structure_from_material:nn} (for updating the mark |
| 1044 |
% structure for a region based on the marks found) and by |
| 1045 |
% \cs{mark_get_marks_for_reinsertion:nNN} (for extracting marks from |
| 1046 |
% some material and prepare for reinserting them later (e.g., out |
| 1047 |
% of a box that is placed as a box into the main galley). |
| 1048 |
% \begin{macrocode} |
| 1049 |
\cs_new_protected:Npn \@@_extract_and_handle_marks:nn #1#2 { |
| 1050 |
% \end{macrocode} |
| 1051 |
% This macro expects code to handle extracted marks in its first argument and |
| 1052 |
% vertical material (not boxed or just consisting of a single |
| 1053 |
% vertical box) as its second. It |
| 1054 |
% extracts top-level mark information from \verb/#2/, stores them |
| 1055 |
% as split marks and then calls |
| 1056 |
% \verb/#1/ to make use of this information. |
| 1057 |
% |
| 1058 |
% If it finds a forced break in the material it removes it and then |
| 1059 |
% restarts the attempt without it. |
| 1060 |
% |
| 1061 |
% We start with a group to keep most changes local. |
| 1062 |
% \begin{macrocode} |
| 1063 |
\group_begin: |
| 1064 |
% \end{macrocode} |
| 1065 |
% |
| 1066 |
% Getting the first and last marks out of the material in \verb=#2= |
| 1067 |
% is done by putting the material in a box and then doing a split |
| 1068 |
% operation to the maximum size possible (which hopefully gets us |
| 1069 |
% all of the content).\footnote{With normal column material cut |
| 1070 |
% from the main galley we should always get all material in one go, |
| 1071 |
% but in certain situations, for example, in a \pkg{multicols} |
| 1072 |
% environment that contains some \cs{columnbreak}s a single split |
| 1073 |
% operation will not be enough. Thus, this is something we need to |
| 1074 |
% handle.} Because this action is used only to get the mark |
| 1075 |
% values, we don't want any underfull box warnings so we (locally) |
| 1076 |
% turn those off. |
| 1077 |
% |
| 1078 |
% \begin{macrocode} |
| 1079 |
\dim_set_eq:NN \tex_splitmaxdepth:D \c_max_dim |
| 1080 |
\int_set_eq:NN \tex_vbadness:D \c_max_int |
| 1081 |
\dim_set_eq:NN \tex_vfuzz:D \c_max_dim |
| 1082 |
% \end{macrocode} |
| 1083 |
% |
| 1084 |
% There is a further complication: if the material contains infinite |
| 1085 |
% shrinking glue then a \tn{vsplit} operation will balk with a |
| 1086 |
% low-level error. Now pages or columns, which are our main concern |
| 1087 |
% here, can't have such infinite shrinkage if they are cut straight |
| 1088 |
% from the galley, however the use of \tn{enlargethispage} actually |
| 1089 |
% does add some at the very bottom (and also wraps the whole page |
| 1090 |
% into a box by itself, so if we leave it this way then a) we get |
| 1091 |
% this error and b) we don't see any marks because they are hidden |
| 1092 |
% one level down). |
| 1093 |
% |
| 1094 |
% Another possible issue are packages or user code that place stray |
| 1095 |
% \tn{vbox}es directly into the main galley (an example is |
| 1096 |
% \pkg{marginnote} that attaches its marginals in this way). If such |
| 1097 |
% boxes end up as the last item on the page we should not unpack |
| 1098 |
% them. |
| 1099 |
% |
| 1100 |
% All these issues need to be handled, which is done in |
| 1101 |
% \cs{@@_prepare_and_extract:nn}. |
| 1102 |
% |
| 1103 |
% \begin{macrocode} |
| 1104 |
\@@_prepare_and_extract:nn {#1} {#2} |
| 1105 |
% \end{macrocode} |
| 1106 |
% Once all mark classes have been processed, the data structures are |
| 1107 |
% updated and we can close the group, which undoes our local |
| 1108 |
% changes and retains only the global ones. |
| 1109 |
% \begin{macrocode} |
| 1110 |
\group_end: |
| 1111 |
} |
| 1112 |
% \end{macrocode} |
| 1113 |
% \end{macro} |
| 1114 |
% |
| 1115 |
% |
| 1116 |
% \begin{macro}{\@@_prepare_and_extract:nn} |
| 1117 |
% |
| 1118 |
% This macro does the dirty work. It is not directly integrated in |
| 1119 |
% \cs{@@_extract_and_handle_marks:nn} because we may have to call |
| 1120 |
% it recursively if we find forced breaks. |
| 1121 |
% \begin{macrocode} |
| 1122 |
\cs_new_protected:Npn \@@_prepare_and_extract:nn #1#2 { |
| 1123 |
% \end{macrocode} |
| 1124 |
% |
| 1125 |
% To handle the \cs{enlargethispage} case we do an \tn{unskip} to |
| 1126 |
% get rid of any glue that is present at the very end of the material |
| 1127 |
% and also check if we have then a \tn{vbox} as the last item and |
| 1128 |
% if so unpack that too, but only under certain conditions, see |
| 1129 |
% below. All this is temporary done in a group, just for getting |
| 1130 |
% the marks out, so it doesn't affect the final page production. |
| 1131 |
% |
| 1132 |
% \begin{macrocode} |
| 1133 |
\vbox_set:Nn \l_@@_box |
| 1134 |
{ |
| 1135 |
#2 |
| 1136 |
\tex_unskip:D |
| 1137 |
\box_set_to_last:N \l_@@_box |
| 1138 |
% \end{macrocode} |
| 1139 |
% After having removed the last box from the current list (if there |
| 1140 |
% was one) we check whether the vertical list is now empty. If not, |
| 1141 |
% then the last box is definitely not the one from |
| 1142 |
% \tn{enlargethispage} and so we can, and should, leave it |
| 1143 |
% alone. Otherwise we check if this last box is a \tn{vbox}. |
| 1144 |
% \changes{v1.0d}{2022/06/01}{Extend the logic for detecting the marks |
| 1145 |
% in the box (gh/836)} |
| 1146 |
% \begin{macrocode} |
| 1147 |
\int_compare:nNnT \tex_lastnodetype:D < 0 |
| 1148 |
{ |
| 1149 |
\box_if_vertical:NT \l_@@_box |
| 1150 |
% \end{macrocode} |
| 1151 |
% If it is, we unpack the box. |
| 1152 |
% \begin{macrocode} |
| 1153 |
{ \vbox_unpack:N \l_@@_box } |
| 1154 |
} |
| 1155 |
% \end{macrocode} |
| 1156 |
% If it wasn't a vbox, it was either an hbox or there was no box. |
| 1157 |
% Given that we are only interested in the marks we don't need put |
| 1158 |
% it back in that case. |
| 1159 |
% \begin{macrocode} |
| 1160 |
} |
| 1161 |
% \end{macrocode} |
| 1162 |
% We are now ready to \cs{vsplit} the box to get at the marks. If |
| 1163 |
% the box contains some infinite negative glue the \TeX{} will |
| 1164 |
% produce an error complaining about it but it will correctly find |
| 1165 |
% the split marks. Given that we can't prevent that error, we |
| 1166 |
% hide it from the user and ensure that \TeX{} doesn't stop. The |
| 1167 |
% error message still shows in the log, but even that is mitigated |
| 1168 |
% as best as possible---see the definition of |
| 1169 |
% \cs{@@_vbox_set_split_to_maxdimen:NN} for the tricks employed. |
| 1170 |
% \begin{macrocode} |
| 1171 |
\@@_vbox_set_split_to_maxdimen:NN \l_@@_ii_box \l_@@_box |
| 1172 |
% \end{macrocode} |
| 1173 |
% After splitting we check if there is anything left in |
| 1174 |
% \cs{l_@@_box}. If not then the above split has set some split marks |
| 1175 |
% that we can then use to finish the extraction: |
| 1176 |
% \begin{macrocode} |
| 1177 |
\box_if_empty:NTF \l_@@_box |
| 1178 |
{ #1 } |
| 1179 |
% \end{macrocode} |
| 1180 |
% If we have a remainder after the split then this means that there |
| 1181 |
% was some forced break in the material. We get rid of that by |
| 1182 |
% combining the content of the two boxes and restart. |
| 1183 |
% \begin{macrocode} |
| 1184 |
{ |
| 1185 |
%<*trace> |
| 1186 |
\@@_debug:n { \iow_term:x |
| 1187 |
{ Marks:~ mark~ extraction~needs~ recursion~ |
| 1188 |
\msg_line_context: } } |
| 1189 |
%</trace> |
| 1190 |
\@@_prepare_and_extract:nn {#1} |
| 1191 |
{ \vbox_unpack:N \l_@@_ii_box |
| 1192 |
\vbox_unpack:N \l_@@_box } |
| 1193 |
} |
| 1194 |
} |
| 1195 |
% \end{macrocode} |
| 1196 |
% \end{macro} |
| 1197 |
% |
| 1198 |
% |
| 1199 |
% \begin{macro}{\@@_vbox_set_split_to_maxdimen:NN} |
| 1200 |
% |
| 1201 |
% Split a box to get at its marks without pausing even if \TeX{} is |
| 1202 |
% producing an error message because of infinite negative glue in |
| 1203 |
% the box. If there is such an error we ensure that it only shows |
| 1204 |
% up in the log but not on the terminal. |
| 1205 |
% |
| 1206 |
% With a recent \TeX{} engine that knows the primitive |
| 1207 |
% \cs{ignoreprimitiveerror} we can turn this |
| 1208 |
% error into a warning (simply by setting this primitive to the value 1). |
| 1209 |
% \begin{macrocode} |
| 1210 |
\if_cs_exist:N \tex_ignoreprimitiveerror:D |
| 1211 |
% \end{macrocode} |
| 1212 |
% |
| 1213 |
% \changes{v1.1e}{2025/08/11}{Use \cs{ignoreprimitiveerror} if available (gh/1750)} |
| 1214 |
% \begin{macrocode} |
| 1215 |
\cs_new_protected:Npn \@@_vbox_set_split_to_maxdimen:NN #1#2 { |
| 1216 |
\tl_set:Ne \l_@@_saved_parameters_tl |
| 1217 |
{ \tex_ignoreprimitiveerror:D |
| 1218 |
\int_use:N \tex_ignoreprimitiveerror:D |
| 1219 |
\scan_stop: |
| 1220 |
} |
| 1221 |
\tex_ignoreprimitiveerror:D 1 \scan_stop: |
| 1222 |
\vbox_set_split_to_ht:NNn #1 #2 { \c_max_dim } |
| 1223 |
\l_@@_saved_parameters_tl |
| 1224 |
} |
| 1225 |
% \end{macrocode} |
| 1226 |
% With older \TeX{} engines we have to make use of David's hack |
| 1227 |
% below to render the error (fairly) harmless and prevent \TeX{} |
| 1228 |
% from stopping. But, of course, the above solution is better |
| 1229 |
% because jumping over the error with a local change to the |
| 1230 |
% interaction mode still means that \TeX{} thinks there was an |
| 1231 |
% error in the run so the return code is no longer 0 (and that |
| 1232 |
% might affect workflows that want to test for this). |
| 1233 |
% \begin{macrocode} |
| 1234 |
\else: |
| 1235 |
% \end{macrocode} |
| 1236 |
% |
| 1237 |
% The nice low-level hack by DPC records in the \texttt{.log} that a glue |
| 1238 |
% shrinkage error is harmless. |
| 1239 |
% |
| 1240 |
% We disguise \cs{c_max_dim} in an odd looking csname, which then |
| 1241 |
% shows up as part of the display of an error message if that error |
| 1242 |
% happens. This csname forms part of the error display so what |
| 1243 |
% you get is something like |
| 1244 |
%\begin{verbatim} |
| 1245 |
% ! Infinite glue shrinkage found in box being split. |
| 1246 |
% <argument> Infinite shrink error above ignored ! |
| 1247 |
% l. ... } |
| 1248 |
%\end{verbatim} |
| 1249 |
% which hopefully makes it clear that the error is harmless and |
| 1250 |
% and should be ignored by the reader of the \texttt{.log}. |
| 1251 |
% \begin{macrocode} |
| 1252 |
\cs_set_eq:cN {Infinite~shrink~error~above~ignored~!}\c_max_dim |
| 1253 |
% \end{macrocode} |
| 1254 |
% |
| 1255 |
% The whole definition of \cs{@@_vbox_set_split_to_maxdimen:NN} |
| 1256 |
% below is fully expanded, so we have to use a lot of |
| 1257 |
% \cs{exp_not:N} commands to prevent expansion where necessary. |
| 1258 |
% \begin{macrocode} |
| 1259 |
\cs_new_protected:Npx \@@_vbox_set_split_to_maxdimen:NN #1#2 { |
| 1260 |
% \end{macrocode} |
| 1261 |
% We start by saving the current interaction and escape char settings. |
| 1262 |
% \begin{macrocode} |
| 1263 |
\tl_set:Ne \exp_not:N \l_@@_saved_parameters_tl |
| 1264 |
{ |
| 1265 |
\tex_interactionmode:D |
| 1266 |
\exp_not:N \int_use:N \tex_interactionmode:D \scan_stop: |
| 1267 |
\tex_escapechar:D |
| 1268 |
\exp_not:N \int_use:N \tex_escapechar:D \scan_stop: |
| 1269 |
} |
| 1270 |
% \end{macrocode} |
| 1271 |
% Then we change them so that no escape char is printed in the |
| 1272 |
% error message (accounts for the missing backslash in front of |
| 1273 |
% \verb/Infinite shrink .../) and we set the interaction to |
| 1274 |
% \cs{nonstopmode} so that the error (if any) just goes into |
| 1275 |
% the \texttt{.log} file and \TeX{} doesn't stop at that point. |
| 1276 |
% \begin{macrocode} |
| 1277 |
\tex_escapechar:D -1 \scan_stop: |
| 1278 |
\tex_interactionmode:D 0 \scan_stop: |
| 1279 |
% \end{macrocode} |
| 1280 |
% Then we do the splitting of the box to \cs{c_max_dim} to get at |
| 1281 |
% the marks. This may generate the error we are worried about, |
| 1282 |
% i.e., if the box contains infinite negative glue. However, \TeX{} |
| 1283 |
% makes this glue finite and continues, which means we get our split |
| 1284 |
% marks which is really all we care about. |
| 1285 |
% \begin{macrocode} |
| 1286 |
\tex_setbox:D #1 \tex_vsplit:D #2 to |
| 1287 |
% \end{macrocode} |
| 1288 |
% The \cs{use:n} may seem pointless, and it is to some extent, but |
| 1289 |
% we need it to get our disguised \cs{c_max_dim} displayed |
| 1290 |
% properly as part of the error message if there is one. Without |
| 1291 |
% it, the display would show only part of what we want it to show |
| 1292 |
% (try it). |
| 1293 |
% \begin{macrocode} |
| 1294 |
\exp_not:N \use:n { |
| 1295 |
\use:c{Infinite~shrink~error~above~ignored~!} |
| 1296 |
} |
| 1297 |
% \end{macrocode} |
| 1298 |
% Finally, we change the escape char and the interaction mode back |
| 1299 |
% to what it was before: |
| 1300 |
% \begin{macrocode} |
| 1301 |
\exp_not:N \l_@@_saved_parameters_tl |
| 1302 |
} |
| 1303 |
% \end{macrocode} |
| 1304 |
% |
| 1305 |
% \begin{macrocode} |
| 1306 |
\fi: |
| 1307 |
% \end{macrocode} |
| 1308 |
% \end{macro} |
| 1309 |
% |
| 1310 |
% |
| 1311 |
% |
| 1312 |
% \begin{macro}{\l_@@_saved_parameters_tl} |
| 1313 |
% The temporary variable used for resetting escape char and |
| 1314 |
% interaction mode. |
| 1315 |
% \begin{macrocode} |
| 1316 |
\tl_new:N \l_@@_saved_parameters_tl |
| 1317 |
% \end{macrocode} |
| 1318 |
% \end{macro} |
| 1319 |
% |
| 1320 |
% \begin{macro}{\mark_update_structure_from_material:nn} |
| 1321 |
% |
| 1322 |
% \changes{v1.0e}{2024/01/29}{Macro renamed} |
| 1323 |
% |
| 1324 |
% This function updates the mark structures of a region. The first |
| 1325 |
% argument is the region to update and second argument receives the |
| 1326 |
% material that holds the marks. Out of this material we extract |
| 1327 |
% the first and last marks for all classes (if there are any) to do |
| 1328 |
% the assignments. |
| 1329 |
% |
| 1330 |
% \begin{macrocode} |
| 1331 |
\cs_new_protected:Npn \mark_update_structure_from_material:nn #1#2 { |
| 1332 |
\@@_extract_and_handle_marks:nn |
| 1333 |
% \end{macrocode} |
| 1334 |
% |
| 1335 |
% Once the marks can be extracted we update the structure from the |
| 1336 |
% split marks (code in \cs{@@_update_structure_from_splitmarks:n}). |
| 1337 |
% \begin{macrocode} |
| 1338 |
{ \@@_update_structure_from_splitmarks:n {#1} } |
| 1339 |
{ #2 } |
| 1340 |
} |
| 1341 |
% \end{macrocode} |
| 1342 |
% \end{macro} |
| 1343 |
% |
| 1344 |
% |
| 1345 |
% |
| 1346 |
% \begin{macro}{\@@_update_structure_from_splitmarks:n} |
| 1347 |
% This macro is called after we have done a \cs{tex_vsplit:D} |
| 1348 |
% operation and the mark data is in the split marks. |
| 1349 |
% \begin{macrocode} |
| 1350 |
\cs_new_protected:Npn \@@_update_structure_from_splitmarks:n #1 { |
| 1351 |
% \end{macrocode} |
| 1352 |
% |
| 1353 |
% The first thing we do is to copy the current region structure to |
| 1354 |
% \texttt{previous-...}; this leaves the current structure |
| 1355 |
% untouched so we can update it class by class (as is necessary). |
| 1356 |
% \begin{macrocode} |
| 1357 |
\mark_copy_structure:nn { previous-#1 } {#1} |
| 1358 |
% \end{macrocode} |
| 1359 |
% After this action we can get first and last marks of the various |
| 1360 |
% classes through \cs{tex_splitfirstmarks:D} and |
| 1361 |
% \cs{tex_splitbotmarks:D}. So now we loop over all classes stored in |
| 1362 |
% \cs{g_@@_classes_seq}. |
| 1363 |
% \begin{macrocode} |
| 1364 |
\seq_map_inline:Nn \g_@@_classes_seq |
| 1365 |
{ |
| 1366 |
% \end{macrocode} |
| 1367 |
% First action: get the last mark from the previous region, i.e., |
| 1368 |
% \verb=previous-#1=. But because it is also still inside \verb=#1=, |
| 1369 |
% at the moment we use that to construct the name because this is a |
| 1370 |
% tiny bit faster. Given that we |
| 1371 |
% need this value in various assignments we store it away which |
| 1372 |
% avoids unnecessary further csname generations. |
| 1373 |
% \begin{macrocode} |
| 1374 |
\tl_gset_eq:Nc \g_@@_new_top_tl { g_@@_#1_last_##1_tl } |
| 1375 |
% \end{macrocode} |
| 1376 |
% This will first of all become the new top mark for the current class. |
| 1377 |
% \begin{macrocode} |
| 1378 |
\tl_gset_eq:cN { g_@@_#1_top_##1_tl } \g_@@_new_top_tl |
| 1379 |
% \end{macrocode} |
| 1380 |
% Next action is to get ourselves the new last mark from the |
| 1381 |
% material supplied. |
| 1382 |
% \begin{macrocode} |
| 1383 |
\tl_gset:No \g_@@_tmp_tl |
| 1384 |
{ \tex_splitbotmarks:D \use:c { c_@@_class_##1_mark } } |
| 1385 |
% \end{macrocode} |
| 1386 |
% If this mark doesn't exist then obviously neither does the first mark, |
| 1387 |
% so both become the last mark from the previous region. We |
| 1388 |
% have to be a little careful here: something like |
| 1389 |
% \verb=\mark_insert:nn{foo}{}= adds an \enquote{empty} mark that should |
| 1390 |
% not be confused with no mark at all. But no mark in our material |
| 1391 |
% will result in \cs{g_@@_tmp_tl} being fully empty. This is why we |
| 1392 |
% have to make sure that \enquote{empty} from \cs{mark_insert:nn} only |
| 1393 |
% appears to be empty when typeset but fails the next test (see below how this |
| 1394 |
% is done). |
| 1395 |
% \begin{macrocode} |
| 1396 |
\tl_if_empty:NTF \g_@@_tmp_tl |
| 1397 |
{ |
| 1398 |
\tl_gset_eq:cN { g_@@_#1_last_ ##1_tl } |
| 1399 |
\g_@@_new_top_tl |
| 1400 |
\tl_gset_eq:cN { g_@@_#1_first_##1_tl } |
| 1401 |
\g_@@_new_top_tl |
| 1402 |
} |
| 1403 |
% \end{macrocode} |
| 1404 |
% If it wasn't empty, i.e., if it had a real value then we use this |
| 1405 |
% value for our new last mark instead. |
| 1406 |
% \begin{macrocode} |
| 1407 |
{ |
| 1408 |
\tl_gset_eq:cN { g_@@_#1_last_##1_tl } \g_@@_tmp_tl |
| 1409 |
% \end{macrocode} |
| 1410 |
% Because we had a last mark we also have a first mark (which |
| 1411 |
% might be the same, but might be not), so we pick that up and |
| 1412 |
% assign it to the appropriate token list. This explains why we first |
| 1413 |
% checked for the last mark because that makes the processing |
| 1414 |
% faster in case there is none. |
| 1415 |
% \begin{macrocode} |
| 1416 |
\tl_gset:co { g_@@_#1_first_##1_tl } |
| 1417 |
{ |
| 1418 |
\tex_splitfirstmarks:D |
| 1419 |
\use:c { c_@@_class_##1_mark } |
| 1420 |
} |
| 1421 |
} |
| 1422 |
} |
| 1423 |
} |
| 1424 |
% \end{macrocode} |
| 1425 |
% \end{macro} |
| 1426 |
% |
| 1427 |
% |
| 1428 |
% |
| 1429 |
% \begin{macro}{\mark_get_marks_for_reinsertion:nNN} |
| 1430 |
% |
| 1431 |
% This function extracts the marks from the material in the first |
| 1432 |
% argument but it does not update any the mark structures. Instead, |
| 1433 |
% it collects the marks in the token lists given as the second and |
| 1434 |
% third argument, in such a way that they can be reinserted by just |
| 1435 |
% executing the token lists.\footnote{It is probably enough to |
| 1436 |
% collect everything in a single token list as long as we put the |
| 1437 |
% first marks first and the last marks last). But for extra |
| 1438 |
% flexibility, I currently use 2 token lists. This might change when it is |
| 1439 |
% really clear that this is never needed.} |
| 1440 |
% |
| 1441 |
% \begin{macrocode} |
| 1442 |
\cs_new_protected:Npn \mark_get_marks_for_reinsertion:nNN #1#2#3 { |
| 1443 |
% \end{macrocode} |
| 1444 |
% First we clear the temporary token lists as we haven't seen any marks yet. |
| 1445 |
% \begin{macrocode} |
| 1446 |
\tl_gclear:N \g_@@_first_marks_tl |
| 1447 |
\tl_gclear:N \g_@@_last_marks_tl |
| 1448 |
% \end{macrocode} |
| 1449 |
% Then we extract all top-level marks, thereby filling the token lists |
| 1450 |
% with suitable \cs{mark_insert:nn} calls. |
| 1451 |
% \begin{macrocode} |
| 1452 |
\@@_extract_and_handle_marks:nn |
| 1453 |
% \end{macrocode} |
| 1454 |
% The first argument holds the code used for filling the token lists and |
| 1455 |
% the second holds the material from which all marks should be extracted. |
| 1456 |
% \begin{macrocode} |
| 1457 |
\@@_get_from_splitmarks: |
| 1458 |
{ #1 } |
| 1459 |
% \end{macrocode} |
| 1460 |
% |
| 1461 |
% Finally, we copy the updated (or not updated) temporary token |
| 1462 |
% lists to the two that have been supplied when the function was |
| 1463 |
% called. By convention \enquote{get} operations return their |
| 1464 |
% values in local variables and \cs{@@_extract_and_handle_marks:nn} |
| 1465 |
% runs in a group, which is why we have to use global temporary |
| 1466 |
% variables for collecting. |
| 1467 |
% \begin{macrocode} |
| 1468 |
\tl_set_eq:NN #2 \g_@@_first_marks_tl |
| 1469 |
\tl_set_eq:NN #3 \g_@@_last_marks_tl |
| 1470 |
} |
| 1471 |
% \end{macrocode} |
| 1472 |
% \end{macro} |
| 1473 |
% |
| 1474 |
% |
| 1475 |
% \begin{macro}{\@@_get_from_splitmarks:} |
| 1476 |
% This function is called after we have done a \cs{vsplit} to |
| 1477 |
% update the split marks. It loops through all mark classes to find |
| 1478 |
% out if there are marks for this class and if so updates the |
| 1479 |
% global tls used for collecting. |
| 1480 |
% \begin{macrocode} |
| 1481 |
\cs_new_protected:Npn \@@_get_from_splitmarks: { |
| 1482 |
\seq_map_inline:Nn \g_@@_classes_seq |
| 1483 |
{ |
| 1484 |
% \end{macrocode} |
| 1485 |
% First we to get the last mark for the current class from the |
| 1486 |
% material supplied. |
| 1487 |
% \begin{macrocode} |
| 1488 |
\tl_gset:No \g_@@_tmp_tl |
| 1489 |
{ \tex_splitbotmarks:D \use:c { c_@@_class_##1_mark } } |
| 1490 |
% \end{macrocode} |
| 1491 |
% |
| 1492 |
% If this mark doesn't exist then obviously first mark doesn't |
| 1493 |
% either, so we do nothing (other than issuing some debugging |
| 1494 |
% info). |
| 1495 |
|
| 1496 |
% We have to be a little careful here: something like |
| 1497 |
% \verb=\mark_insert:nn{foo}{}= adds an \enquote{empty} mark that |
| 1498 |
% we should not confuse with the case where there is no mark at |
| 1499 |
% all. |
| 1500 |
% |
| 1501 |
% When there is no mark at all we get a truly empty |
| 1502 |
% \cs{g_@@_tmp_tl} as a result. This is why we have to make sure |
| 1503 |
% that an \enquote{empty} mark generated with \cs{mark_insert:nn} |
| 1504 |
% only appears to be empty when it is typeset, but fails the next |
| 1505 |
% test (see below how this is done). |
| 1506 |
% \begin{macrocode} |
| 1507 |
\tl_if_empty:NTF \g_@@_tmp_tl |
| 1508 |
{ |
| 1509 |
%<*trace> |
| 1510 |
\@@_debug:n { \iow_term:x { Marks:~no~ marks~ |
| 1511 |
for~ class~ '##1'~\msg_line_context: } } |
| 1512 |
%</trace> |
| 1513 |
} |
| 1514 |
% \end{macrocode} |
| 1515 |
% |
| 1516 |
% If it wasn't empty, i.e., if it had a real value then we use this |
| 1517 |
% value for our new last mark instead. This means we put an |
| 1518 |
% appropriate \cs{mark_insert:nn} statement into |
| 1519 |
% \cs{g_@@_last_marks_tl}. |
| 1520 |
% \begin{macrocode} |
| 1521 |
{ |
| 1522 |
%<*trace> |
| 1523 |
\@@_debug:n { \iow_term:x { Marks:~ extract~ last~ |
| 1524 |
% \end{macrocode} |
| 1525 |
% The mark content in \cs{g_@@_tmp_tl} may contain aribtrary code |
| 1526 |
% that may react badly if it is expanded in a write. So we better |
| 1527 |
% avoid that expansion, otherwise debugging might generate spurious |
| 1528 |
% errors when turned on. |
| 1529 |
% \changes{v1.1c}{2025/01/10}{Do not expand mark content while debugging} |
| 1530 |
% \begin{macrocode} |
| 1531 |
mark~ for~ class~ '##1'~ =~ \exp_not:o \g_@@_tmp_tl } } |
| 1532 |
%</trace> |
| 1533 |
\tl_gput_right:Ne \g_@@_last_marks_tl |
| 1534 |
{ \mark_insert:nn {##1} { \@@_drop_id:o { \g_@@_tmp_tl } } } |
| 1535 |
% \end{macrocode} |
| 1536 |
% Because we had a last mark we also have a first mark (which might |
| 1537 |
% be the same, but might not be), so we pick that up and add it to |
| 1538 |
% the \cs{g_@@_first_marks_tl} token list. This explains why we |
| 1539 |
% first checked for the last mark because that makes the processing |
| 1540 |
% faster in case there is none. |
| 1541 |
% \begin{macrocode} |
| 1542 |
%<*trace> |
| 1543 |
\@@_debug:n { \iow_term:x { |
| 1544 |
Marks:~ extract~ first~ mark~ for~ class~ '##1'~ =~ |
| 1545 |
% \end{macrocode} |
| 1546 |
% Again no expansion for the mark content. |
| 1547 |
% \begin{macrocode} |
| 1548 |
\exp_not:o { |
| 1549 |
\tex_splitfirstmarks:D |
| 1550 |
\use:c { c_@@_class_##1_mark } |
| 1551 |
} |
| 1552 |
} } |
| 1553 |
%</trace> |
| 1554 |
\tl_gput_right:Ne \g_@@_first_marks_tl |
| 1555 |
{ \mark_insert:nn {##1} |
| 1556 |
{ |
| 1557 |
% \end{macrocode} |
| 1558 |
% We better drop the id from the returned value otherwise they |
| 1559 |
% will accumulate in the marks when reinserted. |
| 1560 |
% \begin{macrocode} |
| 1561 |
\@@_drop_id:o { |
| 1562 |
\tex_splitfirstmarks:D |
| 1563 |
\use:c { c_@@_class_##1_mark } |
| 1564 |
} |
| 1565 |
} |
| 1566 |
} |
| 1567 |
} |
| 1568 |
} |
| 1569 |
} |
| 1570 |
% \end{macrocode} |
| 1571 |
% \end{macro} |
| 1572 |
% |
| 1573 |
% |
| 1574 |
% \begin{macro}{\g_@@_first_marks_tl,\g_@@_last_marks_tl} |
| 1575 |
% These are two global temporary variables used in the code above. |
| 1576 |
% \begin{macrocode} |
| 1577 |
\tl_new:N \g_@@_first_marks_tl |
| 1578 |
\tl_new:N \g_@@_last_marks_tl |
| 1579 |
% \end{macrocode} |
| 1580 |
% \end{macro} |
| 1581 |
% |
| 1582 |
% |
| 1583 |
% \begin{macro}{\mark_copy_structure:nn} |
| 1584 |
% This function copies the structure for one region to another, |
| 1585 |
% e.g., from \texttt{page} to \texttt{previous-page} above, |
| 1586 |
% or later from \texttt{column} to \texttt{first-column}, etc. |
| 1587 |
% \changes{v1.1a}{2024/11/09}{Macro renamed} |
| 1588 |
% \begin{macrocode} |
| 1589 |
\cs_new_protected:Npn \mark_copy_structure:nn #1#2 { |
| 1590 |
% \end{macrocode} |
| 1591 |
% This requires a simple loop through all mark classes copying the |
| 1592 |
% token list from one name to the next. |
| 1593 |
% \begin{macrocode} |
| 1594 |
\seq_map_inline:Nn \g_@@_classes_seq |
| 1595 |
{ |
| 1596 |
\tl_gset_eq:cc { g_@@_ #1 _top_ ##1 _tl } |
| 1597 |
{ g_@@_ #2 _top_ ##1 _tl } |
| 1598 |
\tl_gset_eq:cc { g_@@_ #1 _first_ ##1 _tl } |
| 1599 |
{ g_@@_ #2 _first_ ##1 _tl } |
| 1600 |
\tl_gset_eq:cc { g_@@_ #1 _last_ ##1 _tl } |
| 1601 |
{ g_@@_ #2 _last_ ##1 _tl } |
| 1602 |
} |
| 1603 |
} |
| 1604 |
% \end{macrocode} |
| 1605 |
% \end{macro} |
| 1606 |
% |
| 1607 |
% |
| 1608 |
% \begin{macro}{\mark_clear_structure:n} |
| 1609 |
% This function sets the structure of one region back to an initial |
| 1610 |
% state, so that all classes return an empty value if queried. |
| 1611 |
% \changes{v1.1a}{2024/11/09}{} |
| 1612 |
% \begin{macrocode} |
| 1613 |
\cs_new_protected:Npn \mark_clear_structure:n #1 { |
| 1614 |
% \end{macrocode} |
| 1615 |
% This requires a simple loop through all mark classes. |
| 1616 |
% \begin{macrocode} |
| 1617 |
\seq_map_inline:Nn \g_@@_classes_seq |
| 1618 |
{ |
| 1619 |
\tl_gset_eq:cN { g_@@_ #1 _top_ ##1 _tl } |
| 1620 |
\c_@@_empty_tl |
| 1621 |
\tl_gset_eq:cN { g_@@_ #1 _first_ ##1 _tl } |
| 1622 |
\c_@@_empty_tl |
| 1623 |
\tl_gset_eq:cN { g_@@_ #1 _last_ ##1 _tl } |
| 1624 |
\c_@@_empty_tl |
| 1625 |
} |
| 1626 |
} |
| 1627 |
% \end{macrocode} |
| 1628 |
% \end{macro} |
| 1629 |
% |
| 1630 |
% |
| 1631 |
% |
| 1632 |
% \begin{macro}{\mark_set_structure_to_err:n,\@@_error:n} |
| 1633 |
% A slight variation is to install a fixed error message as the |
| 1634 |
% value. |
| 1635 |
% \begin{macrocode} |
| 1636 |
\cs_new_protected:Npn \mark_set_structure_to_err:n #1 { |
| 1637 |
\seq_map_inline:Nn \g_@@_classes_seq |
| 1638 |
{ |
| 1639 |
\tl_gset:ce { g_@@_ #1 _top_ ##1 _tl } { \@@_value:nn{?}{\@@_error:nn {#1}{?} }} |
| 1640 |
\tl_gset:ce { g_@@_ #1 _first_ ##1 _tl } { \@@_value:nn{?}{\@@_error:nn {#1}{?} }} |
| 1641 |
\tl_gset:ce { g_@@_ #1 _last_ ##1 _tl } { \@@_value:nn{?}{\@@_error:nn {#1}{?} }} |
| 1642 |
} |
| 1643 |
} |
| 1644 |
% \end{macrocode} |
| 1645 |
% Given that this is used in only one place, we could hardwire the |
| 1646 |
% argument which would be a bit more compact, but who knows, |
| 1647 |
% perhaps we end up with another reason to use this error command |
| 1648 |
% elsewhere, so for now we keep the argument. |
| 1649 |
% |
| 1650 |
% \begin{macrocode} |
| 1651 |
\cs_new_protected:Npn \@@_error:nn #1#2 { |
| 1652 |
\msg_error:nnnn { mark } { invalid-use } {#1} {#2} |
| 1653 |
} |
| 1654 |
% \end{macrocode} |
| 1655 |
% \end{macro} |
| 1656 |
% |
| 1657 |
% |
| 1658 |
% |
| 1659 |
% |
| 1660 |
% \subsection{Placing and retrieving marks} |
| 1661 |
% |
| 1662 |
% |
| 1663 |
% |
| 1664 |
% \begin{macro}{\mark_insert:nn} |
| 1665 |
% This function puts a mark for some \meta{class} at the current point. |
| 1666 |
% \begin{macrocode} |
| 1667 |
\cs_new_protected:Npn \mark_insert:nn #1#2 |
| 1668 |
{ |
| 1669 |
\seq_if_in:NnTF \g_@@_classes_seq {#1} |
| 1670 |
{ |
| 1671 |
% \end{macrocode} |
| 1672 |
% We need to pass the evaluated argument into the mark but protected |
| 1673 |
% commands should not expand including those protected using the \cs{protect} approach of |
| 1674 |
% \LaTeXe{}. We also disable \cs{label} and the |
| 1675 |
% like.\footnote{Straight copy from \texttt{latex.ltx} but is this |
| 1676 |
% even correct? At least a label in a running header makes little |
| 1677 |
% sense if it get set several times! Maybe that needs looking at in |
| 1678 |
% the 2e kernel.} |
| 1679 |
% |
| 1680 |
% At this point the code eventually should get a public |
| 1681 |
% (and a kernel) hook instead of a set of hardwired settings. |
| 1682 |
% \begin{macrocode} |
| 1683 |
\group_begin: |
| 1684 |
% \end{macrocode} |
| 1685 |
% Within the group we alter some comments, e.g, \cs{label} or |
| 1686 |
% \cs{index}, to do the right at this point. This is done in the |
| 1687 |
% kernel hook \cs{@kernel@before@insertmark} which is followed by |
| 1688 |
% the public hook \hook{insertmark} that can be used by packages to |
| 1689 |
% augment or alter that setup as necessary. |
| 1690 |
% \begin{macrocode} |
| 1691 |
\@kernel@before@insertmark |
| 1692 |
\hook_use:n { insertmark } |
| 1693 |
\unrestored@protected@xdef \g_@@_tmp_tl |
| 1694 |
{ |
| 1695 |
% \end{macrocode} |
| 1696 |
% To ensure that marks are unique we insert a hidden sequence |
| 1697 |
% marker at the beginning of the content of the mark containing the |
| 1698 |
% sequence number of the mark. |
| 1699 |
% \changes{v1.0f}{2024/05/30}{Use sequence marker to make all marks |
| 1700 |
% unique on nearby regions (gh/1359)} |
| 1701 |
% \begin{macrocode} |
| 1702 |
\@@_value:nn{ \int_use:N\g_@@_int }{#2} |
| 1703 |
} |
| 1704 |
%<*trace> |
| 1705 |
\@@_debug:n{ \iow_term:x { Marks:~ set~#1~<-~ |
| 1706 |
'\tl_to_str:V \g_@@_tmp_tl' ~ \msg_line_context: } } |
| 1707 |
%</trace> |
| 1708 |
\tex_marks:D \use:c { c_@@_class_ #1 _mark } |
| 1709 |
{ |
| 1710 |
% \end{macrocode} |
| 1711 |
% Here is the trick to avoid truly empty marks: if the result from |
| 1712 |
% the above processing is empty we add something which eventually |
| 1713 |
% becomes empty, but not immediately; otherwise we just put |
| 1714 |
% \cs{g_@@_tmp_tl} in. |
| 1715 |
% \begin{macrocode} |
| 1716 |
% This is no longer needed with 1.0f |
| 1717 |
% \tl_if_empty:NTF \g_@@_tmp_tl |
| 1718 |
% { \exp_not:n { \prg_do_nothing: } } |
| 1719 |
% { \exp_not:o { \g_@@_tmp_tl } } |
| 1720 |
\exp_not:o { \g_@@_tmp_tl } |
| 1721 |
} |
| 1722 |
\group_end: |
| 1723 |
% \end{macrocode} |
| 1724 |
% A mark introduces a possible break point and in certain |
| 1725 |
% situations that should not happen in vertical mode in \LaTeX{}. |
| 1726 |
% This may need some checking and possibly cleanup \ldots. |
| 1727 |
% \begin{macrocode} |
| 1728 |
\if@nobreak\ifvmode\nobreak\fi\fi |
| 1729 |
} |
| 1730 |
% \end{macrocode} |
| 1731 |
% If the mark class was not known, raise an error. |
| 1732 |
% \begin{macrocode} |
| 1733 |
{ |
| 1734 |
\msg_error:nnx { mark } { unknown-class } |
| 1735 |
{ \tl_to_str:n {#1} } |
| 1736 |
} |
| 1737 |
} |
| 1738 |
% \end{macrocode} |
| 1739 |
% \end{macro} |
| 1740 |
% |
| 1741 |
% |
| 1742 |
% \begin{macro}{\@@_value:nn} |
| 1743 |
% A hidden marker is placed into every mark added by |
| 1744 |
% \cs{mark_insert:nn}. It will not show up in the output but |
| 1745 |
% its argument (a counter value that is incremented) makes all |
| 1746 |
% marks unique so the test for \enquote{equal} is not fooled by two |
| 1747 |
% different marks having the same mark text. |
| 1748 |
% \changes{v1.0f}{2024/05/30}{Use sequence marker to make all marks |
| 1749 |
% unique on nearby regions (gh/1359)} |
| 1750 |
% \begin{macrocode} |
| 1751 |
\cs_new_protected:Npn \@@_value:nn #1#2 { #2 } |
| 1752 |
% \end{macrocode} |
| 1753 |
% \end{macro} |
| 1754 |
% |
| 1755 |
% |
| 1756 |
% \begin{macro}[int]{\@kernel@before@insertmark} |
| 1757 |
% \begin{macro}{insertmark} |
| 1758 |
% By default \cs{label}, \cs{index}, and \cs{glossary} do nothing |
| 1759 |
% when the mark is inserted. |
| 1760 |
% \begin{macrocode} |
| 1761 |
\int_new:N \g_@@_int |
| 1762 |
\cs_new:Npn \@kernel@before@insertmark { |
| 1763 |
\cs_set_eq:NN \label \scan_stop: |
| 1764 |
\cs_set_eq:NN \index \scan_stop: |
| 1765 |
\cs_set_eq:NN \glossary \scan_stop: |
| 1766 |
% \end{macrocode} |
| 1767 |
% We count each mark and use that to place a hidden marker in front |
| 1768 |
% of the mark text. To ensure that there is no overflow (very |
| 1769 |
% unlikely but you never know) we restart every 100000 marks. Thus, |
| 1770 |
% if somebody puts more than that number of marks on a single page |
| 1771 |
% you could construct a scenario in which that approach fails. |
| 1772 |
% \changes{v1.0f}{2024/05/30}{Use sequence marker to make all marks |
| 1773 |
% unique on nearby regions (gh/1359)} |
| 1774 |
% \begin{macrocode} |
| 1775 |
\int_compare:nNnTF \g_@@_int < {99999} |
| 1776 |
{ \int_gincr:N \g_@@_int } |
| 1777 |
{ \int_gzero:N \g_@@_int } |
| 1778 |
|
| 1779 |
} |
| 1780 |
% \end{macrocode} |
| 1781 |
% The public hook to augment the setup. |
| 1782 |
% \begin{macrocode} |
| 1783 |
\hook_new:n {insertmark} |
| 1784 |
% \end{macrocode} |
| 1785 |
% \end{macro} |
| 1786 |
% \end{macro} |
| 1787 |
% |
| 1788 |
% \begin{macro}[EXP]{\mark_use_top:nn, \mark_use_first:nn, \mark_use_last:nn} |
| 1789 |
% |
| 1790 |
% To retrieve the first, last or top region mark, we grab the |
| 1791 |
% appropriate value stored in the corresponding token list variable |
| 1792 |
% and pass its contents back. These functions should be used only |
| 1793 |
% in output routines and only after \cs{mark_update_structure_from_material:nn} has acted, |
| 1794 |
% otherwise their value will be wrong. |
| 1795 |
% |
| 1796 |
% \begin{macrocode} |
| 1797 |
\cs_new:Npn \mark_use_first:nn #1#2 { \@@_use_check:nnn { g_@@_#1_first_#2_tl } {#1} {#2} } |
| 1798 |
\cs_new:Npn \mark_use_last:nn #1#2 { \@@_use_check:nnn { g_@@_#1_last_#2_tl } {#1} {#2} } |
| 1799 |
\cs_new:Npn \mark_use_top:nn #1#2 { \@@_use_check:nnn { g_@@_#1_top_#2_tl } {#1} {#2} } |
| 1800 |
% \end{macrocode} |
| 1801 |
% |
| 1802 |
% If used with an unknown class or region these commands will generate an error. |
| 1803 |
% If that happens in an expandable context then the error |
| 1804 |
% generation is delayed (e.g., if used in a \cs{section}) and |
| 1805 |
% happens when the code is finally used in typesetting, e.g., in the |
| 1806 |
% TOC or a running header. |
| 1807 |
% If used in a \cs{typeout} you only see something like |
| 1808 |
% \verb=\__mark_error:n{page}=. |
| 1809 |
% This is not too good, but probably better than low-level errors, I |
| 1810 |
% guess, and I don't want to use an expandable error because of the |
| 1811 |
% size restrictions in such error messages. |
| 1812 |
% \changes{v1.1a}{2024/11/09}{} |
| 1813 |
% \begin{macrocode} |
| 1814 |
\cs_new:Npn \@@_use_check:nnn #1#2#3 { |
| 1815 |
\tl_if_eq:cNTF {#1} \relax |
| 1816 |
{ \@@_error:nn {#2} {#3} } |
| 1817 |
{ \@@_drop_id:v {#1} } |
| 1818 |
} |
| 1819 |
% \end{macrocode} |
| 1820 |
% |
| 1821 |
% Each mark starts with an id and while the id does not print it is |
| 1822 |
% nevertheless better to remove it when returning the mark, so that |
| 1823 |
% downstream manipulation of the data doesn't have to deal with it. |
| 1824 |
% \changes{v1.0g}{2024/05/31}{Remove the id when returning the mark value (gh/1359)} |
| 1825 |
% This is what the \cs{exp_not:o} accomplishes. |
| 1826 |
% \begin{macrocode} |
| 1827 |
\cs_new:Npn \@@_drop_id:n #1 { \exp_not:o { #1 } } |
| 1828 |
\cs_generate_variant:Nn \@@_drop_id:n { o, v } |
| 1829 |
% \end{macrocode} |
| 1830 |
% \end{macro} |
| 1831 |
% |
| 1832 |
% |
| 1833 |
% |
| 1834 |
% |
| 1835 |
% \subsection{Comparing mark values} |
| 1836 |
% |
| 1837 |
% |
| 1838 |
% |
| 1839 |
% \begin{macro}[TF,EXP]{\mark_if_eq:nnnn,\mark_if_eq:nnnnnn} |
| 1840 |
% Test if in a given region (\verb=#1=) for a given class |
| 1841 |
% (\verb=#2=) the marks in position \verb=#3= and \verb=#4= (top, |
| 1842 |
% first, or last) are identical |
| 1843 |
% \begin{macrocode} |
| 1844 |
\prg_new_conditional:Npnn \mark_if_eq:nnnn #1#2#3#4 { T , F , TF } |
| 1845 |
{ |
| 1846 |
\tl_if_eq:ccTF { g_@@_ #1 _#3_ #2 _tl } |
| 1847 |
{ g_@@_ #1 _#4_ #2 _tl } |
| 1848 |
\prg_return_true: |
| 1849 |
\prg_return_false: |
| 1850 |
} |
| 1851 |
% \end{macrocode} |
| 1852 |
% The fully general test (with two triplets of the form |
| 1853 |
% \meta{region}, \meta{class}, and \meta{position}) is this: |
| 1854 |
% \begin{macrocode} |
| 1855 |
\prg_new_conditional:Npnn \mark_if_eq:nnnnnn #1#2#3#4#5#6 { T , F , TF } |
| 1856 |
{ |
| 1857 |
\tl_if_eq:ccTF { g_@@_ #1 _#3_ #2 _tl } |
| 1858 |
{ g_@@_ #4 _#6_ #5 _tl } |
| 1859 |
\prg_return_true: |
| 1860 |
\prg_return_false: |
| 1861 |
} |
| 1862 |
% \end{macrocode} |
| 1863 |
% \end{macro} |
| 1864 |
% |
| 1865 |
% |
| 1866 |
% |
| 1867 |
% \subsection{Messages} |
| 1868 |
% |
| 1869 |
% Mark errors are \LaTeX{} kernel errors: |
| 1870 |
% \changes{v1.0d}{2022/06/01}{Marks are kernel errors} |
| 1871 |
% \begin{macrocode} |
| 1872 |
\prop_gput:Nnn \g_msg_module_type_prop { mark } { LaTeX } |
| 1873 |
% \end{macrocode} |
| 1874 |
% |
| 1875 |
% \begin{macrocode} |
| 1876 |
\msg_new:nnnn { mark } { class-already-defined } |
| 1877 |
{ Mark~class~'#1'~already~defined } |
| 1878 |
{ |
| 1879 |
\c__msg_coding_error_text_tl |
| 1880 |
LaTeX~was~asked~to~define~a~new~mark~class~called~'#1':~ |
| 1881 |
this~mark~class~already~exists. |
| 1882 |
\c__msg_return_text_tl |
| 1883 |
} |
| 1884 |
% \end{macrocode} |
| 1885 |
% |
| 1886 |
% \begin{macrocode} |
| 1887 |
\msg_new:nnnn { mark } { unknown-class } |
| 1888 |
{ Unknown~mark~class~'#1'. } |
| 1889 |
{ |
| 1890 |
\c__msg_coding_error_text_tl |
| 1891 |
LaTeX~was~asked~to~manipulate~a~mark~of~class~'#1',~ |
| 1892 |
but~this~class~of~marks~does~not~exist. |
| 1893 |
} |
| 1894 |
% \end{macrocode} |
| 1895 |
% |
| 1896 |
% The next error can also happen if the mark class is unknown, so this |
| 1897 |
% should perhaps be separated into two different errors. |
| 1898 |
% \begin{macrocode} |
| 1899 |
\msg_new:nnnn { mark } { invalid-use } |
| 1900 |
{ Mark~region~'#1'~not~usable~or~class~'#2'~unknown } |
| 1901 |
{ |
| 1902 |
\c__msg_coding_error_text_tl |
| 1903 |
The~region~'#1'~is~either~not~known~or~data~for~it~ |
| 1904 |
still~needs~to~be~assembled,~e.g.,~last-column~ |
| 1905 |
while~building~the~first-column.~ |
| 1906 |
Also~possible:~the~class~namne~'#2'~is~misspelled. |
| 1907 |
\c__msg_return_text_tl |
| 1908 |
} |
| 1909 |
% \end{macrocode} |
| 1910 |
% |
| 1911 |
% |
| 1912 |
% |
| 1913 |
% |
| 1914 |
% |
| 1915 |
% \subsection{Debugging the mark structures} |
| 1916 |
% |
| 1917 |
% Code and commands in this section are not final, it needs more |
| 1918 |
% experimentation to see what kind of tracing information is going to |
| 1919 |
% be useful in practice. For now the tracing is mainly meant to be used |
| 1920 |
% for code testing and not so much for application testing. |
| 1921 |
% |
| 1922 |
% It is quite likely that the |
| 1923 |
% commands and the behavior of the tracing might change in the |
| 1924 |
% future once we gained some experience with it. |
| 1925 |
% |
| 1926 |
% \begin{macro}{\g_@@_debug_bool} |
| 1927 |
% Holds the current debugging state. |
| 1928 |
% \begin{macrocode} |
| 1929 |
\bool_new:N \g_@@_debug_bool |
| 1930 |
% \end{macrocode} |
| 1931 |
% \end{macro} |
| 1932 |
% |
| 1933 |
% \begin{macro}{\mark_debug_on:,\mark_debug_off:} |
| 1934 |
% \begin{macro}{\@@_debug:n} |
| 1935 |
% \begin{macro}{\@@_debug_gset:} |
| 1936 |
% Turns debugging on and off by redefining \cs{@@_debug:n}. |
| 1937 |
% \begin{macrocode} |
| 1938 |
\cs_new_eq:NN \@@_debug:n \use_none:n |
| 1939 |
\cs_new_protected:Npn \mark_debug_on: |
| 1940 |
{ |
| 1941 |
\bool_gset_true:N \g_@@_debug_bool |
| 1942 |
\@@_debug_gset: |
| 1943 |
} |
| 1944 |
\cs_new_protected:Npn \mark_debug_off: |
| 1945 |
{ |
| 1946 |
\bool_gset_false:N \g_@@_debug_bool |
| 1947 |
\@@_debug_gset: |
| 1948 |
} |
| 1949 |
\cs_new_protected:Npn \@@_debug_gset: |
| 1950 |
{ |
| 1951 |
\cs_gset_protected:Npx \@@_debug:n ##1 |
| 1952 |
{ \bool_if:NT \g_@@_debug_bool {##1} } |
| 1953 |
} |
| 1954 |
% \end{macrocode} |
| 1955 |
% \end{macro} |
| 1956 |
% \end{macro} |
| 1957 |
% \end{macro} |
| 1958 |
% |
| 1959 |
% |
| 1960 |
% |
| 1961 |
% \begin{macro}{\DebugMarksOn,\DebugMarksOff} |
| 1962 |
% CamelCase commands for debugging. |
| 1963 |
% \begin{macrocode} |
| 1964 |
\cs_new_eq:NN \DebugMarksOn \mark_debug_on: |
| 1965 |
\cs_new_eq:NN \DebugMarksOff \mark_debug_off: |
| 1966 |
% \end{macrocode} |
| 1967 |
% \end{macro} |
| 1968 |
% |
| 1969 |
% |
| 1970 |
% |
| 1971 |
% \begin{macro}{\@@_class_status:nnn} |
| 1972 |
% Shows the mark values across all regions for one mark class |
| 1973 |
% (\verb=#2=). |
| 1974 |
% |
| 1975 |
% The first argument gives some \meta{info} to help |
| 1976 |
% in identifying where the command was called, the second is |
| 1977 |
% the class and the third holds the number of \texttt{mcol-...} we |
| 1978 |
% should display: inside a \env{multicols} environment this will be \cs{col@number}, |
| 1979 |
% in \LaTeX{}'s normal output routines it will be \texttt{0}. |
| 1980 |
% \changes{v1.1a}{2024/11/09}{Add a third argument} |
| 1981 |
% \begin{macrocode} |
| 1982 |
%<*trace> |
| 1983 |
\cs_new_protected:Npn \@@_class_status:nnn #1#2#3 { |
| 1984 |
\typeout{ Marks:~#2~ #1:} |
| 1985 |
\@@_region_status:nnn {#2}{ page~ (previous) } { previous-page } |
| 1986 |
\@@_region_status:nnn {#2}{ page~ (current)~ } { page } |
| 1987 |
\@@_region_status:nnn {#2}{ column~ (previous) }{ previous-column } |
| 1988 |
\@@_region_status:nnn {#2}{ column~ (current)~ }{ column } |
| 1989 |
\@@_region_status:nnn {#2}{ column~ (first) } { first-column } |
| 1990 |
\@@_region_status:nnn {#2}{ column~ (last)~ } { last-column } |
| 1991 |
% \end{macrocode} |
| 1992 |
% Then finish by displaying a subset of the \texttt{mcol-...} regions: none (\texttt{0}) |
| 1993 |
% in the standard \LaTeX{} output routine and \cs{col@number} |
| 1994 |
% within a \env{multicols} environment. |
| 1995 |
% \begin{macrocode} |
| 1996 |
\int_step_inline:nn {#3} |
| 1997 |
{ |
| 1998 |
\@@_region_status:nnn {#2}{ column~ (##1)~ } { mcol-##1 } |
| 1999 |
} |
| 2000 |
} |
| 2001 |
% \end{macrocode} |
| 2002 |
% \end{macro} |
| 2003 |
% |
| 2004 |
% |
| 2005 |
% \begin{macro}{\@@_region_status:nnn} |
| 2006 |
% |
| 2007 |
% Display the top, first, and last mark of a region unless none of |
| 2008 |
% them exist or all of them are empty. |
| 2009 |
% \begin{macrocode} |
| 2010 |
\cs_new_protected:Npn \@@_region_status:nnn #1#2#3 { |
| 2011 |
\group_begin: |
| 2012 |
\cs_set:Npn \@@_value:nn ##1##2{ \exp_not:n{ {##1} ~ ##2 } } |
| 2013 |
\tl_if_exist:cT { g_@@_#3_last_ #1 _tl } |
| 2014 |
{ |
| 2015 |
\tl_if_eq:cNF { g_@@_#3_last_ #1 _tl } \c_@@_empty_tl |
| 2016 |
{ |
| 2017 |
\typeout{\@spaces #2 = |
| 2018 |
~|~ \use:c { g_@@_#3_top_ #1 _tl } ~|~ |
| 2019 |
\use:c { g_@@_#3_first_ #1 _tl } ~|~ |
| 2020 |
\use:c { g_@@_#3_last_ #1 _tl } ~| |
| 2021 |
} |
| 2022 |
} |
| 2023 |
} |
| 2024 |
\group_end: |
| 2025 |
} |
| 2026 |
% \end{macrocode} |
| 2027 |
% \end{macro} |
| 2028 |
% |
| 2029 |
% |
| 2030 |
% \begin{macro}{\@@_status:nn} |
| 2031 |
% Show a snapshot of all mark class values across all regions. The |
| 2032 |
% first argument is a string to identify the output, the second |
| 2033 |
% argument is the number of \texttt{mcol-...} regions to show. Outside |
| 2034 |
% of a \env{multicols} environment this is normally set to 0. |
| 2035 |
% \changes{v1.1a}{2024/11/09}{Add a second argument} |
| 2036 |
% \begin{macrocode} |
| 2037 |
\cs_new_protected:Npn \@@_status:nn #1#2 |
| 2038 |
{ |
| 2039 |
\seq_map_inline:Nn \g_@@_classes_seq |
| 2040 |
{ \@@_class_status:nnn {#1} {##1} {#2} } |
| 2041 |
} |
| 2042 |
%</trace> |
| 2043 |
% \end{macrocode} |
| 2044 |
% \end{macro} |
| 2045 |
% |
| 2046 |
% |
| 2047 |
% \begin{macro}{\ShowMarksAt} |
| 2048 |
% \changes{v1.0e}{2024/01/29}{Macro added} |
| 2049 |
% Debugging helper that displays a snapshot of all known mark |
| 2050 |
% structures. The first argument is a text string that is |
| 2051 |
% displayed to help identifying when the snapshot was made. The |
| 2052 |
% optional second one determines how many \texttt{mcol-...} regions |
| 2053 |
% are displayed (by default 4). |
| 2054 |
% |
| 2055 |
% This may not stay like this (or at all), which is why it isn't |
| 2056 |
% yet documented as an official command. |
| 2057 |
% \begin{macrocode} |
| 2058 |
\NewDocumentCommand \ShowMarksAt {m O{4} } { |
| 2059 |
%<*trace> |
| 2060 |
\@@_debug:n { \@@_status:nn {#1}{#2} } |
| 2061 |
%</trace> |
| 2062 |
} |
| 2063 |
% \end{macrocode} |
| 2064 |
% \end{macro} |
| 2065 |
% |
| 2066 |
% |
| 2067 |
% \subsection{Designer-level interfaces} |
| 2068 |
% |
| 2069 |
% |
| 2070 |
% \begin{macro}{\NewMarkClass,\InsertMark} |
| 2071 |
% These two are identical to the L3 programming layer commands. |
| 2072 |
% \begin{macrocode} |
| 2073 |
\cs_new_eq:NN \NewMarkClass \mark_new_class:n |
| 2074 |
\@onlypreamble \NewMarkClass |
| 2075 |
% \end{macrocode} |
| 2076 |
% |
| 2077 |
% \begin{macrocode} |
| 2078 |
\cs_new_eq:NN \InsertMark \mark_insert:nn |
| 2079 |
% \end{macrocode} |
| 2080 |
% \end{macro} |
| 2081 |
% |
| 2082 |
% |
| 2083 |
% \begin{macro}[EXP]{\TopMark, \FirstMark, \LastMark} |
| 2084 |
% The following commands take an optional argument that defaults to |
| 2085 |
% page. There is no checking that the region is actually valid. If |
| 2086 |
% not there is simply an empty return. |
| 2087 |
% \begin{macrocode} |
| 2088 |
\NewExpandableDocumentCommand \FirstMark { O{page} m } |
| 2089 |
{ \mark_use_first:nn {#1}{#2} } |
| 2090 |
% \end{macrocode} |
| 2091 |
% |
| 2092 |
% \begin{macrocode} |
| 2093 |
\NewExpandableDocumentCommand \LastMark { O{page} m } |
| 2094 |
{ \mark_use_last:nn {#1}{#2} } |
| 2095 |
% \end{macrocode} |
| 2096 |
% |
| 2097 |
% \begin{macrocode} |
| 2098 |
\NewExpandableDocumentCommand \TopMark { O{page} m } |
| 2099 |
{ \mark_use_top:nn {#1}{#2} } |
| 2100 |
% \end{macrocode} |
| 2101 |
% \end{macro} |
| 2102 |
% |
| 2103 |
% |
| 2104 |
% |
| 2105 |
% \begin{macro}[EXP]{\IfMarksEqualTF,\IfMarksEqualT,\IfMarksEqualF} |
| 2106 |
% \changes{v1.0h}{2024/10/21}{Define \cs{IfMarksEqualT}, \cs{IfMarksEqualF}} |
| 2107 |
% We only provide CamelCase commands for the case with one region |
| 2108 |
% (optional) and one class. One could think of also providing a |
| 2109 |
% version for the general case with several optional arguments, but |
| 2110 |
% use cases for this are most likely rare, so not done yet. |
| 2111 |
% \begin{macrocode} |
| 2112 |
\NewExpandableDocumentCommand \IfMarksEqualTF {O{page}mmm} { |
| 2113 |
\mark_if_eq:nnnnTF {#1}{#2}{#3}{#4} |
| 2114 |
} |
| 2115 |
\NewExpandableDocumentCommand \IfMarksEqualT {O{page}mmm} { |
| 2116 |
\mark_if_eq:nnnnT {#1}{#2}{#3}{#4} |
| 2117 |
} |
| 2118 |
\NewExpandableDocumentCommand \IfMarksEqualF {O{page}mmm} { |
| 2119 |
\mark_if_eq:nnnnF {#1}{#2}{#3}{#4} |
| 2120 |
} |
| 2121 |
% \end{macrocode} |
| 2122 |
% \end{macro} |
| 2123 |
% |
| 2124 |
% |
| 2125 |
% |
| 2126 |
% |
| 2127 |
% \section{\LaTeXe{} integration} |
| 2128 |
% |
| 2129 |
% \subsection{Core \LaTeXe{} integration} |
| 2130 |
% |
| 2131 |
% \begin{macro}{\@@_update_singlecol_structures:} |
| 2132 |
% This command updates the mark structures if we are producing a |
| 2133 |
% single column document. |
| 2134 |
% \begin{macrocode} |
| 2135 |
\cs_new_protected:Npn \@@_update_singlecol_structures: { |
| 2136 |
% \end{macrocode} |
| 2137 |
% First we update the \texttt{page} region (which also updates the |
| 2138 |
% \texttt{previous-page}. |
| 2139 |
% |
| 2140 |
% The \cs{@outputbox} is normally in \cs{vbox} in \LaTeX{} but we |
| 2141 |
% can't take that for granted (an \pkg{amsmath} test document |
| 2142 |
% changed it to an \cs{hbox} just to trip me up) so we are a little |
| 2143 |
% careful with unpack now. |
| 2144 |
% \begin{macrocode} |
| 2145 |
\box_if_vertical:NTF \@outputbox |
| 2146 |
{ |
| 2147 |
\mark_update_structure_from_material:nn {page} |
| 2148 |
{ \vbox_unpack:N \@outputbox } |
| 2149 |
} |
| 2150 |
{ |
| 2151 |
\mark_update_structure_from_material:nn {page} |
| 2152 |
{ \hbox_unpack:N \@outputbox } |
| 2153 |
} |
| 2154 |
% \end{macrocode} |
| 2155 |
% Then we provide the necessary updates for the aliases. |
| 2156 |
% \begin{macrocode} |
| 2157 |
\mark_copy_structure:nn {previous-column}{previous-page} |
| 2158 |
\mark_copy_structure:nn {column}{page} |
| 2159 |
\mark_copy_structure:nn {first-column}{page} |
| 2160 |
\mark_copy_structure:nn {last-column}{page} |
| 2161 |
%<*trace> |
| 2162 |
% move this into status itself? |
| 2163 |
\@@_debug:n |
| 2164 |
{ |
| 2165 |
\@@_status:nn |
| 2166 |
{ in~ OR~ ( |
| 2167 |
\legacy_if:nTF {@twoside} |
| 2168 |
{ twoside- |
| 2169 |
\int_if_odd:nTF \c@page |
| 2170 |
{ odd }{ even } |
| 2171 |
} |
| 2172 |
{ oneside } |
| 2173 |
) |
| 2174 |
} |
| 2175 |
{0} |
| 2176 |
} |
| 2177 |
%</trace> |
| 2178 |
} |
| 2179 |
% \end{macrocode} |
| 2180 |
% \end{macro} |
| 2181 |
% |
| 2182 |
% \begin{macro}{\@@_update_dblcol_structures:} |
| 2183 |
% This commands handles the updates if we are doing two-column pages. |
| 2184 |
% \begin{macrocode} |
| 2185 |
\cs_new_protected:Npn \@@_update_dblcol_structures: { |
| 2186 |
% \end{macrocode} |
| 2187 |
% First we update the \texttt{column} and \texttt{previous-column} |
| 2188 |
% regions using the material assembled in \cs{@outputbox}. |
| 2189 |
% \begin{macrocode} |
| 2190 |
\box_if_vertical:NTF \@outputbox |
| 2191 |
{ |
| 2192 |
\mark_update_structure_from_material:nn {column} |
| 2193 |
{ \vbox_unpack:N \@outputbox } |
| 2194 |
} |
| 2195 |
{ |
| 2196 |
\mark_update_structure_from_material:nn {column} |
| 2197 |
{ \hbox_unpack:N \@outputbox } |
| 2198 |
} |
| 2199 |
% \end{macrocode} |
| 2200 |
% How we have to update the alias regions depends on whether or not |
| 2201 |
% \cs{@opcol} was called to process the first column or to produce |
| 2202 |
% the completed page |
| 2203 |
% \begin{macrocode} |
| 2204 |
\legacy_if:nTF {@firstcolumn} |
| 2205 |
{ |
| 2206 |
% \end{macrocode} |
| 2207 |
% If we are processing the first column then \texttt{column} is our |
| 2208 |
% \texttt{first-column} and there is no \texttt{last-column} yet, |
| 2209 |
% so we make those an error. |
| 2210 |
% \begin{macrocode} |
| 2211 |
\mark_copy_structure:nn {first-column}{column} |
| 2212 |
\mark_set_structure_to_err:n {last-column} |
| 2213 |
} |
| 2214 |
{ |
| 2215 |
% \end{macrocode} |
| 2216 |
% If we produce the completed page then the \texttt{first-column} |
| 2217 |
% is the same as the new \texttt{previous-column}. However, the |
| 2218 |
% structure should already be correct if you think about it |
| 2219 |
% (because is was set to \texttt{column} last time which is now the |
| 2220 |
% \texttt{previous-column}), thus there is no need to make an update. |
| 2221 |
% \begin{macrocode} |
| 2222 |
% \mark_copy_structure:nn {first-column}{previous-column} |
| 2223 |
% \end{macrocode} |
| 2224 |
% However, we now have a proper \texttt{last-column} so we assign that. |
| 2225 |
% \begin{macrocode} |
| 2226 |
\mark_copy_structure:nn {last-column}{column} |
| 2227 |
% \end{macrocode} |
| 2228 |
% What now remains doing is to update the \texttt{page} and |
| 2229 |
% \texttt{previous-page} regions. For this we have to copy the |
| 2230 |
% settings in \texttt{page} into \texttt{previous-page} and then |
| 2231 |
% update \texttt{page} such that the top and first marks are taken |
| 2232 |
% from the \texttt{first-column} region and the last marks are |
| 2233 |
% taken from the \texttt{last-column} region. All this has to be |
| 2234 |
% done for all mark classes so we loop over our sequence. |
| 2235 |
% |
| 2236 |
% Note that one loop is needed if we arrange the copy statements in |
| 2237 |
% a suitable way. |
| 2238 |
% \begin{macrocode} |
| 2239 |
\seq_map_inline:Nn \g_@@_classes_seq |
| 2240 |
{ |
| 2241 |
% \end{macrocode} |
| 2242 |
% The \texttt{previous-page} updates need to come before the |
| 2243 |
% updates for \texttt{page} region because otherwise the values |
| 2244 |
% to copy are already overwritten. |
| 2245 |
% necessary values. |
| 2246 |
% \begin{macrocode} |
| 2247 |
\tl_gset_eq:cc { g_@@_previous-page_top_ ##1 _tl } |
| 2248 |
{ g_@@_page_top_ ##1 _tl } |
| 2249 |
\tl_gset_eq:cc { g_@@_previous-page_first_ ##1 _tl } |
| 2250 |
{ g_@@_page_first_ ##1 _tl } |
| 2251 |
\tl_gset_eq:cc { g_@@_previous-page_last_ ##1 _tl } |
| 2252 |
{ g_@@_page_last_ ##1 _tl } |
| 2253 |
% \end{macrocode} |
| 2254 |
% To update the \texttt{top} we only have to copy what is in |
| 2255 |
% \texttt{first-column}: |
| 2256 |
% \begin{macrocode} |
| 2257 |
\tl_gset_eq:cc { g_@@_page_top_ ##1 _tl } |
| 2258 |
{ g_@@_first-column_top_ ##1 _tl } |
| 2259 |
|
| 2260 |
% \end{macrocode} |
| 2261 |
% Updating the \texttt{first} mark for the \texttt{page} region is |
| 2262 |
% more complicated. We first have to find out of there is any mark |
| 2263 |
% in the first column (this can be done by comparing the \texttt{top} and |
| 2264 |
% the \texttt{first} mark of that region). |
| 2265 |
% \changes{v1.0f}{2024/05/30}{Correct logic for first mark in page |
| 2266 |
% region if first column contains no marks (gh/1359)} |
| 2267 |
% \begin{macrocode} |
| 2268 |
\tl_if_eq:ccTF { g__@@_first-column_top_ ##1 _tl } |
| 2269 |
{ g__@@_first-column_first_ ##1 _tl } |
| 2270 |
{ |
| 2271 |
% \end{macrocode} |
| 2272 |
% If there is no mark in the first column we copy the first mark of |
| 2273 |
% the last column. If that doesn't contain a mark we still get the |
| 2274 |
% right result because the first mark is then equal to the top mark. |
| 2275 |
% \begin{macrocode} |
| 2276 |
\tl_gset_eq:cc { g_@@_page_first_ ##1 _tl } |
| 2277 |
{ g_@@_last-column_first_ ##1 _tl } |
| 2278 |
} |
| 2279 |
{ |
| 2280 |
% \end{macrocode} |
| 2281 |
% On the other hand, if there is a mark in the first column we copy |
| 2282 |
% over the \texttt{first} mark from that column. |
| 2283 |
% \begin{macrocode} |
| 2284 |
\tl_gset_eq:cc { g_@@_page_first_ ##1 _tl } |
| 2285 |
{ g_@@_first-column_first_ ##1 _tl } |
| 2286 |
} |
| 2287 |
% \end{macrocode} |
| 2288 |
% The logic for the \texttt{last} page mark is again simple, we can |
| 2289 |
% just copy the value in the \texttt{last} mark of the last column. |
| 2290 |
% If that column doesn't contain any marks, then the value in |
| 2291 |
% \texttt{last} will be automatically the same as the \texttt{last} |
| 2292 |
% from the first column. |
| 2293 |
% \begin{macrocode} |
| 2294 |
\tl_gset_eq:cc { g_@@_page_last_ ##1 _tl } |
| 2295 |
{ g_@@_last-column_last_ ##1 _tl } |
| 2296 |
} |
| 2297 |
} |
| 2298 |
%<*trace> |
| 2299 |
\@@_debug:n |
| 2300 |
{ |
| 2301 |
\@@_status:nn |
| 2302 |
{ in~ OR~ ( |
| 2303 |
\legacy_if:nTF {@twoside} |
| 2304 |
{ twoside- |
| 2305 |
\int_if_odd:nTF \c@page |
| 2306 |
{ odd }{ even } |
| 2307 |
} |
| 2308 |
{ oneside } |
| 2309 |
\space |
| 2310 |
\legacy_if:nTF {@firstcolumn} |
| 2311 |
{ first~ }{ second~ } |
| 2312 |
column ) |
| 2313 |
} |
| 2314 |
{0} |
| 2315 |
} |
| 2316 |
%</trace> |
| 2317 |
} |
| 2318 |
% \end{macrocode} |
| 2319 |
% \end{macro} |
| 2320 |
% |
| 2321 |
% |
| 2322 |
% |
| 2323 |
% \subsection{Other \LaTeXe{} output routines} |
| 2324 |
% |
| 2325 |
% This section will cover support for packages that alter the |
| 2326 |
% \LaTeX{} output routine (as necessary). The support for |
| 2327 |
% \pkg{multicol} (for now) is handled directly in that package. |
| 2328 |
% |
| 2329 |
% |
| 2330 |
% |
| 2331 |
% |
| 2332 |
% \begin{macrocode} |
| 2333 |
%<@@=> |
| 2334 |
% \end{macrocode} |
| 2335 |
% |
| 2336 |
|
| 2337 |
|
| 2338 |
% \begin{macro}[int]{\@expl@@@mark@update@singlecol@structures@@} |
| 2339 |
% \begin{macrocode} |
| 2340 |
\cs_new_eq:NN \@expl@@@mark@update@singlecol@structures@@ |
| 2341 |
\__mark_update_singlecol_structures: |
| 2342 |
% \end{macrocode} |
| 2343 |
% \end{macro} |
| 2344 |
% |
| 2345 |
% |
| 2346 |
% |
| 2347 |
% \begin{macro}[int]{\@expl@@@mark@update@dblcol@structures@@} |
| 2348 |
% \begin{macrocode} |
| 2349 |
\cs_new_eq:NN \@expl@@@mark@update@dblcol@structures@@ |
| 2350 |
\__mark_update_dblcol_structures: |
| 2351 |
% \end{macrocode} |
| 2352 |
% \end{macro} |
| 2353 |
% |
| 2354 |
% |
| 2355 |
% |
| 2356 |
% |
| 2357 |
% \subsection{Rollback information} |
| 2358 |
% |
| 2359 |
% |
| 2360 |
% \begin{macrocode} |
| 2361 |
%<latexrelease>\IncludeInRelease{0000/00/00}{ltmarks}% |
| 2362 |
%<latexrelease> {Undo~Marks~handling} |
| 2363 |
%<latexrelease> |
| 2364 |
% \end{macrocode} |
| 2365 |
% We keep the interface commands around even if we roll back in |
| 2366 |
% case they are used in packages that don't roll back. Not likely |
| 2367 |
% to do a lot of good, but then there is not much we can do, but |
| 2368 |
% this at least they won't give unknown csname errors. |
| 2369 |
% \begin{macrocode} |
| 2370 |
%<latexrelease>\DeclareRobustCommand \NewMarkClass[1]{} |
| 2371 |
%<latexrelease>\DeclareRobustCommand \InsertMark[2]{} |
| 2372 |
%<latexrelease>\RenewExpandableDocumentCommand \FirstMark { O{} m } { } |
| 2373 |
%<latexrelease>\RenewExpandableDocumentCommand \LastMark { O{} m } { } |
| 2374 |
%<latexrelease>\RenewExpandableDocumentCommand \TopMark { O{} m } { } |
| 2375 |
%<latexrelease>\RenewExpandableDocumentCommand \IfMarksEqualTF { O{} mmm }{ } |
| 2376 |
%<latexrelease> |
| 2377 |
% \end{macrocode} |
| 2378 |
% Same here, this avoided extra roll back code in the OR. |
| 2379 |
% \begin{macrocode} |
| 2380 |
%<latexrelease>\let \@expl@@@mark@update@singlecol@structures@@ \relax |
| 2381 |
%<latexrelease>\let \@expl@@@mark@update@dblcol@structures@@ \relax |
| 2382 |
%<latexrelease> |
| 2383 |
%<latexrelease> |
| 2384 |
%<latexrelease>\EndModuleRelease |
| 2385 |
% \end{macrocode} |
| 2386 |
% |
| 2387 |
% \begin{macrocode} |
| 2388 |
\ExplSyntaxOff |
| 2389 |
% \end{macrocode} |
| 2390 |
% \begin{macrocode} |
| 2391 |
%</2ekernel|latexrelease> |
| 2392 |
% \end{macrocode} |
| 2393 |
% |
| 2394 |
% Reset module prefix: |
| 2395 |
% \begin{macrocode} |
| 2396 |
%<@@=> |
| 2397 |
% \end{macrocode} |
| 2398 |
% |
| 2399 |
% |
| 2400 |
% |
| 2401 |
% |
| 2402 |
% |
| 2403 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2404 |
\endinput |
| 2405 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2406 |
% |