| 1 |
\documentclass{l3doc} |
| 2 |
\usepackage{updatemarks} |
| 3 |
\usepackage[a4paper,top=2cm,bottom=2.5cm,left=5cm,right=2cm]{geometry} |
| 4 |
|
| 5 |
\title{Update marks in box\thanks{Issues: \url{https://github.com/Sophanatprime/updatemarks/issues}}} |
| 6 |
\author{WenJian Chern\thanks{Email: [email protected]}} |
| 7 |
\date{\today\qquad v0.4a} |
| 8 |
|
| 9 |
\begin{document} |
| 10 |
|
| 11 |
\maketitle |
| 12 |
|
| 13 |
\begin{abstract} |
| 14 |
There are some cases where one may put title in box and still want its |
| 15 |
\cs{markboth} working. This brings the \pkg{updatemarks} package. |
| 16 |
The \pkg{updatemarks} package provides interface to extract marks where are in a |
| 17 |
inner box and then can put the first and last marks back to outer. |
| 18 |
It can automatically update marks where are in \env{minipage}, |
| 19 |
\textit{boxed multicols} and \env{tcolorbox} environments. |
| 20 |
\end{abstract} |
| 21 |
|
| 22 |
|
| 23 |
\tableofcontents |
| 24 |
|
| 25 |
|
| 26 |
\section{Usage of the package} |
| 27 |
|
| 28 |
You simply insert \verb|\usepackage{updatemarks}| or |
| 29 |
\verb|\usepackage|\oarg{options}\verb|{updatemarks}| in the preamble of your document. |
| 30 |
|
| 31 |
There are three package options \texttt{minipage}, |
| 32 |
\texttt{multicol}(an optional \texttt s) and |
| 33 |
\texttt{tcolorbox}, which are used to enable the function of automatical updating marks |
| 34 |
in \env{minipage}, \env{multicols} and |
| 35 |
\env{tcolorbox} (both \env{tcolorbox} environment and \tn{tcbox} command), respectively. |
| 36 |
|
| 37 |
No automatical updatings are enable, by default. |
| 38 |
|
| 39 |
If your {\LaTeX} version is 2022-06-01 or newer, you can use |
| 40 |
\cs{SetKeys}\texttt{[updatemarks]}\marg{options} to enable or disable |
| 41 |
automatical updating locally. |
| 42 |
|
| 43 |
Such as, |
| 44 |
\begin{verbatim} |
| 45 |
\SetKeys[updatemarks]{minipage=false, tcolorbox=true, multicol} |
| 46 |
\end{verbatim} |
| 47 |
so marks in \env{minipage} would not update, |
| 48 |
whereas \env{tcolorbox} and \env{multicols} do. |
| 49 |
|
| 50 |
The total empty mark will not be extracted and updated. |
| 51 |
But \verb|\markboth{}{}| and \verb|\InsertMark{}| do will be extracted and updated, |
| 52 |
because they are not total empty internally. |
| 53 |
|
| 54 |
However, the updating is not once for all. |
| 55 |
For example, if you are using \env{minipage} in \tn{makebox}, even if you enable |
| 56 |
the automatical updating, the marks still can not be found by \LaTeX. |
| 57 |
But, if you put \env{minipage} in \env{tcolorbox} or the other way round, |
| 58 |
\LaTeX\ still can get correct marks. |
| 59 |
|
| 60 |
The point is, updating marks is done inner to outer and level by level, |
| 61 |
if any level is not updated, you will lost all marks in inner boxes. |
| 62 |
Furthermore, whether marks are updated or not is only influenced by box level |
| 63 |
instead of group level, so if you try to limit marks in a certain position, you should |
| 64 |
use a box instead of \tn{begingroup} and \tn{endgroup}. |
| 65 |
|
| 66 |
The extracting and updating would not remove these marks, they still be there, you |
| 67 |
can find them by your own method as well. |
| 68 |
|
| 69 |
|
| 70 |
\section{\env{minipage}} |
| 71 |
|
| 72 |
You can enable automatically extracting and updating marks where are in \env{minipage} |
| 73 |
to its nearest outer box level, |
| 74 |
by using \texttt{minipage} package option or set \texttt{minipage} key to true. |
| 75 |
|
| 76 |
\pkg{updatemarks} patches the \tn{endminipage}, if you enable the function, |
| 77 |
marks in any other environments that use \env{minipage} will be updated, |
| 78 |
including \env{varwidth} of \pkg{varwidth} package, etc. |
| 79 |
|
| 80 |
\section{Version 2.* of \pkg{multicol}} |
| 81 |
|
| 82 |
\pkg{multicol} has fully supported the new mark mechanism of \LaTeX{} since version 2.0, |
| 83 |
so no more things are needed to be done by \pkg{updatemarks}. |
| 84 |
|
| 85 |
\section{Version 1.* of \pkg{multicol} and \pkg{adjmulticol}} |
| 86 |
|
| 87 |
If \env{multicols} or \env{adjmulticols} or their starred versions are put in a box |
| 88 |
--- so called \emph{boxed multicols}, you are able to eanble automatically extracting |
| 89 |
and updating marks into the box (not outer of the box, because they are only updated |
| 90 |
one level). |
| 91 |
If you need to update marks in this box, you have to do it manually. |
| 92 |
Of cause, if the box is \env{minipage} or \env{tcolorbox} or another \env{multicols} |
| 93 |
or any other supported environments or commands, then no more things to do. |
| 94 |
|
| 95 |
All \env{multicols} and \env{adjmulticols} and their starred versions share the |
| 96 |
same option \texttt{multicol}(an optional \texttt s). |
| 97 |
|
| 98 |
For \emph{non boxed multicols}, i.e, not in any other box except |
| 99 |
the main vertical list, the \tn{topmark} (and \tn{topmarks}) at first and last page |
| 100 |
are not correct. Multiple contiguous forced break or \tn{clearpage} may cause the |
| 101 |
wrong marks. |
| 102 |
|
| 103 |
If your {\LaTeX} version is 2022-06-01 or newer, |
| 104 |
you can get more correct mark values by using \cs{TopMark}, \cs{FirstMark} |
| 105 |
and \cs{LastMark} in head and foot, but only the |
| 106 |
\texttt{previous-page} region and \texttt{page} region are supported. |
| 107 |
Still, Multiple contiguous forced break or \tn{clearpage} may cause the wrong marks. |
| 108 |
|
| 109 |
|
| 110 |
\section{\pkg{tcolorbox}} |
| 111 |
|
| 112 |
The \pkg{updatemarks} package can also update marks in \env{tcolorbox} environments |
| 113 |
(both breakable and unbreakable) and \tn{tcbox} commands. |
| 114 |
|
| 115 |
You are allowed to use \verb|updatemarks=true| or \verb|updatemarks| in \tn{tcbset} |
| 116 |
or as environment and command option to enable the function, and |
| 117 |
\verb|updatemarks=false| to disable. |
| 118 |
|
| 119 |
|
| 120 |
\section{Set automatical updating list} |
| 121 |
|
| 122 |
\pkg{updatemarks} can automatically detect mark classes allocated by \tn{newmarks} |
| 123 |
and \cs{NewMarkClass} in preamble. But if you allocate mark class after preamble |
| 124 |
(which I strongly recommend you do not), |
| 125 |
\pkg{updatemarks} also provides interfaces to enable you add these mark class to |
| 126 |
automatical updating list. If you are not using these two commands, then nothing need |
| 127 |
to be done. |
| 128 |
|
| 129 |
|
| 130 |
\begin{function}{\AddToUpdateMarksList,\SetUpdateMarksList,\RemoveFromUpdateMarksList} |
| 131 |
\begin{syntax} |
| 132 |
\verb|\AddToUpdateMarksList| \marg{number list} |
| 133 |
\verb|\SetUpdateMarksList| \marg{number list} |
| 134 |
\verb|\RemoveFromUpdateMarksList| \marg{number list} |
| 135 |
\end{syntax} |
| 136 |
You can use these functions to globally add items to, set items, and remove items from |
| 137 |
the list of mark classes which need to be automatically updated. |
| 138 |
|
| 139 |
The \meta{number} is the first argument of \tn{newmarks}, or literally, a number. |
| 140 |
Specially, for those mark classes declared by \cs{NewMarkClass}, you are able to use |
| 141 |
\oarg{class} or \cs{MarkClass}\marg{class}. Such as |
| 142 |
\begin{verbatim} |
| 143 |
\RemoveFromUpdateMarksList { [2e-right], 4, \MarkClass{my-class} } |
| 144 |
\end{verbatim} |
| 145 |
You can also use number ranges in \meta{number list}, such as \verb|2 -> 5|. |
| 146 |
\end{function} |
| 147 |
|
| 148 |
|
| 149 |
\begin{function}{\AddAllocatedToUpdateMarksList} |
| 150 |
\begin{syntax} |
| 151 |
\verb|\AddAllocatedToUpdateMarksList| |
| 152 |
\end{syntax} |
| 153 |
The function add all mark classes allocated by \tn{newmarks} and \cs{NewMarkClass} |
| 154 |
to automatical updating list. |
| 155 |
\end{function} |
| 156 |
|
| 157 |
|
| 158 |
\section{Generic interfaces of extracting and updating} |
| 159 |
|
| 160 |
If you need to extract and update marks manually, \cs{ExtractMarks}, |
| 161 |
\cs{ExtractSplitMarks} and \cs{UpdateMarks} will help you. |
| 162 |
|
| 163 |
\begin{function}{\ExtractMarks} |
| 164 |
\begin{syntax} |
| 165 |
\verb|\ExtractMarks| \marg{box number} |
| 166 |
\verb|\ExtractMarks| \oarg{number list} \marg{box number} |
| 167 |
\verb|\ExtractMarks| * \marg{text} |
| 168 |
\verb|\ExtractMarks| * \oarg{number list} \marg{text} |
| 169 |
\end{syntax} |
| 170 |
Save first marks and last marks of specified mark classes |
| 171 |
which are directly presented in \meta{box number} or \meta{text} |
| 172 |
if these marks is not total empty. |
| 173 |
Marks in deeper boxes will not be detected, unless they are moved out. |
| 174 |
|
| 175 |
If \meta{number list} is presented, the mark classes are these numbers, otherwise |
| 176 |
they are the automatical updating list. |
| 177 |
|
| 178 |
The \meta{box number} is the first argument of \tn{newbox} or \tn{newsavebox}, etc., |
| 179 |
and have saved contents by using \env{lrbox} or \tn{sbox} or similar. |
| 180 |
|
| 181 |
The \meta{text} is typeset material and \emph{will be executed}. |
| 182 |
|
| 183 |
If the \meta{box number} is a vbox and contains forced page break, then all marks after |
| 184 |
the first forced page break will not be detected. |
| 185 |
\end{function} |
| 186 |
|
| 187 |
\begin{function}{\ExtractSplitMarks} |
| 188 |
\begin{syntax} |
| 189 |
\verb|\ExtractSplitMarks| |
| 190 |
\verb|\ExtractSplitMarks| \oarg{number list} |
| 191 |
\end{syntax} |
| 192 |
This command is used after a \tn{vsplit}, and save |
| 193 |
first marks and last marks of specified mark classes which are directly |
| 194 |
presented in being split part if these marks is not total empty. |
| 195 |
Marks in deeper boxes will not be detected, unless they are moved out. |
| 196 |
|
| 197 |
If \meta{number list} is presented, the mark classes are these numbers, otherwise |
| 198 |
they are the automatical updating list. |
| 199 |
\end{function} |
| 200 |
|
| 201 |
\begin{function}{\UpdateMarks} |
| 202 |
\begin{syntax} |
| 203 |
\verb|\UpdateMarks| |
| 204 |
\verb|\UpdateMarks| \oarg{number list} |
| 205 |
\end{syntax} |
| 206 |
Reinserting saved first marks and last marks of specified mark classes |
| 207 |
(if have been saved) into the current box, |
| 208 |
or if not in a box then the main vertical list. |
| 209 |
|
| 210 |
If \meta{number list} is presented, the mark classes are these numbers, otherwise |
| 211 |
they are the automatical updating list. |
| 212 |
|
| 213 |
\texttt{insertmark} hook would not be used as it's already been used. |
| 214 |
\end{function} |
| 215 |
|
| 216 |
\begin{function}[added=2024-02-19]{\ExtractMarksTo} |
| 217 |
\begin{syntax} |
| 218 |
\verb|\ExtractMarksTo| \marg{box number} \marg{cmd} |
| 219 |
\verb|\ExtractMarksTo| \oarg{number list} \marg{box number} \marg{cmd} |
| 220 |
\verb|\ExtractMarksTo| * \marg{text} \marg{cmd} |
| 221 |
\verb|\ExtractMarksTo| * \oarg{number list} \marg{text} \marg{cmd} |
| 222 |
\end{syntax} |
| 223 |
It collects all marks to \meta{cmd}, then you can use \meta{cmd} to reinsert these marks. |
| 224 |
|
| 225 |
\texttt{insertmark} hook would not be used as it's already been used. |
| 226 |
\end{function} |
| 227 |
|
| 228 |
\section{Disable patches or write your own patches} |
| 229 |
|
| 230 |
By default, \pkg{updatemarks} use its own patches to support \env{minipage}, |
| 231 |
\env{multicols} and \env{tcolorbox}, however, you can write your own patches and |
| 232 |
remove the patches will be done by \pkg{updatemarks}. |
| 233 |
|
| 234 |
To the patches for \env{minipage}, you can define \tn{updatemarks@minipage@patch} |
| 235 |
before \pkg{updatemarks} is loaded, then \pkg{updatemarks} will use your patches. |
| 236 |
Specially, if you set \tn{updatemarks@minipage@patch} to empty, then no patches will |
| 237 |
be done for \cs{endminipage}. |
| 238 |
|
| 239 |
The patches for \pkg{multicol}, \pkg{adjmulticol} and \pkg{tcolorbox}, |
| 240 |
are \tn{updatemarks@multicol@patch}, \tn{updatemarks@adjmulticol@patch}, |
| 241 |
\tn{updatemarks@tcolorbox@patch} and \linebreak\tn{updatemarks@multicolnewmark@patch}, |
| 242 |
\tn{updatemarks@adjmulticolnewmark@patch} for new mark mechanism, |
| 243 |
you are able set them in preamble before or after \pkg{updatemarks} is loaded. |
| 244 |
|
| 245 |
|
| 246 |
\section{Programming interfaces} |
| 247 |
|
| 248 |
This section describes the interfaces of \LaTeX3. |
| 249 |
|
| 250 |
\begin{function}[added=2024-02-19]{\updatemarks_parse_classes:Nn} |
| 251 |
\begin{syntax} |
| 252 |
\verb|\updatemarks_parse_classes:Nn| \meta{seq var} \marg{number list} |
| 253 |
\end{syntax} |
| 254 |
Parse number list and save it to \meta{seq var}. |
| 255 |
\end{function} |
| 256 |
|
| 257 |
\begin{function}{\updatemarks_extract:nN,\updatemarks_extract_split:N} |
| 258 |
\begin{syntax} |
| 259 |
\verb|\updatemarks_extract:nN| \marg{material} \meta{seq var} |
| 260 |
\verb|\updatemarks_extract_split:N| \meta{seq var} |
| 261 |
\end{syntax} |
| 262 |
Programming interface of \cs{ExtractMarks} and \cs{ExtractSplitMarks}, respectively. |
| 263 |
|
| 264 |
\meta{material} is content to build a box. |
| 265 |
Such as unpacked box using \cs{hbox_unpack:N} or \cs{vbox_unpack:N} or text. |
| 266 |
|
| 267 |
\meta{seq var} is the number sequence of mark classes which are need to be extracted. |
| 268 |
|
| 269 |
They only save the marks whose positions are first or last. |
| 270 |
\end{function} |
| 271 |
|
| 272 |
\begin{function}[added=2024-02-19]{\updatemarks_extract:nNN} |
| 273 |
\begin{syntax} |
| 274 |
\verb|\updatemarks_extract:nNN| \marg{material} \meta{seq var} \meta{tl var} |
| 275 |
\end{syntax} |
| 276 |
Programming interface of \cs{ExtractMarksTo}. |
| 277 |
|
| 278 |
\texttt{insertmark} hook would not be used as it's already been used. |
| 279 |
\end{function} |
| 280 |
|
| 281 |
\begin{function}[added=2024-02-19]{\updatemarks_extract_act:nNn} |
| 282 |
\begin{syntax} |
| 283 |
\verb|\updatemarks_extract_act:nNn| \marg{material} \meta{seq var} \marg{code} |
| 284 |
\end{syntax} |
| 285 |
Run \meta{code} for every mark classes in \meta{seq var}, the code can use one |
| 286 |
parameter, which is the current mark class, and two \texttt{tl} variable |
| 287 |
\cs{l_updatemarks_first_tl} and \cs{l_updatemarks_last_tl}, which save |
| 288 |
the first and last marks at specified mark class, respectively. If these two \texttt{tl} |
| 289 |
is not exist, then no marks at the mark class are inserted. |
| 290 |
\end{function} |
| 291 |
|
| 292 |
\begin{function}{\updatemarks_update:N} |
| 293 |
\begin{syntax} |
| 294 |
\verb|\updatemarks_update:N| \meta{seq var} |
| 295 |
\end{syntax} |
| 296 |
This function has the same function of \cs{UpdateMarks}. |
| 297 |
|
| 298 |
\meta{seq var} is the number sequence of mark classes which are need to be |
| 299 |
reinserted into the current box or the main vertical list. |
| 300 |
|
| 301 |
It only reinserts marks whose positions are first or last. |
| 302 |
|
| 303 |
\texttt{insertmark} hook would not be used as it's already been used. |
| 304 |
\end{function} |
| 305 |
|
| 306 |
\begin{function}{\updatemarks_save:Nnn} |
| 307 |
\begin{syntax} |
| 308 |
\verb|\updatemarks_save:Nnn| \meta{seq var} \marg{position} \marg{value code} |
| 309 |
\end{syntax} |
| 310 |
Saving marks at \meta{position} of specified mark classes \meta{seq var}, |
| 311 |
whose values are expanding \meta{value code} \emph{once}. |
| 312 |
|
| 313 |
If \cs{l_updatemarks_nonempty_bool} is set to \texttt{true}, then the expanded value |
| 314 |
will not be saved if it is total empty. |
| 315 |
|
| 316 |
The \meta{value code} receives each item in the \meta{seq var} |
| 317 |
as a trailing brace group, then expand the whole part of |
| 318 |
\meta{value code} and the trailing group \emph{once}. |
| 319 |
\end{function} |
| 320 |
|
| 321 |
\begin{function}{\updatemarks_save_e:Nnn} |
| 322 |
\begin{syntax} |
| 323 |
\verb|\updatemarks_save_e:Nnn| \meta{seq var} \marg{position} \marg{value code} |
| 324 |
\end{syntax} |
| 325 |
Saving marks at \meta{position} of specified mark classes \meta{seq var}, |
| 326 |
whose values are fully expanding \meta{value code}. |
| 327 |
|
| 328 |
If \cs{l_updatemarks_nonempty_bool} is set to \texttt{true}, then the expanded value |
| 329 |
will not be saved if it is total empty. |
| 330 |
|
| 331 |
The \meta{value code} receives each item in the \meta{seq var} |
| 332 |
as a trailing brace group, then \emph{fully expand} the whole part of |
| 333 |
\meta{value code} and the trailing group. |
| 334 |
\end{function} |
| 335 |
|
| 336 |
\begin{function}{\updatemarks_alias:Nnn} |
| 337 |
\begin{syntax} |
| 338 |
\verb|\updatemarks_alias:Nnn| \meta{seq var} \marg{alias position} \marg{source position} |
| 339 |
\end{syntax} |
| 340 |
Setting marks at \meta{alias position} are equal to \meta{source position} |
| 341 |
of specified mark classes \meta{seq var}. |
| 342 |
|
| 343 |
If \cs{l_updatemarks_nonempty_bool} is set to \texttt{true}, then the expanded value |
| 344 |
will not be saved if it is total empty. |
| 345 |
\end{function} |
| 346 |
|
| 347 |
\begin{function}{\updatemarks_remove:Nn} |
| 348 |
\begin{syntax} |
| 349 |
\verb|\updatemarks_remove:Nn| \meta{seq var} \marg{position} |
| 350 |
\end{syntax} |
| 351 |
Remove marks at \meta{position} of specified mark classes \meta{seq var}. |
| 352 |
\end{function} |
| 353 |
|
| 354 |
\begin{function}[EXP]{\updatemarks_value:nn} |
| 355 |
\begin{syntax} |
| 356 |
\verb|\updatemarks_value:nn| \marg{position} \marg{mark class} |
| 357 |
\end{syntax} |
| 358 |
Return the value of \meta{mark class} at \meta{position}. |
| 359 |
If it has not been saved, then return to total empty. |
| 360 |
|
| 361 |
\begin{texnote} |
| 362 |
The result is returned within the \tn{unexpanded} primitive (\cs{exp_not:n}). |
| 363 |
\end{texnote} |
| 364 |
\end{function} |
| 365 |
|
| 366 |
\begin{function}{\g_updatemarks_max_int} |
| 367 |
Readonly interger, its value is the maximum mark class number allocated. |
| 368 |
\end{function} |
| 369 |
|
| 370 |
\begin{function}{\g_updatemarks_seq} |
| 371 |
The number sequence which holds the mark classes needed to be automatical updated. |
| 372 |
\end{function} |
| 373 |
|
| 374 |
\begin{function}{\g_updatemarks_classes_seq} |
| 375 |
Readonly number sequence which holds the mark classes allocated by |
| 376 |
\cs{NewMarkClass}. If \cs{NewMarkClass} is undefined, then it's empty. |
| 377 |
\end{function} |
| 378 |
|
| 379 |
\begin{function}{\l_updatemarks_nonempty_bool} |
| 380 |
A local \texttt{bool} variable which is used to control if is going to save |
| 381 |
a total empty value. |
| 382 |
\end{function} |
| 383 |
|
| 384 |
\begin{function}{\l_updatemarks_first_tl,\l_updatemarks_last_tl} |
| 385 |
A local \texttt{tl} variable which are use to save the first and last marks. |
| 386 |
\end{function} |
| 387 |
|
| 388 |
|
| 389 |
\PrintIndex |
| 390 |
|
| 391 |
\end{document} |