| 1 |
% \iffalse |
| 2 |
%<*driver> |
| 3 |
\def\nameofplainTeX{plain} |
| 4 |
\ifx\fmtname\nameofplainTeX\else |
| 5 |
\expandafter\begingroup |
| 6 |
\fi |
| 7 |
\input docstrip % |
| 8 |
\askforoverwritefalse |
| 9 |
\preamble |
| 10 |
|
| 11 |
MIT License |
| 12 |
|
| 13 |
Copyright (c) 2021-2022 Magnus Lie Hetland |
| 14 |
|
| 15 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 16 |
of this software and associated documentation files (the "Software"), to deal |
| 17 |
in the Software without restriction, including without limitation the rights |
| 18 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 19 |
copies of the Software, and to permit persons to whom the Software is |
| 20 |
furnished to do so, subject to the following conditions: |
| 21 |
|
| 22 |
The above copyright notice and this permission notice shall be included in all |
| 23 |
copies or substantial portions of the Software. |
| 24 |
|
| 25 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 26 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 28 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 29 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 30 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 |
SOFTWARE. |
| 32 |
|
| 33 |
\endpreamble |
| 34 |
% stop docstrip adding \endinput |
| 35 |
\postamble |
| 36 |
\endpostamble |
| 37 |
\generate{\file{abspos.sty}{\from{abspos.dtx}{package}}} |
| 38 |
\ifx\fmtname\nameofplainTeX |
| 39 |
\expandafter\endbatchfile |
| 40 |
\else |
| 41 |
\expandafter\endgroup |
| 42 |
\fi |
| 43 |
%</driver> |
| 44 |
% |
| 45 |
%<*driver|package> |
| 46 |
\RequirePackage{expl3} |
| 47 |
%<driver|package> |
| 48 |
% |
| 49 |
%<*driver> |
| 50 |
\documentclass[full]{l3doc} |
| 51 |
\usepackage{graphicx} |
| 52 |
\usepackage[export]{adjustbox} |
| 53 |
\usepackage{tcolorbox} |
| 54 |
\tcbuselibrary{listings,skins} |
| 55 |
\usepackage{xcoffins} |
| 56 |
\usepackage{abspos} |
| 57 |
|
| 58 |
\lstdefinestyle{tcblatex}{language={[LaTeX]TeX}, |
| 59 |
columns=fullflexible, |
| 60 |
keepspaces=true, |
| 61 |
breaklines=true, |
| 62 |
breakatwhitespace=true, |
| 63 |
basicstyle=\ttfamily\small\color{black!80}, |
| 64 |
extendedchars=true, |
| 65 |
nolol, |
| 66 |
inputencoding=\kvtcb@listingencoding, |
| 67 |
literate={~}{\textcolor{gray}{\raisebox{-.75ex}{\textasciitilde}}}{1}, |
| 68 |
commentstyle=\color{gray}, |
| 69 |
} |
| 70 |
|
| 71 |
\DeclareTCBInputListing \Example { m } { |
| 72 |
listing only, |
| 73 |
listing file=demo#1, |
| 74 |
tile, |
| 75 |
finish={ |
| 76 |
\draw (frame.north west) + (-\marginparsep,0pt) |
| 77 |
node[line width=0pt, inner sep=0pt, anchor=north east] |
| 78 |
{\includegraphics[page=#1, frame, width=\marginparwidth]{demo}} |
| 79 |
; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
\ExplSyntaxOn |
| 84 |
\cs_set:Npn \__codedoc_macro_end_style:n #1 {} |
| 85 |
\ExplSyntaxOff |
| 86 |
|
| 87 |
\begin{document} |
| 88 |
\DocInput{\jobname.dtx} |
| 89 |
\end{document} |
| 90 |
%</driver> |
| 91 |
% |
| 92 |
%<*package> |
| 93 |
\ProvidesExplPackage {abspos} {2022-09-22} {0.1} |
| 94 |
{Absolute placement with coffins} |
| 95 |
%</package> |
| 96 |
% \fi |
| 97 |
% |
| 98 |
% \title{The \pkg{abspos} package\\ Absolute placement with coffins} |
| 99 |
% \author{Magnus Lie Hetland} |
| 100 |
% |
| 101 |
% \maketitle |
| 102 |
% |
| 103 |
% \begin{documentation} |
| 104 |
% |
| 105 |
% \noindent |
| 106 |
% The \pkg{abspos} package lets you place contents at an absolute position, |
| 107 |
% anchored at some specified part of the content, similar to how \pkg{tikz} |
| 108 |
% nodes work, though without using the two-pass strategy of \pkg{tikz}. It also |
| 109 |
% avoids messing with the order of \pkg{beamer} overlays, which is what happens |
| 110 |
% when one uses the \pkg{textpos} package with the \pkg{overlay} |
| 111 |
% option.\footnote{Another possible solution is to use the \pkg{pst-abspos} |
| 112 |
% package, which relies on \pkg{pstricks}.} The solution used is quite |
| 113 |
% straightforward, combining \emph{coffins} (using \pkg{l3coffins}) with the |
| 114 |
% placement mechanisms of \pkg{atbegshi}. |
| 115 |
% |
| 116 |
% The main command of the package is |\absput|, which is somewhat similar to the |
| 117 |
% |\put| command of the \LaTeX\@ |picture| environment. |
| 118 |
% By default, it places its contents in the middle of the page, so |
| 119 |
% |\absput{Hello}| will put the word ``Hello'' front and center. Variations |
| 120 |
% are then possible using an optional argument consisting of keys and key--value |
| 121 |
% pairs, as shown in the following. |
| 122 |
% |
| 123 |
% \Example{1} |
| 124 |
% |
| 125 |
% \noindent |
| 126 |
% Supplying a |width| creates a vertical box. If the surrounding text is set, |
| 127 |
% for example, using \cs{raggedright} (as is common in \pkg{beamer}), the |
| 128 |
% contents of the \cs{absput} command will be, too. So if you want your text |
| 129 |
% justified, you can use something like the \cs{justifying} command from |
| 130 |
% \pkg{ragged2e}. |
| 131 |
% |
| 132 |
% \Example{2} |
| 133 |
% |
| 134 |
% \noindent |
| 135 |
% The options can also be set globally (or within a group) using |
| 136 |
% \cs{absposset}. For example, if you with to scale everything you place by a |
| 137 |
% certain amount, you could do that as in the following. |
| 138 |
% |
| 139 |
% \Example{3} |
| 140 |
% |
| 141 |
% \noindent |
| 142 |
% By default, the contents are placed \emph{in front} of the current page, but |
| 143 |
% this can be modified by supplying your own ``page coffin'' (an \pkg{l3coffins} |
| 144 |
% or \pkg{xcoffins} coffin) and typesetting that with, e.g., \pkg{atbegshi}. If, |
| 145 |
% for example, you wish to place something in the background of every slide of a |
| 146 |
% \pkg{beamer} presentation, you could do that by adding the following to the |
| 147 |
% preamble.\footnote{Note that because it will end up behind even the slide |
| 148 |
% itself, you need to remove the background color, by setting |bg| to nothing, |
| 149 |
% as in the example code. If you want it behind the content, but still have a |
| 150 |
% background color, you would need to add that yourself, with a colored box or |
| 151 |
% filled \pkg{tikz} rectangle, possibly also using the \cs{absput} command.} |
| 152 |
% |
| 153 |
% ^^A Can't use tcblisting, because it uses \lstinputlisting, which doesn't |
| 154 |
% ^^A respect `gobble` |
| 155 |
% \begin{tcolorbox}[tile] |
| 156 |
% \begin{lstlisting}[gobble=2, style=tcblatex] |
| 157 |
% \setbeamercolor{background canvas}{bg=} % So the coffin isn't obscured |
| 158 |
% |
| 159 |
% \NewCoffin \MyPageCoffin |
| 160 |
% \AtBeginShipout{ |
| 161 |
% \AtBeginShipoutUpperLeft{ |
| 162 |
% \TypesetCoffin \MyPageCoffin [t,l] (0pt,0pt) |
| 163 |
% } |
| 164 |
% } |
| 165 |
% \end{lstlisting} |
| 166 |
% \end{tcolorbox} |
| 167 |
% |
| 168 |
% \noindent |
| 169 |
% Now simply add a \cs{absput} command at the beginning of the document, before |
| 170 |
% your first |frame| (after |\begin{document}|), using |pg=\MyPageCoffin| to |
| 171 |
% specify which coffin to use for rendering and positioning contents. This gives |
| 172 |
% you a coordinate system starting at the top left corner of the page. If you |
| 173 |
% wish to anchor your positioned elements elsewhere, you'll need to resize your |
| 174 |
% page coffin (see p.~\pageref{p:reset}). |
| 175 |
% |
| 176 |
% \section*{Reference} |
| 177 |
% |
| 178 |
% \begin{function}{\absposset} |
| 179 |
% \begin{syntax} |
| 180 |
% \cs{absposset} \marg{options} |
| 181 |
% \end{syntax} |
| 182 |
% Sets the options, as described under \cs{absput}, to the value they should |
| 183 |
% have within the current group (or globally, if not inside a group). |
| 184 |
% \end{function} |
| 185 |
% |
| 186 |
% \begin{function}{\absput} |
| 187 |
% \begin{syntax} |
| 188 |
% \cs{absput} \oarg{options} \marg{contents} |
| 189 |
% \end{syntax} |
| 190 |
% Places \meta{contents} at some position (possibly scaled or rotated) as |
| 191 |
% dictated by the optional \meta{options}, supplied as keys and key--value |
| 192 |
% pairs. The \emph{defaults} are used as values if only the keys are given, and |
| 193 |
% the \emph{initial values} are used if the options are not specified. The |
| 194 |
% available options are as follows. |
| 195 |
% \end{function} |
| 196 |
% \begin{itemize} |
| 197 |
% |
| 198 |
% \item |angle=|\meta{angle}: The angle to which the coffin is rotated |
| 199 |
% before being positioned. |
| 200 |
% |
| 201 |
% No default. Initial value |0|. |
| 202 |
% |
| 203 |
% \item |h=|\meta{h-anchor}: The horizontal anchor to use for positioning. |
| 204 |
% This corresponds to a \pkg{l3coffins} (or \pkg{xcoffins}) \emph{pole}. The |
| 205 |
% available anchors are |l| for left, |hc| for center and |r| for right. |
| 206 |
% These are also available as separate valueless keys, so if you supply |
| 207 |
% \cs{absput} with the key |l|, that is equivalent to using |h=l|, etc. |
| 208 |
% |
| 209 |
% There are also two-letter shortcuts defined for setting the horizontal and |
| 210 |
% vertical anchors simultaneously, with the vertical one first. For example, |
| 211 |
% |tl| is equivalent to |v=t,h=l|. In these double shortcuts, the prefixes |
| 212 |
% |h| and |v| have been stripped from the center anchors, so that bottom |
| 213 |
% center is |bc|, for example, and not |bhc|. |
| 214 |
% |
| 215 |
% No default. Initial value |hc|, which centers the coffin horizontally at |
| 216 |
% \meta{x-coord}. |
| 217 |
% |
| 218 |
% \item |pg=|\meta{page-coffin}: Supplies the coffin to use as the |
| 219 |
% page, or ``canvas,'' for placing the contents. |
| 220 |
% |
| 221 |
% No default. The initial value is an internal canvas that is rendered in |
| 222 |
% front of the current page (on shipout), and then cleared. |
| 223 |
% |
| 224 |
% \item |pg-h|=\meta{page-h-anchor}: Similar to |h|, except that it applies |
| 225 |
% to the canvas (set by |pg|). Shortcuts (like |pg-l| for |pg-h=l|) are |
| 226 |
% defined for the default anchors (|l|, |hc|, |r|). |
| 227 |
% |
| 228 |
% Double shortcuts are defined for |pg-h| and |pg-v| in a similar manner to |
| 229 |
% those defined for |h| and |v|, so that |pg-tl| is equivalent to |
| 230 |
% |pg-v=t,pg-h=l|. |
| 231 |
% |
| 232 |
% No default. Initial value |hc|. |
| 233 |
% |
| 234 |
% \item |pg-v|=\meta{page-v-anchor}: Similar to |v|, except that it applies |
| 235 |
% to the canvas (set by |pg|). Shortcuts (like |pg-t| for |pg-v=t|) are |
| 236 |
% defined for the default anchors (|t|, |vc|, |b|, |T|, |B|, |H|). |
| 237 |
% |
| 238 |
% Combined shortcuts such as |pg-tl| and |pg-br|, etc., are also defined. |
| 239 |
% See the descriptions of |h| and |pg-h| for more. |
| 240 |
% |
| 241 |
% No default. Initial value |vc|. |
| 242 |
% |
| 243 |
% \item |scale=|\meta{scale}: The factor by which the coffin is scaled. |
| 244 |
% |
| 245 |
% No default. If |scale| is not used, no scaling is performed. |
| 246 |
% |
| 247 |
% \item |v=|\meta{v-anchor}: The vertical anchor to use for positioning (see |
| 248 |
% |h|). The available anchors are |t| for top, |vc| for center, |b| for |
| 249 |
% bottom and |H| for baseline. These are also available as separate |
| 250 |
% valueless keys, so if you supply \cs{absput} with the key |t|, that is |
| 251 |
% equivalent to using |v=t|, etc. |
| 252 |
% |
| 253 |
% Note that if the |width| key is set, a vertial coffin is used, which makes |
| 254 |
% the additional anchors (or poles) |T| (baseline of the first line, or |
| 255 |
% other material at the top) and |B| (baseline for the last line, or other |
| 256 |
% material at the bottom). |
| 257 |
% |
| 258 |
% Combined shortcuts such as |tl| and |br|, etc., are also defined. See the |
| 259 |
% description of |h| for more. |
| 260 |
% |
| 261 |
% No default. Initial value |vc|, which centers the coffin vertically at |
| 262 |
% \meta{y-coord}. |
| 263 |
% |
| 264 |
% \item |width=|\meta{width}: Set the width constraining the contents, |
| 265 |
% before scaling. If this is set, the contents are set in vertical mode; |
| 266 |
% otherwise, they are set in horizontal mode. |
| 267 |
% |
| 268 |
% No default and no initial value. |
| 269 |
% |
| 270 |
% \item |x=|\meta{x-coord}: The $x$ coordinate, measured from the current |
| 271 |
% horizontal page anchor, set by |pg-h|. |
| 272 |
% |
| 273 |
% No default. Initial value |0pt|. |
| 274 |
% |
| 275 |
% \item |y=|\meta{y-coord}: The $y$ coordinate, measured from the current |
| 276 |
% vertical page anchor, set by |pg-v|. |
| 277 |
% |
| 278 |
% No default. Initial value |0pt|. |
| 279 |
% \end{itemize} |
| 280 |
% |
| 281 |
% \begin{function}{\absputcoffin} |
| 282 |
% \begin{syntax} |
| 283 |
% \cs{absputcoffin} \oarg{options} \meta{coffin} |
| 284 |
% \end{syntax} |
| 285 |
% Places \meta{coffin} at some position (possibly scaled or rotated), just like |
| 286 |
% \cs{absput}. The difference is that a coffin is provided directly, rather than |
| 287 |
% constructed by typesetting some supplied contents. This means that the |width| |
| 288 |
% key is not used, though it is permitted for consistency (and ease of reusing |
| 289 |
% option lists). |
| 290 |
% \end{function} |
| 291 |
% |
| 292 |
% \end{documentation} |
| 293 |
% |
| 294 |
% \begin{implementation} |
| 295 |
% |
| 296 |
% \section*{Implementation} |
| 297 |
% |
| 298 |
% \begin{macrocode} |
| 299 |
%<*package> |
| 300 |
%<@@=apos> |
| 301 |
% \end{macrocode} |
| 302 |
% |
| 303 |
% \noindent |
| 304 |
% First, we need to import the necessary packages. We're using \pkg{expl3} to |
| 305 |
% set up the package, so we get \pkg{l3coffins} for free (and cannot import it |
| 306 |
% directly, anyway). If \pkg{abspos} is used with \pkg{beamer}, then |
| 307 |
% \pkg{atbegshi} is already included. Elsewhere, though, it will not be, so we |
| 308 |
% require it here. |
| 309 |
% |
| 310 |
% \begin{macrocode} |
| 311 |
\RequirePackage{atbegshi} |
| 312 |
% \end{macrocode} |
| 313 |
% |
| 314 |
% \noindent |
| 315 |
% We make sure we have the variants we need of some existing commands: |
| 316 |
% |
| 317 |
% \begin{macrocode} |
| 318 |
\cs_generate_variant:Nn \tl_if_novalue:nTF { VTF } |
| 319 |
\cs_generate_variant:Nn \tl_if_novalue:nF { VF } |
| 320 |
\cs_generate_variant:Nn \coffin_gattach:NnnNnnnn { NooNoonn } |
| 321 |
% \end{macrocode} |
| 322 |
% |
| 323 |
% \begin{variable}{\g_apos_shipout_coffin} |
| 324 |
% |
| 325 |
% This variable is normally used to store the contents to be placed on the |
| 326 |
% current page. It accumulates the contents from every call to \cs{absput} until |
| 327 |
% the page is about to be typeset (shipped out), at which point |
| 328 |
% \cs{g_apos_shipout_coffin} is typeset in front. |
| 329 |
% |
| 330 |
% \begin{macrocode} |
| 331 |
\coffin_new:N \g_apos_shipout_coffin |
| 332 |
% \end{macrocode} |
| 333 |
% \end{variable} |
| 334 |
% |
| 335 |
% \begin{macro}{\apos_reset_shipout_coffin:}\label{p:reset} |
| 336 |
% Used to initialize, and later reinitialize, the shipout coffin, to simply be |
| 337 |
% an empty coffin with the width and height of the current page. |
| 338 |
% \begin{macrocode} |
| 339 |
\cs_new:Npn \apos_reset_shipout_coffin: { |
| 340 |
\hcoffin_gset:Nn \g_apos_shipout_coffin { |
| 341 |
\phantom{\rule{\paperwidth}{\paperheight}} |
| 342 |
} |
| 343 |
} |
| 344 |
% \end{macrocode} |
| 345 |
% \end{macro} |
| 346 |
% |
| 347 |
% \noindent |
| 348 |
% The following hook ensures that that \cs{g_apos_shipout_coffin} is typeset in |
| 349 |
% front of the page as it is being shipped out (anchored top left), and then |
| 350 |
% cleared, ready to accumulate contents for the next page. The \pkg{atbegshi} |
| 351 |
% command used wraps its contents in a |picture| environment, which we don't |
| 352 |
% really need, but it seems to be more trouble than it's worth to get rid of it. |
| 353 |
% |
| 354 |
% \begin{macrocode} |
| 355 |
\apos_reset_shipout_coffin: |
| 356 |
\AtBeginShipout{ |
| 357 |
\AtBeginShipoutUpperLeftForeground{ |
| 358 |
\coffin_typeset:Nnnnn \g_apos_shipout_coffin {t} {l} {0pt} {0pt} |
| 359 |
\apos_reset_shipout_coffin: |
| 360 |
} |
| 361 |
} |
| 362 |
% \end{macrocode} |
| 363 |
% |
| 364 |
% \begin{variable}{\g_apos_canvas_coffin} |
| 365 |
% |
| 366 |
% This variable is used as part of the |pg| key, and is initially set equal to |
| 367 |
% \cs{g_apos_shipout_coffin}, so that whatever is rendered to the canvas (i.e., |
| 368 |
% \cs{g_apos_canvas_coffin}) is placed on top of the page contents on shipout, |
| 369 |
% and then cleared. If a different behavior is desired, another coffin can can |
| 370 |
% be supplied instead. Rather than constructing a coffin, we just set up a token |
| 371 |
% list, which initially will be aliased to the actual coffin |
| 372 |
% \cs{g_apos_shipout_coffin} as part of the key handling. |
| 373 |
% \begin{macrocode} |
| 374 |
\tl_new:N \g_apos_canvas_coffin |
| 375 |
% \end{macrocode} |
| 376 |
% \end{variable} |
| 377 |
% \begin{macro}{\apos_reset_overlay:} |
| 378 |
% This is a utility to reset \pkg{beamer} overlay specifications at the end of |
| 379 |
% our coffin contents. The idea is that if we use, say, \cs{pause} inside |
| 380 |
% \cs{absput}, then everything after the \cs{pause} command will be paused, |
| 381 |
% including material \emph{outside} \cs{absput}. To restrict such commands to the |
| 382 |
% contents provided to \cs{absput}, we use \cs{onslide<1->} after typesetting the |
| 383 |
% contents in our coffin. This is only useful (or possible) when using |
| 384 |
% \pkg{beamer}, so otherwise, we just alias \cs{ap_reset_overlay:} to |
| 385 |
% \cs{relax}, i.e., don't do anything. |
| 386 |
% \begin{macrocode} |
| 387 |
\tl_new:N \apos_reset_overlay: |
| 388 |
\@ifclassloaded{beamer} |
| 389 |
{ \tl_gset:Nn \apos_reset_overlay: { \onslide<1-> } } |
| 390 |
{ \tl_gset_eq:NN \apos_reset_overlay: \relax } |
| 391 |
% \end{macrocode} |
| 392 |
% \end{macro} |
| 393 |
% |
| 394 |
% \noindent |
| 395 |
% We now define the various keys used to configure \cs{absput}, as described |
| 396 |
% in the reference. |
| 397 |
% |
| 398 |
% \begin{macrocode} |
| 399 |
\keys_define:nn { abspos } { |
| 400 |
|
| 401 |
angle .tl_set:N = \l_apos_angle_tl, |
| 402 |
angle .initial:V = \c_novalue_tl, |
| 403 |
angle .value_required:n = true, |
| 404 |
|
| 405 |
h .tl_set:N = \l_apos_hanchor_tl, |
| 406 |
h .initial:n = hc, |
| 407 |
h .value_required:n = true, |
| 408 |
|
| 409 |
pg .code:n = { \tl_set_eq:NN \g_apos_canvas_coffin #1 }, |
| 410 |
pg .initial:n = \g_apos_shipout_coffin, |
| 411 |
pg .value_required:n = true, |
| 412 |
|
| 413 |
pg-h .tl_set:N = \l_apos_on_hanchor_tl, |
| 414 |
pg-h .initial:n = hc, |
| 415 |
pg-h .value_required:n = true, |
| 416 |
|
| 417 |
pg-v .tl_set:N = \l_apos_on_vanchor_tl, |
| 418 |
pg-v .initial:n = vc, |
| 419 |
pg-v .value_required:n = true, |
| 420 |
|
| 421 |
scale .tl_set:N = \l_apos_scale_tl, |
| 422 |
scale .initial:V = \c_novalue_tl, |
| 423 |
scale .value_required:n = true, |
| 424 |
|
| 425 |
v .tl_set:N = \l_apos_vanchor_tl, |
| 426 |
v .initial:n = vc, |
| 427 |
v .value_required:n = true, |
| 428 |
|
| 429 |
width .tl_set:N = \l_apos_width_tl, |
| 430 |
width .initial:V = \c_novalue_tl, |
| 431 |
width .value_required:n = true, |
| 432 |
|
| 433 |
x .tl_set:N = \l_apos_x_tl, |
| 434 |
x .initial:n = { 0pt }, |
| 435 |
x .value_required:n = true, |
| 436 |
|
| 437 |
y .tl_set:N = \l_apos_y_tl, |
| 438 |
y .initial:n = { 0pt }, |
| 439 |
y .value_required:n = true, |
| 440 |
|
| 441 |
} |
| 442 |
|
| 443 |
\clist_const:Nn \@@_hanchors_clist {l,hc,r} |
| 444 |
\clist_const:Nn \@@_vanchors_clist {t,vc,b,H,T,B} |
| 445 |
|
| 446 |
\cs_new:Npn \@@_define_shortcuts:nnn #1 #2 #3 { |
| 447 |
\keys_define:nn { abspos } { |
| 448 |
|
| 449 |
#1 .meta:n = { #2 }, |
| 450 |
#1 .value_forbidden:n = true, |
| 451 |
|
| 452 |
pg-#1 .meta:n = { #3 }, |
| 453 |
pg-#1 .value_forbidden:n = true, |
| 454 |
|
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
\cs_generate_variant:Nn \@@_define_shortcuts:nnn { Vnn } |
| 459 |
|
| 460 |
\clist_map_inline:Nn \@@_hanchors_clist { |
| 461 |
|
| 462 |
\@@_define_shortcuts:nnn { #1 } { h = #1 } { pg-h = #1 } |
| 463 |
|
| 464 |
} |
| 465 |
|
| 466 |
\clist_map_inline:Nn \@@_vanchors_clist { |
| 467 |
|
| 468 |
\@@_define_shortcuts:nnn { #1 } { v = #1 } { pg-v = #1 } |
| 469 |
|
| 470 |
} |
| 471 |
|
| 472 |
\clist_map_inline:Nn \@@_vanchors_clist { |
| 473 |
\clist_map_inline:Nn \@@_hanchors_clist { |
| 474 |
|
| 475 |
\tl_clear:N \g_tmpa_tl |
| 476 |
|
| 477 |
\tl_if_eq:nnTF { #1 } { vc } |
| 478 |
{ \tl_put_right:Nn \g_tmpa_tl { c } } |
| 479 |
{ \tl_put_right:Nn \g_tmpa_tl { #1 } } |
| 480 |
|
| 481 |
\tl_if_eq:nnTF { ##1 } { hc } |
| 482 |
{ \tl_put_right:Nn \g_tmpa_tl { c } } |
| 483 |
{ \tl_put_right:Nn \g_tmpa_tl { ##1 } } |
| 484 |
|
| 485 |
\@@_define_shortcuts:Vnn |
| 486 |
\g_tmpa_tl { v = #1, h = ##1 } { pg-v = #1, pg-h = ##1 } |
| 487 |
|
| 488 |
} |
| 489 |
} |
| 490 |
% \end{macrocode} |
| 491 |
% In order to let the user set options outside the actual use of \cs{absput} and |
| 492 |
% \cs{absputcoffin}, we introduce a wrapper: |
| 493 |
% \begin{macrocode} |
| 494 |
\NewDocumentCommand \absposset { +m } { |
| 495 |
\keys_set:nn { abspos } { #1 } |
| 496 |
} |
| 497 |
% \end{macrocode} |
| 498 |
% |
| 499 |
% \begin{macro}{\absput} |
| 500 |
% This is the main command of the package. It takes a key--value list as its |
| 501 |
% first optional argument, followed by the contents that are to be placed. |
| 502 |
% \begin{macrocode} |
| 503 |
\NewDocumentCommand \absput { +O{ } +m } { |
| 504 |
\group_begin: |
| 505 |
% \end{macrocode} |
| 506 |
% First we handle the keys, updating variables holding coordinates, etc. |
| 507 |
% \begin{macrocode} |
| 508 |
\keys_set:nn { abspos } { #1 } |
| 509 |
% \end{macrocode} |
| 510 |
% Then the contents are typeset, with some additions, into a temporary coffin. |
| 511 |
% The additions are that whitespace is stripped around the contents, and that we |
| 512 |
% reset any overlay counters (in case they are modified by \cs{onslide} or |
| 513 |
% \cs{pause}, or the like). If we're not using \pkg{beamer}, this last part is a |
| 514 |
% no-op. |
| 515 |
% |
| 516 |
% If |width| has been set, the contents is set in vertical mode (using the given |
| 517 |
% width); otherwise, it is set in horizontal mode. |
| 518 |
% \begin{macrocode} |
| 519 |
\tl_set:Nn \l_tmpa_tl { |
| 520 |
\ignorespaces #2 \unskip |
| 521 |
\apos_reset_overlay: |
| 522 |
} |
| 523 |
\tl_if_novalue:VTF \l_apos_width_tl { |
| 524 |
\hcoffin_set:Nn \l_tmpa_coffin \l_tmpa_tl |
| 525 |
} { |
| 526 |
\vcoffin_set:Nnn \l_tmpa_coffin \l_apos_width_tl \l_tmpa_tl |
| 527 |
} |
| 528 |
% \end{macrocode} |
| 529 |
% Finally, actually place the typeset coffin on the canvas coffin. |
| 530 |
% \begin{macrocode} |
| 531 |
\@@_absput_coffin:N \l_tmpa_coffin |
| 532 |
\group_end: |
| 533 |
} |
| 534 |
% \end{macrocode} |
| 535 |
% \end{macro} |
| 536 |
% |
| 537 |
% \begin{macro}{\absputcoffin} |
| 538 |
% A thin wrapper around the internal \cs{@@_absput_coffin:N}. The only extra |
| 539 |
% work done here is setting the keys. |
| 540 |
% \begin{macrocode} |
| 541 |
\NewDocumentCommand \absputcoffin { +O{ } m } { |
| 542 |
\group_begin: |
| 543 |
\keys_set:nn { abspos } { #1 } |
| 544 |
\@@_absput_coffin:N #2 |
| 545 |
\group_end: |
| 546 |
} |
| 547 |
% \end{macrocode} |
| 548 |
% \end{macro} |
| 549 |
% |
| 550 |
% \begin{macro}{\@@_absput_coffin:N} |
| 551 |
% An internal macro for placing a given coffin, using the options currently in |
| 552 |
% effect (i.e., as configured by \cs{keys_set:nn} in some outer group). Used by |
| 553 |
% \cs{absput} and \cs{absputcoffin}. |
| 554 |
% \begin{macrocode} |
| 555 |
\cs_new:Npn \@@_absput_coffin:N #1 { |
| 556 |
% \end{macrocode} |
| 557 |
% If a scale has been provided, we scale the temporary coffin (with the same |
| 558 |
% factor in both directions). |
| 559 |
% \begin{macrocode} |
| 560 |
\tl_if_novalue:VF \l_apos_scale_tl { |
| 561 |
\coffin_scale:Nnn #1 \l_apos_scale_tl \l_apos_scale_tl |
| 562 |
} |
| 563 |
% \end{macrocode} |
| 564 |
% If an angle has been provided, we rotate the temporary coffin. |
| 565 |
% \begin{macrocode} |
| 566 |
\tl_if_novalue:VF \l_apos_angle_tl { |
| 567 |
\coffin_rotate:Nn #1 \l_apos_angle_tl |
| 568 |
} |
| 569 |
% \end{macrocode} |
| 570 |
% We now join the temporary coffin to our canvas coffin, so it will be rendered |
| 571 |
% at the correct position at shipout. |
| 572 |
% \begin{macrocode} |
| 573 |
\coffin_gattach:NooNoonn |
| 574 |
\g_apos_canvas_coffin |
| 575 |
{\l_apos_on_hanchor_tl} {\l_apos_on_vanchor_tl} |
| 576 |
#1 |
| 577 |
{\l_apos_hanchor_tl} {\l_apos_vanchor_tl} |
| 578 |
{\l_apos_x_tl} {\l_apos_y_tl} |
| 579 |
% \end{macrocode} |
| 580 |
% |
| 581 |
% \noindent |
| 582 |
% Ideally, what we just did should have been enough. However, until |
| 583 |
% October~2021, the \cs{coffin_gattach:} command was not actually |
| 584 |
% global,\footnote{\url{https://tex.stackexchange.com/questions/618198}} so |
| 585 |
% to have our modification take effect outside the current group also for older |
| 586 |
% versions of \pkg{l3coffins}, we perform a final (normally redundant) global |
| 587 |
% self-assignment before ending the \cs{absput} command. |
| 588 |
% |
| 589 |
% \begin{macrocode} |
| 590 |
\coffin_gset_eq:NN \g_apos_canvas_coffin \g_apos_canvas_coffin |
| 591 |
} |
| 592 |
% \end{macrocode} |
| 593 |
% \end{macro} |
| 594 |
% \begin{macrocode} |
| 595 |
%</package> |
| 596 |
% \end{macrocode} |
| 597 |
% |
| 598 |
% \end{implementation} |