Debian Codegraph @

texmf-dist/source/latex/cardgame/cardgame.dtx

raw
1 % \iffalse meta-comment
2 %<*internal>
3 \iffalse
4 %</internal>
5 %<*readme>
6 cardgame -- Typeset custom playing cards for printing
7 ===================================================
8
9 The `cardgame` package allows you to define `cards`, which
10 have various attributes like image, text, and a bunch of
11 layout features. You can then include those cards as
12 images or, more importantly, generate a document containing
13 all of the cards you defined laid out optimally for printing
14 and cutting. You can optionally create card lists for
15 your game's manual, and you can create multiple copies
16 of cards and automatically print the correct number
17 of back sides.
18
19 Installation
20 ------------
21
22 The package is supplied in `.dtx` format and as a pre-extracted
23 `.zip` file, `cardgame.zip`. The latter is most convenient
24 for most users: simply unzip this in your local `texmf`
25 directory. If you want to unpack the `.dtx` yourself, running
26 `tex cardgame.dtx` will extract the package whereas `latex
27 cardgame.dtx` or `pdflatex cardgame.dtx` will extract it
28 and also typeset the documentation.
29
30 The package requires LaTeX3 support as provided in the
31 `l3kernel` and `l3packages` bundles. Both of these are available
32 on [CTAN](http://www.ctan.org/) as ready-to-install `.zip`
33 files. Suitable versions are available in MiKTeX 2.9 and TeX
34 Live 2012 (updating the relevant packages online may be
35 necessary). LaTeX3, and so `cardgame`, requires the e-TeX
36 extensions: these are available on all modern TeX systems.
37
38 Typesetting the documentation requires a number of packages in
39 addition to those needed to use the package. To compile the
40 documentation without error, you will need the following packages:
41 - `listings`
42 - `float`
43 %</readme>
44 %<*internal>
45 \fi
46 \def\nameofplainTeX{plain}
47 \ifx\fmtname\nameofplainTeX\else
48 \expandafter\begingroup
49 \fi
50 %</internal>
51 %<*install>
52 \input l3docstrip.tex
53 \keepsilent
54 \askforoverwritefalse
55 \preamble
56 ---------------------------------------------------------------
57 cardgame --- Typeset custom board game cards
58 Maintained by Adrian Rettich
59 E-mail: [email protected]
60 Released under the LaTeX Project Public License v1.3c or later
61 See http://www.latex-project.org/lppl.txt
62 ---------------------------------------------------------------
63
64 \endpreamble
65 \postamble
66
67 Copyright (C) 2026 by
68 Adrian Rettich <[email protected]>
69
70 It may be distributed and/or modified under the conditions of
71 the LaTeX Project Public License (LPPL), either version 1.3c of
72 this license or (at your option) any later version. The latest
73 version of this license is in the file:
74
75 http://www.latex-project.org/lppl.txt
76
77 This work is "maintained" (as per LPPL maintenance status) by
78 Adrian Rettich.
79
80 This work consists of the file cardgame.dtx
81 and the derived files cardgame.ins,
82 cardgame.pdf and
83 cardgame.sty.
84
85 \endpostamble
86
87 \usedir{tex/latex/cardgame}
88 \generate{
89 \file{\jobname.sty}{\from{\jobname.dtx}{package}}
90 }
91 %</install>
92 %<install> \endbatchfile
93 %<*internal>
94 \usedir{source/latex/cardgame}
95 \generate{
96 \file{\jobname.ins}{\from{\jobname.dtx}{install}}
97 }
98 \nopreamble\nopostamble
99 \usedir{doc/latex/cardgame}
100 \generate{
101 \file{README.txt}{\from{\jobname.dtx}{readme}}
102 }
103 \ifx\fmtname\nameofplainTeX
104 \expandafter\endbatchfile
105 \else
106 \expandafter\endgroup
107 \fi
108 %</internal>
109 %<*driver|package>
110 \RequirePackage{xparse}
111 %</driver|package>
112 %<*driver>
113 \documentclass[full]{l3doc}
114 \usepackage[playtest]{cardgame}
115 \usepackage[final]{listings}
116 \usepackage{float}
117 \begin{document}
118 \DocInput{\jobname.dtx}
119 \end{document}
120 %</driver>
121 % \fi
122 %
123 % \makeatletter
124 %
125 % ^^A For creating examples with nice highlighting of code, and so
126 % ^^A on; based on the system used in the listings source (lstsample).
127 % \lst@RequireAspects{writefile}
128 % \newsavebox{\LaTeXdemo@box}
129 % \lstnewenvironment{LaTeXdemo}[1][code and example]{^^A
130 % \global\let\lst@intname\@empty
131 % \expandafter\let\expandafter\LaTeXdemo@end
132 % \csname LaTeXdemo@#1@end\endcsname
133 % \@nameuse{LaTeXdemo@#1}^^A
134 % }{^^A
135 % \LaTeXdemo@end
136 % }
137 % \newcommand*\LaTeXdemo@new[3]{^^A
138 % \expandafter\newcommand\expandafter*\expandafter
139 % {\csname LaTeXdemo@#1\endcsname}{#2}^^A
140 % \expandafter\newcommand\expandafter*\expandafter
141 % {\csname LaTeXdemo@#1@end\endcsname}{#3}^^A
142 % }
143 % \newcommand*\LaTeXdemo@common{^^A
144 % \setkeys{lst}{
145 % basicstyle = \small\ttfamily,
146 % basewidth = 0.51em,
147 % gobble = 4,
148 % keywordstyle = \color{blue},
149 % language = [LaTeX]{TeX},
150 % moretexcs = {
151 % bibnote ,
152 % bibnotemark ,
153 % bibnotesetup ,
154 % bibnotetext ,
155 % printbibnotes
156 % }
157 % }^^A
158 % }
159 % \newcommand*\LaTeXdemo@input{^^A
160 % \MakePercentComment
161 % \catcode`\^^M=10\relax
162 % \small
163 % \begingroup
164 % \setkeys{lst}{
165 % SelectCharTable=\lst@ReplaceInput{\^\^I}{\lst@ProcessTabulator}
166 % }^^A
167 % \leavevmode
168 % \input{\jobname.tmp}^^A
169 % \endgroup
170 % \MakePercentIgnore
171 % }
172 % \LaTeXdemo@new{code and example}{^^A
173 % \setbox\LaTeXdemo@box=\hbox\bgroup
174 % \lst@BeginAlsoWriteFile{\jobname.tmp}^^A
175 % \LaTeXdemo@common
176 % }{^^A
177 % \lst@EndWriteFile
178 % \egroup
179 % \begin{center}
180 % \ifdim\wd\LaTeXdemo@box>0.48\linewidth\relax
181 % \hbox to\linewidth{\box\LaTeXdemo@box\hss}^^A
182 % \begin{minipage}{\linewidth}
183 % \LaTeXdemo@input
184 % \end{minipage}
185 % \else
186 % \begin{minipage}{0.48\linewidth}
187 % \LaTeXdemo@input
188 % \end{minipage}
189 % \hfill
190 % \begin{minipage}{0.48\linewidth}
191 % \hbox to\linewidth{\box\LaTeXdemo@box\hss}^^A
192 % \end{minipage}
193 % \fi
194 % \end{center}
195 % }
196 % \LaTeXdemo@new{code only}{^^A
197 % \LaTeXdemo@common
198 % }{^^A
199 % }
200 %
201 % \providecommand*\opt[1]{\texttt{#1}}
202 %
203 % \makeatother
204 % \GetFileInfo{\jobname.sty}
205 %
206 % \changes{v1.0}{2026/04/19}{Initial release}
207
208 % \title{^^A
209 % \pkg{cardgame} --- Typeset custom game cards^^A
210 % \thanks{^^A
211 % This file describes version \fileversion, last revised
212 % \filedate.^^A
213 % }^^A
214 % }
215 % \author{^^A
216 % Adrian Rettich\thanks{E-mail: [email protected]}^^A
217 % }
218 % \date{Released \filedate}
219 %
220 % \maketitle
221 %
222 % \begin{abstract}
223 % The \pkg{cardgame} package allows you to define `cards', which
224 % have various attributes like image, text, and a bunch of
225 % layout features. You can then include those cards as
226 % images or, more importantly, generate a document containing
227 % all of the cards you defined laid out optimally for printing
228 % and cutting. You can optionally create card lists for
229 % your game's manual, and you can create multiple copies
230 % of cards and automatically print the correct number
231 % of back sides.
232 % \end{abstract}
233 %
234 % \tableofcontents
235 %
236 % \begin{documentation}
237 %
238 % \section{Introduction}
239 %
240 % The main use of this package is as follows:
241 % You have created a board or card game. You want to play it.
242 % You do not want to use handwritten cards anymore.
243 % Using the \pkg{cardgame} package, you can input your cards
244 % in a reasonably intuitive way and let \LaTeX{} handle the
245 % layout for you. The package produces a PDF file that contains
246 % all of your cards, ready to be cut out. The size is such that
247 % the cards fit into standard gaming sleeves; the easiest way to
248 % use them without printing on expensive card stock is to
249 % put cheap Magic: the Gathering cards or any other pre-existing
250 % cards into sleeves, then slide your own cards on top of them.
251 % You may use sleeves with transparent back in order to have your
252 % own card back design; in this case the generated PDF file
253 % contains the correct amount of card backs for you to cut out.
254
255 % \section{Installation}
256 %
257 % The package is supplied in \file{dtx} format and as a pre-extracted
258 % zip file, \file{\jobname.zip}. The latter is most convenient for
259 % most users: simply unzip this in your local texmf directory and
260 % run \texttt{texhash} to update the database of file locations. If
261 % you want to unpack the \file{dtx} yourself, running
262 % \texttt{tex \jobname.dtx} will extract the package whereas
263 % \texttt{latex \jobname.dtx} or \texttt{pdflatex \jobname.dtx}
264 % will extract it and also typeset the documentation.
265 %
266 % The package requires \LaTeX3 support as provided in the
267 % \pkg{l3kernel} and \pkg{l3packages} bundles. Both of these are available
268 % on \href{http://www.ctan.org}{\textsc{ctan}} as ready-to-install
269 % zip files. Suitable versions are available in MiKTeX 2.9 and
270 % TeX Live 2011 (updating the relevant packages online may be
271 % necessary). \LaTeX3, and so \pkg{cardgame}, requires the e-\TeX{}
272 % extensions: these are available on all modern \TeX{} systems.
273 %
274 % Typesetting the documentation requires a number of packages in
275 % addition to those needed to use the package. To
276 % compile the documentation without error, you will need the following packages:
277 % \begin{itemize}
278 % \item \pkg{listings}
279 % \item \pkg{float}
280 % \end{itemize}
281 %
282 % \section{Quick Start}
283 %
284 % If you just want to get to making basic cards and do not need
285 % any advanced features, this section provides basic code you
286 % can copy and paste into your own document.
287 % \begin{LaTeXdemo}[code only]
288 % \usepackage[<options>]{cardgame}
289 % \end{LaTeXdemo}
290 % You can generate a simple playing card as follows.
291 % For the artwork, a PNG with transparency is recommended, but you can
292 % of course use any image file.
293 % Our examples use the excellent CTAN lion drawn by Duane Bibby.
294 % A card has two mandatory arguments: a name and a text.
295 % All other options are specified as key-value pairs in the optional argument.
296 % \begin{LaTeXdemo}
297 % \Card[
298 % art=lion.png,
299 % south east content=5,
300 % tags=animal
301 % ] {Lion} {
302 % You get a billion points. The card costs 5 of some game resource
303 % and is of type `animal'.\\
304 % Line breaks are supported, but a blank line such as this\\\ \\
305 % must contain an explicit space.
306 % }
307 % \begin{figure}[H]
308 % \ShowCard
309 % \end{figure}
310 % \end{LaTeXdemo}
311 % Line breaks are supported via explicit backslashes. Do not attempt to have a blank line inside your text argument; it will break because everything on a card is happening inside a TikZ picture. Always use the backslashes.
312 %
313 % You can customise many of the features of a card; they are documented in the later sections of this manual.
314 % Here is another card showcasing some of these features.
315 % Note how you can pass name and text as options if you leave the mandatory arguments empty.
316 % \begin{LaTeXdemo}
317 % \Card[
318 % name=Landscape Lion,
319 % art=lion.png,
320 % text={
321 % This card is in landscape mode.\\
322 % Note how the tags are sorted automatically to have
323 % the same order on all of your cards.},
324 % orientation=landscape,
325 % north east content=5,
326 % north east pre=cost:,
327 % tags={predator,animal},
328 % background colour=Lavender!20,
329 % title colour=BlueViolet!50,
330 % title gradient=BrickRed,
331 % tags colour=BlueViolet!50,
332 % tags gradient=DarkOrchid!50,
333 % frame colour=Blue,
334 % border colour=darkgray
335 % ]{}{}
336 % \begin{figure}[H]
337 % \rotatebox{270}{
338 % \ShowCard
339 % }
340 % \end{figure}
341 % \end{LaTeXdemo}
342 % The keys \opt{background color} and so forth are provided as an alternative to the default spelling.
343 %
344 % Note how both cards are \emph{defined} before they are ever put inside a figure; the command \cs{ShowCard} is a convenience function that immediately typesets the most recently defined card.
345 % Mostly, if you are designing a game, you just want to print all the cards on as few sheets of cardstock as possible.
346 % To this end, you do not use the \cs{ShowCard} macro.
347 % Rather, first define all of your cards.
348 % If you want to have more than one copy of a card, simply include \opt{copies=N} for the desired number \opt{N} in the \cs{Card} call.
349 %
350 % Once you have defined all of your cards, call \cs{PrintCards} to generate a list of \emph{all} cards you have created.
351 % Note that you must compile your document twice for this to work.
352 %
353 % You can easily keep your cards sorted in different files by simply having files filled with \cs{Card} commands and using \cs{input} to pull them into one PDF file.
354 %
355 % By default, cards are sorted by type, subtype, and then title, and one back side is created for each card.
356 % You can suppress sorting by passing \opt{sort=false} to \cs{Cardlist} as an optional argument, and you can suppress creation of back sides by passing \opt{backs=false}.
357 %
358 % You can avoid copying options that should be the same for each card by using the \cs{DeclareCardType} macro.
359 % \begin{LaTeXdemo}[code only]
360 % \DeclareCardType{GreenCard}{
361 % title colour=green
362 % }
363 % \end{LaTeXdemo}
364 % This provides you with a new command \cs{GreenCard}, which acts exactly like \cs{Card} except that it has a green title box by default.
365 % If \cs{DeclareCardType} receives the name of an existing card type as an optional argument, it inherits all options from that card type.
366 % Each option can still be overwritten in individual calls.
367 %
368 % If you want to include some of your cards in your game manual, give them a \opt{uid}.
369 % \begin{LaTeXdemo}
370 % \Card[
371 % art=lion.png,
372 % south east content=5,
373 % tags=animal,
374 % uid=truelion
375 % ]{Lion}{
376 % You get a billion points.
377 % }
378 % \Card[
379 % art=lion.png,
380 % ]{Tiger}{
381 % You lose all your points.
382 % }
383 % \end{LaTeXdemo}
384 % Now, even though the last card we defined is ``tiger'', we can get our lion back by passing its \opt{uid} to the \cs{ShowCard} command.
385 % \begin{LaTeXdemo}
386 % \begin{figure}[H]
387 % \ShowCard[truelion]
388 % \end{figure}
389 % \end{LaTeXdemo}
390 % \opt{uid} stands for ``unique identifier'', and as such, the package will throw an error if you try to create a second card with the same \opt{uid}, whereas multiple cards with the same \opt{name} are allowed.
391 %
392 % This concludes the introductory part of this documentation.
393 % Read on if you want to know about the full set of features.
394 %
395 % \section{The Parts of a Card}
396 %
397 % In order to communicate information about typesetting of game cards, it is helpful to establish some shared terminology.
398 %
399 % All cards generated by \pkg{cardgame} have the following layout.
400 % \Card[
401 % north west content=1,
402 % north east content=2,
403 % south west content=3,
404 % south east content=4,
405 % art=lion.png,
406 % separator=true,
407 % tags={tag list},
408 % version=1.0,
409 % type=type,
410 % subtype=subtype,
411 % more text=More text
412 % ]{Name}{This is the main text.}
413 % \begin{figure}[H]
414 % \ShowCard
415 % \end{figure}
416 % The parts of this card are as follows.
417 % \begin{description}
418 % \item[Border] The black outline of the card, showing you where to cut. It should probably not carry information.
419 % \item[Title Box] The coloured box at the top, containing the numbers 1 and 2 and the word ``name''.
420 % \item[Tag Box] The bottom box, containing the numbers 3 and 4 and the words ``tag list''.
421 % \item[Frame] The vertical orange bars on the left and right. Do not confuse the frame with the border; the frame's colour usually changes with the card colour, while the border is always black.
422 % \item[Main Area] The central area containing the artwork and main text. In this card, it is split in half by a horizontal divider, called the card's separator. In landscape mode, the split is vertical instead.
423 % \item[Artwork] The area above the divider line, usually occupied by a picture.
424 % \item[Text] The area below the divider line.
425 % \item[Name] The card's name is displayed in the centre of the title box.
426 % \item[Tags] A card can have any number of ``tags'' passed as a comma-separated list. How you use them is up to you; they could for example be subtypes. The list is sorted alphabetically and by default is displayed in the tag box, though you can change this.
427 % \item[Corners] The card has four corners. Each of the corners can display content. They are called north west (1), north east (2), south west (3), and south east (4).
428 % \item[Playtesting Information] If you look carefully, you can see the string ``type -- subtype -- v1.0'' displayed in the eastern frame. This optional information tells you the type (and subtype) of card and its newest revision, useful when you are playtesting a game and updating cards as you go. The version information lets you check quickly whether the printed version is currently up to date.
429 % This text does not appear by default; set the \opt{playtest} package option to enable it.
430 % \end{description}
431 % Apart from those visible elements, each card has additional attributes that may or may not be visible.
432 % They are explained in detail later, but the most important are the following ones.
433 % \begin{description}
434 % \item[Type] Each card has a ``type''. This could affect which of various piles in a game the card is a part of. It is not usually displayed on the card itself since it is easier to distinguish cards by colours or symbols. When generating a list of cards, they are sorted by type first.
435 % \item[Subtype] Cards can also have a subtype. If you want cards with multiple subtypes, then use the tag list instead. An option lets you control whether to display the subtype in the tag box.
436 % \item[Cost] Cards can carry costs. These can, but need not, be numbers, and they can be displayed in one or more corners of the card.
437 % \item[Level] Cards can have a level. This is a non-negative integer and can be displayed in one or more corners.
438 % \item[Mark] This can contain any text you like. It can be displayed in one or more corners.
439 % \item[Secondary Mark] Same principle as mark.
440 % \end{description}
441 % Everything we just talked about makes up the \emph{front side} or \emph{face} of the card. A card also has a \emph{back}, which has the same parts, except that there is no main text and the artwork is centred on the card.
442 % \section{Defining Cards}
443 % \subsection{Options}
444 % All card-making macros accept all options listed in this section.
445 % Options are given as a comma-separated list of key-value pairs in the form \opt{<key>=<value>} or \opt{<key>=\{<value>\}}.
446 % Enclosing the value in curly braces is necessary if it contains a comma or an equals sign.
447 %
448 % For options that define boolean values (those that take either \opt{true} or \opt{false} as their value), the equals sign and value can be omitted. Passing \opt{<someboolean>} is the same as passing \opt{<someboolean>=true}.
449 % \subsubsection{Options Defining Card Text}
450 % \DescribeOption{name}
451 % The title of the card. If this is too long, it may be hard to fit into the title box. See \opt{modify name} and \opt{title box content} for when that happens.
452 % The name can also be passed as the first mandatory argument of the \cs{Card} macro.
453 %
454 % \DescribeOption{type}
455 % The ``type'' of card. In reality, this can be any text. It is the primary key for sorting cards. You might want to display this on the back of the card.
456 %
457 % \DescribeOption{subtype}
458 % The secondary key when sorting. Again, this can be any text. If your game is very complex, you might still want this on the back of the card in order to sort your various draw piles.
459 %
460 % \DescribeOption{text}
461 % The main text of the card. Can also be passed as the second mandatory argument of the \cs{Card} macro.
462 % Text is wrapped automatically. If you want to force a line break, use \texttt{\textbackslash\textbackslash}. Blank lines in the input are not allowed. If you want to force a blank line in your text, either use the \opt{more text} option below or put a single explicit space on the blank line with a construction like \mbox{\texttt{\textbackslash\textbackslash\textbackslash\ \textbackslash\textbackslash}}.
463 %
464 % \DescribeOption{more text}
465 % Text passed to this option is typeset in the main text area, but at the bottom. The effect is as if you had a \cs{vfill} between \opt{text} and \opt{more text}.
466 % Of course, it is your responsibility to ensure that both texts fit on the card; if they are too long, \pkg{cardgame} will print them overlapping.
467 %
468 % \DescribeOption{art}
469 % This option takes the name of a file that \LaTeX{} can import as a graphic.
470 % A PNG file with transparency works well if you want to still see the background colour of the card.
471 % Otherwise, your image should bring its own frame \emph{or} you will have to make sure that it has exactly the right dimensions in order to not look strange.
472 %
473 % In portrait format, images are scaled (keeping the aspect ratio) to a maximum size of 56mm times 31mm.
474 % In landscape format, the maximum size is 40mm times 38mm.
475 %
476 % \DescribeOption{back art}
477 % This option takes the name of a file that \LaTeX{} can import as a graphic.
478 % It is set centred on the back of the card.
479 % It is scaled just like the face art.
480 %
481 % \DescribeOption{level}
482 % This option takes a non-negative integer, which can be displayed in various places.
483 % If it exists, then it becomes the secondary key in sorting cards and the \opt{subtype} is demoted to tertiary key.
484 %
485 % \DescribeOption{cost}
486 % This option is meant to define what game resources a card costs. It can be an integer, but it can also be arbitrary text. It can be displayed in various places.
487 %
488 % \DescribeOption{mark}
489 % This option takes arbitrary text and sets the \opt{mark} attribute of the card. It has no inherent meaning, but it can be displayed in various places.
490 %
491 % \DescribeOption{secondary mark}
492 % This option takes arbitrary text and sets the \opt{secondary mark} attribute of the card. It has no inherent meaning, but it can be displayed in various places.
493 %
494 % \DescribeOption{tags}
495 % This option takes a comma-separated list of tags, all of which are added to the card. By default, tags are sorted alphabetically and displayed in the tag box.
496 %
497 % When specifying more than one tag, remember to enclose your list in curly braces.
498 % If you really want to, you can specify tags that include commas by nesting braces; for example, \opt{tags=\{c,\{b,a\}\}} would be sorted as \texttt{b,a,c} because \texttt{b,a} is a single tag.
499 % \subsubsection{Options Modifying the Display of Text}
500 % \DescribeOption{modify name}
501 % Content of this field is executed right before the name of the card is typeset on the card. This allows you to, for example, change the font size for very long names without modifying the name itself, so it is still read correctly by macros like \cs{ListCards}.
502 % By default, the card name uses \cs{Large}\cs{bf}. Use \opt{modify name=} (an empty value) to produce a non-bold normalsize card title.
503 %
504 % \emph{Nota bene}, because this argument is passed to \texttt{TiKZ}, you must use the deprecated series of commands \cs{bf}, \cs{it}, and so forth to change the font face. The modern macros \cs{textbf}, \cs{textit}, and so forth will lead to errors.\footnote{If someone knows how to do this better, feel free to submit a pull request or just send your solution to \texttt{[email protected]}. Maybe using \texttt{TikZ}'s \opt{font} feature is not the correct approach in the first place?}
505 %
506 % \DescribeOption{modify text}
507 % The same as \opt{modify name}, except it modifies the main text of the card and is empty by default.
508 %
509 % \DescribeOption{modify more text}
510 % The same as \opt{modify text}, but for the \opt{more text} field at the bottom of the text box.
511 %
512 % \DescribeOption{modify <corner>}
513 % \DescribeOption{modify <corner> pre}
514 % \DescribeOption{modify <corner> post}
515 % In each of these options, \opt{<corner>} is a corner specification as described in section \ref{sec:corners}.
516 % The options modify the main text respectively the \opt{pre} or \opt{post} text of that corner just as \opt{modify text} modifies the main text.
517 % The default value of \opt{modify <corner>} is empty, while the other two use \cs{tiny} by default.
518 % \subsubsection{Options Controlling the Placement of Text}\label{sec:corners}
519 % The options in this section might be difficult to understand without pictures, so there is an example using most of them at the end of the section.
520 %
521 % Apart from the main parts of the card (name, text, and more text) there are six places available for displaying information.
522 % These are the centre of the title box, the centre of the tag box, and the four corners. Corners are specified by compass directions: the four corners are \opt{north west}, \opt{north east}, \opt{south west}, and \opt{south east}. Every occurrence of the string \opt{<corner>} in this section can be replaced by any of those four specifications.
523 % In landscape format, the cardinal directions are oriented such that the card name is north, not such that the top of the page is north.
524 %
525 % In each of these places, you can of course put some text manually. However, you also have the option to link certain information about the card to them, as follows.
526 %
527 % \DescribeOption{title box}\DescribeOption{tag box}\DescribeOption{<corner>}
528 % Set these options to link card attributes to the specified location. Possible values are \opt{name}, \opt{type}, \opt{subtype}, \opt{tags}, \opt{level}, \opt{cost}, \opt{mark}, and \opt{secondmark}. For example, the option \opt{north west=mark} means that the value of the \opt{mark} option is set in the upper right corner. This is useful when you define your own card types (see section \ref{sec:cardtypes}). You can set any of these options to be empty in order to not display anything in that position.
529 %
530 % The default value of \opt{title box} is \opt{name}.
531 % The default value of \opt{tag box} is \opt{tags}.
532 % The corners are empty by default.
533 %
534 % Even if a link is specified, you can override it on a case by case basis by setting the appropriate \opt{content} option, described next.
535 %
536 % \DescribeOption{back title box}\DescribeOption{back tag box}\DescribeOption{back <corner>}
537 % These options work just like those just described, but place text on the back of the card.
538 % By default, the \opt{back title box} contains the \opt{type} of the card, while the others are empty.
539 %
540 % \DescribeOption{title box content}
541 % \DescribeOption{tag box content}
542 % \DescribeOption{<corner> content}
543 % These options override the automatic content of the specified location. If you want to put something in the corner of just one card, it is easier to specify this.
544 %
545 % You can also use this to shorten the display name of a card while retaining its full name for card lists.
546 %
547 % \DescribeOption{<corner> pre}
548 % The value of this option is set before the content of the corner, on a separate line. It has a smaller font size by default, but this can be overridden via the \opt{modify <corner> pre} option.
549 %
550 % \DescribeOption{<corner> post}
551 % Same as the previous option, but set after the corner content.
552 %
553 % Here is an example using the options just described.
554 % Note how the \opt{mark} is used to place the same content in multiple places without duplicating it in the code.
555 % \begin{LaTeXdemo}
556 % \Card[
557 % type=animal,
558 % mark=M,
559 % tag box=type,
560 % north west=mark,
561 % north east=mark,
562 % modify north east=\Huge,
563 % north west pre=mark:,
564 % south west content=SW,
565 % south west post=post,
566 % south east=mark,
567 % modify south west post=\it\scriptsize,
568 % ] {Text Placement} {}
569 % \begin{figure}[H]
570 % \ShowCard
571 % \end{figure}
572 % \end{LaTeXdemo}
573 % \subsubsection{Colours}
574 % \pkg{cardgame} depends on the \pkg{xcolor} package and automatically loads it with the \opt{dvipsnames} option.
575 %
576 % For every option containing the word \opt{colour}, a US English equivalent (\opt{color}) is available.
577 %
578 % \DescribeOption{link colours}
579 % Set this Boolean option to \opt{true} in order to link the colours on the back of the card to the colours on the face. By default, they are controlled separately.
580 % If this is \opt{true}, then setting any of the subsequent options from this section for the face of the card automatically sets the same option for the back. However, each option can still be overridden by explicitly setting it for the back side.
581 %
582 % All other options described in this section take as their value a colour name.
583 % This name must be fit to go into a \cs{colorlet} macro (see the \pkg{xcolor} documentation for details). As such, \opt{black}, \opt{ForestGreen}, and \opt{Dandelion!50} are valid, but if you want to define your own colour by RGB values, you must use \pkg{xcolor}'s \cs{definecolor} first.
584 %
585 % Some parts of the card allow gradients. If you specify both a colour and a gradient for a part of the card, then that part will be coloured with a gradient such that the \opt{colour} option is further inside and the \opt{gradient} option is closer to the border of the card. There is an example card at the end of this section.
586 %
587 % \DescribeOption{background colour}
588 % \DescribeOption{back background colour}
589 % This is the background of the main area of the card. Choose a light colour to ensure your text is legible. The default for this is \opt{Dandelion!20}.
590 %
591 % \DescribeOption{title colour}\DescribeOption{title gradient}
592 % \DescribeOption{back title colour}\DescribeOption{back title gradient}
593 % Colour for the title box. The default for both of these is \opt{Dandelion!60}.
594 %
595 % \vspace{3\baselineskip}
596 % \DescribeOption{tags colour}\DescribeOption{tags gradient}
597 % \DescribeOption{back tags colour}\DescribeOption{back tags gradient}
598 % Colour for the tag box. If empty, these default to the corresponding \opt{title} value.
599 %
600 % \vspace{3\baselineskip}
601 % \DescribeOption{frame colour}
602 % \DescribeOption{back frame colour}
603 % The frame's colour. The default value for this is \opt{Bittersweet!60}.
604 %
605 % \vspace{\baselineskip}
606 % \DescribeOption{separator colour}
607 % \DescribeOption{back separator colour}
608 % If you set the \opt{separator} option, this controls the colour of the separator bar. If empty, it defaults to the value of \opt{frame colour}.
609 %
610 % \DescribeOption{border colour}
611 % \DescribeOption{back border colour}
612 % The colour for the outer border of the card. The default is \opt{black}.
613 %
614 % \vspace{\baselineskip}
615 % Here is a card using some of the options described above.
616 % \begin{LaTeXdemo}
617 % \Card[
618 % background colour=ForestGreen!10,
619 % frame colour=PineGreen,
620 % title colour=ForestGreen,
621 % title gradient=Goldenrod,
622 % tags colour=ForestGreen,
623 % tags gradient=MidnightBlue,
624 % border colour=Gray!30,
625 % separator
626 % ] {Colours} {}
627 % \begin{figure}[H]
628 % \ShowCard
629 % \end{figure}
630 % \end{LaTeXdemo}
631 % \subsubsection{Options Controlling the Overall Layout}
632 % \DescribeOption{orientation}
633 % This must be either \opt{portrait} or \opt{landscape}. The default is \opt{portrait}.
634 %
635 % \DescribeOption{separator}
636 % \DescribeOption{back separator}
637 % These are boolean options. They make the separator in the middle of the main area appear on the face respectively the back of the card.
638 %
639 % \DescribeOption{rounded corners}
640 % This is a boolean option that is \opt{true} by default. Setting \opt{rounded corners=false} disables the rounded corners on the outside of the card border. It does \emph{not} affect any of the corners of boxes on the card, only the part where you cut it. This can prevent ugly white corners around the printed cards if you want to cut your cards with a machine but do not have a corner rounder available.
641 %
642 % \DescribeOption{back}
643 % This is a boolean option and is \opt{false} by default. If set, \emph{only} the back of the card is generated. It is unlikely that you will ever want to set this option; the \cs{PrintCards} macro can automatically generate the back sides of all cards.
644 % \subsubsection{Invisible Attributes}
645 % The options described in this section set various attributes of the card which do not usually appear on the card itself, but can be used for control flow, debugging, and by the \cs{ListCards} macro.
646 %
647 % \DescribeOption{uid}
648 % Set this option to a unique string to later be able to fetch this specific card from your card list. For example, you may have a document containing dozens or hundreds of cards, but in the manual for your game you want to show just one of them as an example.
649 % Instead of recreating the card for the manual, give it a uid and \cs{input} your card list, then typeset only that card by passing its uid to the \cs{ShowCard} macro.
650 %
651 % IDs must be unique. If you specify the same \opt{uid} for more than one card, compilation will abort and tell you to fix it.
652 %
653 % Do not use integers as your uids, because \pkg{cardgame} uses them internally. It might work, but it might also not.
654 %
655 % \DescribeOption{version}
656 % You can assign a version number to each card (or, of course, use a card type definition to set all your cards to the same version) in order to track changes while playtesting.
657 % If the \opt{playtest} package option is set, then each card's version number is displayed in its frame.
658 %
659 % \DescribeOption{rulings}
660 % Set this option to describe any additional rules, specific interactions with other cards, or FAQs that are too long to appear on the card itself. You can use the \cs{ListCards} macro to display these rulings in your game's manual.
661 %
662 % \DescribeOption{copies}
663 % Set this to a positive integer to have the \cs{PrintCards} macro generate that many copies of the card (and that many copies of the back as well).
664 % \subsection{Card-Defining Macros}
665 % The main command to make a card is the \cs{Card} macro.
666 % \DescribeMacro {\Card}
667 % \begin{syntax}
668 % \cs{Card} \oarg{options} \marg{name} \marg{text}
669 % \end{syntax}
670 % A card only has two mandatory parts: a name (usually displayed in the title box) and a text.
671 % However, either or both of those mandatory arguments can be empty.
672 % If any of them are empty, then the card instead uses its \opt{name} respectively \opt{text} options, if given.
673 % If those are empty as well, then the card is generated without a name respectively text, which is perfectly legal.
674 %
675 % \opt{options} is a comma-separated list of key-value pairs, as described in the previous sections.
676 % \subsection{Defining New Card Types}\label{sec:cardtypes}
677 % In order to avoid duplicating information in your document, you can define new ``card types'' that share any number of default options.
678 % This has nothing to do with the \opt{type} attribute of a card, though it would be natural for a card type to have a shared \opt{type} as well.
679 % \DescribeMacro {\DeclareCardType}
680 % \begin{syntax}
681 % \cs{DeclareCardType} \oarg{type} \marg{name} \marg{defaults}
682 % \end{syntax}
683 % This command defines a new macro \cs{<name>} (or raises an error if that command already exists). The new macro behaves exactly like the \cs{Card} macro, except that any key-value pairs you pass to the final argument of \cs{DeclareCardType} become the default values for cards created by the new macro.
684 % You can still overwrite them on a case by case basis.
685 %
686 % Card types can inherit from each other: if you pass the name of an existing card type (created by an earlier \cs{DeclareCardType}) as the optional argument to \cs{DeclareCardType}, then all the options of that existing type are imported into the new type. You can override any number of them by passing new values in the \opt{<defaults>} argument.
687 %
688 % For both the \opt{<type>} and the \opt{<name>} option, do not include the backslash. That is, use \cs{DeclareCardType[type]\{name\}}, not \cs{DeclareCardType[\textbackslash type]\{\textbackslash name\}}.
689 % \section{Outputting Things}
690 % The commands in this section are the only ones that actually typeset something.
691 % In order to output a card, you must first have defined it as described in the previous section.
692 %
693 % \DescribeMacro{\ShowCard}
694 % \begin{syntax}
695 % \cs{ShowCard} \oarg{uid}
696 % \end{syntax}
697 % This macro typesets a single card. It is equivalent to a call to \cs{tikz} and as such you probably want to wrap it in a \texttt{figure} environment.
698 %
699 % If no argument is given, then the most recently defined card is shown.
700 % Otherwise, the argument should be the \opt{uid} of an existing card; that card is shown.
701 %
702 % \DescribeMacro{\PrintCards}
703 % \begin{syntax}
704 % \cs{PrintCards} \oarg{options}
705 % \end{syntax}
706 % This macro typesets \emph{all} the cards you have defined in this document.
707 %
708 % Cards are printed flush with each other, nine to a page (the maximum possible for a home printer).
709 %
710 % If you call this in a document that also contains other things, you probably want to call \cs{newpage} first.
711 %
712 % \opt{<options>} is a list of key-value pairs. The following options are recognised.
713 %
714 % \DescribeOption{sort}
715 % This is a boolean. The default is \opt{true} and sorts the cards by type, then level, then subtype, then name. All faces are printed first, then all back sides (if enabled).
716 % If \opt{false}, then cards appear in the order in which they are defined in the document, though back sides still appear last.
717 %
718 % \DescribeOption{backs}
719 % This is a boolean. The default is \opt{true}.
720 % If \opt{false}, only faces are generated, no back sides.
721 %
722 % \cs{PrintCards} requires two compilations to work properly.
723 %
724 % \DescribeMacro{\ListCards}
725 % \begin{syntax}
726 % \cs{ListCards}\oarg{options}
727 % \end{syntax}
728 % This macro generates a table with information about \emph{all} cards you have defined. You can include it in your game manual as a reference.
729 % It takes one optional key-value argument, \opt{sort}, which has the same effect as for the \cs{PrintCards} command.
730 % \begin{LaTeXdemo}[code only]
731 % \ListCards[sort=false]
732 % \end{LaTeXdemo}
733 % \ListCards[sort=false]
734 % \section{Package Options}
735 % The \pkg{cardgame} package accepts the following options.
736 %
737 % \DescribeOption{sort}
738 % This sets the default value of the \opt{sort} option for the \cs{PrintCards} and \cs{ListCards} commands.
739 %
740 % \DescribeOption{backs}
741 % This sets the default value of the \opt{backs} option for the \cs{PrintCards} command.
742 %
743 % \DescribeOption{playtest}
744 % A boolean that defaults to \opt{false}.
745 % If \opt{true}, include versioning information in the frame of the card.
746 % This documentation has been compiled with \opt{playtest=true}.
747 % \section{Issues}
748 % If you find a bug or have a request, please contact me at \texttt{[email protected]} or open an issue at \href{https://codeberg.org/BettaGeorge/cardgame}{https://codeberg.org/BettaGeorge/cardgame}.
749 %
750 % The implementation of \cs{ListCards} is rudimentary and to be improved in future versions of this package.
751 % \end{documentation}
752 %
753 % \begin{implementation}
754 %
755 % \section{Implementation}
756 %
757 % \begin{macrocode}
758 %<*package>
759 % \end{macrocode}
760 %
761 % \begin{macrocode}
762 %<@@=cardgame>
763 % \end{macrocode}
764 %
765 % \begin{macrocode}
766 \ProvidesExplPackage {cardgame} {2026-04-19} {1.0}
767 {Typesetting custom game cards}
768 \RequirePackage{l3keys2e}
769 \RequirePackage[dvipsnames]{xcolor}
770 \RequirePackage{tabularray}
771 % \end{macrocode}
772 % TikZ libraries cannot be loaded while explicit syntax is on, even though they can be \emph{used} without problem.
773 % \begin{macrocode}
774 \ExplSyntaxOff
775 \usepackage{tikz}
776 \usetikzlibrary{calc}
777 \ExplSyntaxOn
778 % \end{macrocode}
779 % \subsection{Variables and constants}
780 %
781 % \begin{macro}{\c_@@_file_message_tl}
782 % A short piece of text that is added to the top of an auto-generated
783 % file. Setting this up as a constant means that it can be changed
784 % (for example for translation) if necessary.
785 % \begin{macrocode}
786 \tl_const:Nn \c_@@_file_message_tl
787 {
788 \iow_char:N \% ~
789 This~is~an~auxiliary~file~used~by~the~'cardgame'~package.
790 \iow_newline:
791 \iow_char:N \% ~
792 This~file~may~safely~be~deleted.
793 \iow_newline:
794 \iow_char:N \% ~
795 It~will~be~recreated~as~required.
796 \iow_newline:
797 }
798 % \end{macrocode}
799 % \end{macro}
800 % \begin{macro}{defaultbgcolour,defaulttitlecolour,defaultframecolour,defaultbordercolour}
801 % The following are the default colours for things, just because we need to do \emph{something} if the user sets no options. I like yellow.
802 % \begin{macrocode}
803 \colorlet{defaultbgcolour}{Dandelion!20}
804 \colorlet{defaulttitlecolour}{Dandelion!60}
805 \colorlet{defaultframecolour}{Bittersweet!60}
806 \colorlet{defaultbordercolour}{black}
807 % \end{macrocode}
808 % \end{macro}
809
810
811 % These token lists contain what certain things should be called.
812 % \begin{macrocode}
813 \tl_const:Nn \const_portrait_tl {portrait}
814 \tl_const:Nn \const_cost_tl {cost}
815 \tl_const:Nn \const_mark_tl {mark}
816 \tl_const:Nn \const_secondarymark_tl {secondary~mark}
817 \tl_const:Nn \const_level_tl {level}
818 \tl_const:Nn \const_type_tl {type}
819 \tl_const:Nn \const_subtype_tl {subtype}
820 \tl_const:Nn \const_tags_tl {tags}
821 \tl_const:Nn \const_name_tl {name}
822 % \end{macrocode}
823
824
825 % These two comma-separated lists save all existing cards.
826 % We are going to write precompiled key lists into them, then later call \cs{tl_use} on each element to recover the values.
827 % \begin{macrocode}
828 \clist_new:N \g_cards_clist
829 \clist_new:N \g_cardbacks_clist
830 % \end{macrocode}
831 % This list saves which uids are currently being used, so we can check whether a newly requested uid is in fact unique.
832 % \begin{macrocode}
833 \clist_new:N \g_uid_clist
834 % \end{macrocode}
835 % The following increments by one each time a card is created and assigns it a unique identifier, if the user has not provided one.
836 % \begin{macrocode}
837 \int_new:N\g_uid_int
838 % \end{macrocode}
839 % This list tracks which tags \emph{exist} at all. This is not currently useful, but we might want to generate lists of tags or something like that later.
840 % \begin{macrocode}
841 \clist_new:N \g_existingtags_clist
842 % \end{macrocode}
843 % debugging messages
844 % \begin{macrocode}
845 \msg_new:nnn { cardgame } { tagcount } {
846 #1:~#2
847 }
848 \msg_new:nnn { cardgame } { cornercontent }{
849 Unknown~identifier~'#1';~
850 typesetting~nothing~and~continuing.
851 }
852 \msg_new:nnn { cardgame } { uid }{
853 UID~'#1'~is~already~taken;~assigning~
854 a~random~one.
855 }
856 % \end{macrocode}
857 % \subsection{Key-Value Options}
858 % We now set up the various key-value options. All of these are documented in the user part of this manual, so we just list them here without further comment.
859 %
860 % First, the options that can be passed to the package itself.
861 % \begin{macrocode}
862 \keys_define:nn { cardgame }
863 {
864 sort .bool_set:N = \l_sort_bool,
865 sort .initial:n = { true },
866 sort .default:n = { true },
867
868 backs .bool_set:N = \l_generatecardbacks_bool,
869 backs .initial:n = { true },
870 backs .default:n = { true },
871
872 playtest .bool_set:N = \l_playtestinfo_bool,
873 playtest .initial:n = { false },
874 playtest .default:n = { true },
875 }
876 \ProcessKeysOptions{cardgame}
877 % \end{macrocode}
878 %
879 % The options that can be passed to list-producing macros (\cs{PrintCards} and \cs{ListCards}) overlap with the package options, but we may want to add more in the future.
880 % \begin{macrocode}
881 \keys_define:nn { cardlist }
882 {
883 sort .bool_set:N = \l_sort_bool,
884 sort .initial:n = { true },
885 sort .default:n = { true },
886
887 backs .bool_set:N = \l_generatecardbacks_bool,
888 backs .initial:n = { true },
889 backs .default:n = { true },
890 }
891 % \end{macrocode}
892 % By far the most expansive list is the one for the \cs{Card} command.
893 % The meta keys are just a trick to make \opt{color} set \opt{colour}.
894 % \begin{macrocode}
895 \keys_define:nn { card }
896 {
897 % OPTIONS DEFINING CARD TEXT
898 name .tl_set:N = \l_name_tl,
899 name .initial:n = {},
900 name .default:n = {},
901
902 type .tl_set:N = \l_type_tl,
903 type .initial:n = {},
904 type .default:n = {},
905
906 subtype .tl_set:N = \l_subtype_tl,
907 subtype .initial:n = {},
908 subtype .default:n = {},
909
910 text .tl_set:N = \l_text_tl,
911 text .initial:n = {},
912 % text .default:n = {},
913
914 more~text .tl_set:N = \l_moretext_tl,
915 more~text .initial:n = {},
916 % more~text .default:n = {},
917
918 art .tl_set:N = \l_art_tl,
919 art .initial:n = {},
920 art .default:n = {},
921
922 back~art .tl_set:N = \l_backart_tl,
923 back~art .initial:n = {},
924 back~art .default:n = {},
925
926 cost .tl_set:N = \l_cost_tl,
927 cost .initial:n = { 0 },
928 cost .default:n = 0,
929
930 mark .tl_set:N = \l_mark_tl,
931 mark .initial:n = {},
932 mark .default:n = {},
933
934 secondary~mark .tl_set:N = \l_mark_tl,
935 secondary~mark .initial:n = {},
936 secondary~mark .default:n = {},
937
938 level .int_set:N = \l_level_int,
939 level .initial:n = { 0 },
940 level .default:n = 0,
941
942 tags .clist_set:N = \l_tags_clist,
943 tags .initial:n = {},
944 tags .default:n = {},
945
946 % OPTIONS MODIFYING THE DISPLAY OF TEXT
947
948 modify~name .tl_set:N = \l_modifyname_tl,
949 modify~name .initial:n = { \Large\bf },
950 modify~name .default:n = {},
951
952 modify~text .tl_set:N = \l_textsize_tl,
953 modify~text .initial:n = {\normalsize},
954 modify~text .default:n = {\normalsize},
955
956 modify~more~text .tl_set:N = \l_moretextsize_tl,
957 modify~more~text .initial:n = {\normalsize},
958 modify~more~text .default:n = {\normalsize},
959
960 modify~north~west .tl_set:N = \l_nwtextsize_tl,
961 modify~north~west .initial:n = {\normalsize},
962 modify~north~west .default:n = {\normalsize},
963 modify~north~west~pre .tl_set:N = \l_nwpretextsize_tl,
964 modify~north~west~pre .initial:n = {\tiny},
965 modify~north~west~pre .default:n = {\tiny},
966 modify~north~west~post .tl_set:N = \l_nwposttextsize_tl,
967 modify~north~west~post .initial:n = {\tiny},
968 modify~north~west~post .default:n = {\tiny},
969 modify~north~east .tl_set:N = \l_netextsize_tl,
970 modify~north~east .initial:n = {\normalsize},
971 modify~north~east .default:n = {\normalsize},
972 modify~north~east~pre .tl_set:N = \l_nepretextsize_tl,
973 modify~north~east~pre .initial:n = {\tiny},
974 modify~north~east~pre .default:n = {\tiny},
975 modify~north~east~post .tl_set:N = \l_neposttextsize_tl,
976 modify~north~east~post .initial:n = {\tiny},
977 modify~north~east~post .default:n = {\tiny},
978 modify~south~east .tl_set:N = \l_setextsize_tl,
979 modify~south~east .initial:n = {\normalsize},
980 modify~south~east .default:n = {\normalsize},
981 modify~south~east~pre .tl_set:N = \l_sepretextsize_tl,
982 modify~south~east~pre .initial:n = {\tiny},
983 modify~south~east~pre .default:n = {\tiny},
984 modify~south~east~post .tl_set:N = \l_seposttextsize_tl,
985 modify~south~east~post .initial:n = {\tiny},
986 modify~south~east~post .default:n = {\tiny},
987 modify~south~west .tl_set:N = \l_swtextsize_tl,
988 modify~south~west .initial:n = {\normalsize},
989 modify~south~west .default:n = {\normalsize},
990 modify~south~west~pre .tl_set:N = \l_swpretextsize_tl,
991 modify~south~west~pre .initial:n = {\tiny},
992 modify~south~west~pre .default:n = {\tiny},
993 modify~south~west~post .tl_set:N = \l_swposttextsize_tl,
994 modify~south~west~post .initial:n = {\tiny},
995 modify~south~west~post .default:n = {\tiny},
996
997 % OPTIONS CONTROLLING THE PLACEMENT OF TEXT
998
999 tag~box .tl_set:N = \l_tagbox_tl,
1000 tag~box .initial:n = { tags },
1001 tag~box .default:n = {},
1002 tag~box~content .tl_set:N = \l_tagboxcontent_tl,
1003 tag~box~content .initial:n = {},
1004 tag~box~content .default:n = {},
1005 back~tag~box .tl_set:N = \l_btagbox_tl,
1006 back~tag~box .initial:n = {},
1007 back~tag~box .default:n = {},
1008
1009 title~box .tl_set:N = \l_titlebox_tl,
1010 title~box .initial:n = { name },
1011 title~box .default:n = {},
1012 title~box~content .tl_set:N = \l_titleboxcontent_tl,
1013 title~box~content .initial:n = {},
1014 title~box~content .default:n = {},
1015 back~title~box .tl_set:N = \l_btitlebox_tl,
1016 back~title~box .initial:n = { type },
1017 back~title~box .default:n = {},
1018
1019 south~west~content .tl_set:N = \l_swcontent_tl,
1020 south~west~content .initial:n = {},
1021 south~west~content .default:n = {},
1022 south~west~pre .tl_set:N = \l_swpre_tl,
1023 south~west~pre .initial:n = {},
1024 south~west~pre .default:n = {},
1025 south~west~post .tl_set:N = \l_swpost_tl,
1026 south~west~post .initial:n = {},
1027 south~west~post .default:n = {},
1028 south~west .tl_set:N = \l_sw_tl,
1029 south~west .initial:n = {},
1030 south~west .default:n = {},
1031 back~south~west .tl_set:N = \l_bsw_tl,
1032 back~south~west .initial:n = {},
1033 back~south~west .default:n = {},
1034
1035 south~east~content .tl_set:N = \l_secontent_tl,
1036 south~east~content .initial:n = {},
1037 south~east~content .default:n = {},
1038 south~east~pre .tl_set:N = \l_sepre_tl,
1039 south~east~pre .initial:n = {},
1040 south~east~pre .default:n = {},
1041 south~east~post .tl_set:N = \l_sepost_tl,
1042 south~east~post .initial:n = {},
1043 south~east~post .default:n = {},
1044 south~east .tl_set:N = \l_se_tl,
1045 south~east .initial:n = {},
1046 south~east .default:n = {},
1047 back~south~east .tl_set:N = \l_bse_tl,
1048 back~south~east .initial:n = {},
1049 back~south~east .default:n = {},
1050
1051 north~west~content .tl_set:N = \l_nwcontent_tl,
1052 north~west~content .initial:n = {},
1053 north~west~content .default:n = {},
1054 north~west~pre .tl_set:N = \l_nwpre_tl,
1055 north~west~pre .initial:n = {},
1056 north~west~pre .default:n = {},
1057 north~west~post .tl_set:N = \l_nwpost_tl,
1058 north~west~post .initial:n = {},
1059 north~west~post .default:n = {},
1060 north~west .tl_set:N = \l_nw_tl,
1061 north~west .initial:n = {},
1062 north~west .default:n = {},
1063 back~north~west .tl_set:N = \l_bnw_tl,
1064 back~north~west .initial:n = {},
1065 back~north~west .default:n = {},
1066
1067 north~east~content .tl_set:N = \l_necontent_tl,
1068 north~east~content .initial:n = {},
1069 north~east~content .default:n = {},
1070 north~east~pre .tl_set:N = \l_nepre_tl,
1071 north~east~pre .initial:n = {},
1072 north~east~pre .default:n = {},
1073 north~east~post .tl_set:N = \l_nepost_tl,
1074 north~east~post .initial:n = {},
1075 north~east~post .default:n = {},
1076 north~east .tl_set:N = \l_ne_tl,
1077 north~east .initial:n = {},
1078 north~east .default:n = {},
1079 back~north~east .tl_set:N = \l_bne_tl,
1080 back~north~east .initial:n = {},
1081 back~north~east .default:n = {},
1082
1083 % COLOUR OPTIONS
1084
1085 link~colours .bool_set:N = \l_linkcolours_bool,
1086 link~colours .initial:n = { false },
1087 link~colours .default:n = { true },
1088 link~colors .meta:n = { link~colours={#1} },
1089
1090 background~colour .tl_set:N = \l_col_bg_tl,
1091 background~colour .initial:n = {},
1092 background~colour .default:n = {},
1093 background~color .meta:n = { background~colour={#1} },
1094
1095 title~colour .tl_set:N = \l_col_title_tl,
1096 title~colour .initial:n = {},
1097 title~colour .default:n = {},
1098 title~color .meta:n = { title~colour={#1} },
1099 title~gradient .tl_set:N = \l_grad_title_tl,
1100 title~gradient .initial:n = {},
1101 title~gradient .default:n = {},
1102
1103 tags~colour .tl_set:N = \l_col_tags_tl,
1104 tags~colour .initial:n = {},
1105 tags~colour .default:n = {},
1106 tags~color .meta:n = { tags~colour={#1} },
1107 tags~gradient .tl_set:N = \l_grad_tags_tl,
1108 tags~gradient .initial:n = {},
1109 tags~gradient .default:n = {},
1110
1111 frame~colour .tl_set:N = \l_col_frame_tl,
1112 frame~colour .initial:n = {},
1113 frame~colour .default:n = {},
1114 frame~color .meta:n = { frame~colour={#1} },
1115
1116 separator~colour .tl_set:N = \l_col_separator_tl,
1117 separator~colour .initial:n = {},
1118 separator~colour .default:n = {},
1119 separator~color .meta:n = { frame~colour={#1} },
1120
1121 border~colour .tl_set:N = \l_col_border_tl,
1122 border~colour .initial:n = {},
1123 border~colour .default:n = {},
1124 border~color .meta:n = { border~colour={#1} },
1125
1126 back~background~colour .tl_set:N = \l_bcol_bg_tl,
1127 back~background~colour .initial:n = {},
1128 back~background~colour .default:n = {},
1129 back~background~color .meta:n = { back~background~colour={#1} },
1130
1131 back~title~colour .tl_set:N = \l_bcol_title_tl,
1132 back~title~colour .initial:n = {},
1133 back~title~colour .default:n = {},
1134 back~title~color .meta:n = { back~title~colour={#1} },
1135 back~title~gradient .tl_set:N = \l_bgrad_title_tl,
1136 back~title~gradient .initial:n = {},
1137 back~title~gradient .default:n = {},
1138
1139 back~tags~colour .tl_set:N = \l_bcol_tags_tl,
1140 back~tags~colour .initial:n = {},
1141 back~tags~colour .default:n = {},
1142 back~tags~color .meta:n = { back~tags~colour={#1} },
1143 back~tags~gradient .tl_set:N = \l_bgrad_tags_tl,
1144 back~tags~gradient .initial:n = {},
1145 back~tags~gradient .default:n = {},
1146
1147 back~frame~colour .tl_set:N = \l_bcol_frame_tl,
1148 back~frame~colour .initial:n = {},
1149 back~frame~colour .default:n = {},
1150 back~frame~color .meta:n = { back~frame~colour={#1} },
1151
1152 back~separator~colour .tl_set:N = \l_bcol_separator_tl,
1153 back~separator~colour .initial:n = {},
1154 back~separator~colour .default:n = {},
1155 back~separator~color .meta:n = { frame~colour={#1} },
1156
1157 back~border~colour .tl_set:N = \l_bcol_border_tl,
1158 back~border~colour .initial:n = {},
1159 back~border~colour .default:n = {},
1160 back~border~color .meta:n = { back~border~colour={#1} },
1161
1162 % OPTIONS CONTROLLING THE OVERALL LAYOUT
1163
1164 orientation .tl_set:N = \l_orientation_tl,
1165 orientation .initial:n = {portrait},
1166 orientation .default:n = {portrait},
1167
1168 separator .bool_set:N = \l_separator_bool,
1169 separator .initial:n = { false },
1170 separator .default:n = { true },
1171
1172 back~separator .bool_set:N = \l_bseparator_bool,
1173 back~separator .initial:n = { false },
1174 back~separator .default:n = { true },
1175
1176 rounded~corners .bool_set:N = \l_rounded_corners_bool,
1177 rounded~corners .initial:n = { true },
1178 rounded~corners .default:n = { true },
1179
1180 back .bool_set:N = \l_back_bool,
1181 back .initial:n = { false },
1182 back .default:n = { true },
1183
1184 % OPTIONS FOR INVISIBLE ATTRIBUTES
1185
1186 version .tl_set:N = \l_version_tl,
1187 version .initial:n = {},
1188 version .default:n = {},
1189
1190 rulings .tl_set:N = \l_rulings_tl,
1191 rulings .initial:n = {},
1192 rulings .default:n = {},
1193
1194 uid .tl_set:N = \l_uid_tl,
1195 uid .initial:n = {},
1196 uid .default:n = {},
1197
1198 copies .int_set:N = \l_copies_int,
1199 copies .initial:n = { 1 },
1200 copies .default:n = 1,
1201 }
1202 % \end{macrocode}
1203 % \subsection{Helper Functions}
1204 % \begin{macro}{\insert_attribute:n}
1205 % Use this in places where we want to typeset one of the
1206 % various attributes of a card based on the user's preference.
1207 % The sole argument is the string the user passed.
1208 % For example, if \opt{south west=mark} is set by the user, then
1209 % while typesetting the south west corner, we call
1210 % \cs{insert_attribute:n\{mark\}}.
1211 % \begin{macrocode}
1212 \cs_new:Nn \insert_attribute:n {
1213 \tl_case:NnF{#1}{
1214 \const_tags_tl {
1215 \clist_use:Nn \l_tags_clist {,~}
1216 }
1217 \const_cost_tl {
1218 \tl_use:N\l_cost_tl
1219 }
1220 \const_level_tl {
1221 \int_use:N\l_level_int
1222 }
1223 \const_mark_tl {
1224 \tl_use:N\l_mark_tl
1225 }
1226 \const_secondarymark_tl {
1227 \tl_use:N\l_secondarymark_tl
1228 }
1229 \const_type_tl {
1230 \tl_use:N\l_type_tl
1231 }
1232 \const_subtype_tl {
1233 \tl_use:N\l_subtype_tl
1234 }
1235 \const_name_tl {
1236 \tl_use:N\l_name_tl
1237 }
1238 }{
1239 \msg_error:nnV { cardgame }{ cornercontent }{ #1 }
1240 }
1241 }
1242 % \end{macrocode}
1243 % \end{macro}
1244 %
1245 % \subsection{Defining Cards}
1246 % \begin{macro}{\card:n}
1247 % The main command to make a card.
1248 % It takes all of its arguments via the key-value interface.
1249 % It stores the card indexed by its type, subtype, and name, such that we can later
1250 % sort them alphabetically.
1251 % It also stores a copy of the card indexed by its uid, because I could not figure
1252 % out how to use references.
1253 % We do not typeset the cards yet; this is handled by separate commands.
1254 % If automatic card back generation is on, the command calls itself
1255 % once to generate the back side.
1256 % \begin{macrocode}
1257 \cs_generate_variant:Nn \keys_precompile:nnN { nVN }
1258 \cs_new:Nn \card:n {
1259 \group_begin:
1260 \keys_set:nn { card } { #1 }
1261 % first, if a uid was provided, check whether it is valid.
1262 % if not, assign one.
1263 % Do not do any of this for backsides though.
1264 \bool_if:NF \l_back_bool {
1265 \tl_if_empty:NTF\l_uid_tl {
1266 \tl_set:NV\l_uid_tl\g_uid_int
1267 \int_gincr:N\g_uid_int
1268 }{
1269 \clist_if_in:NVT\g_uid_clist\l_uid_tl {
1270 \msg_error:nnV {cardgame} {uid} {\l_uid_tl}
1271 \tl_set:Ne\l_uid_tl{\int_use:N\g_uid_int}
1272 \int_incr:N\g_uid_int
1273 }
1274 }
1275 \clist_gput_right:NV \g_uid_clist \l_uid_tl
1276 }
1277
1278 % we simply set a new token list to contain all the keys of the card.
1279 % since we want to process back sides separately, they go in a special
1280 % back side list.
1281 \bool_if:NTF \l_back_bool {
1282 \tl_new:c {
1283 cardback @
1284 \l_type_tl @
1285 \int_use:N\l_level_int @
1286 \l_subtype_tl @
1287 \l_name_tl @
1288 \l_uid_tl
1289 }
1290 \keys_precompile:nnN { card } { #1 } \l_tmpa_tl
1291 % precompile is a local assignment, and there is no global variant.
1292 \tl_gset_eq:cN {
1293 cardback @
1294 \l_type_tl @
1295 \int_use:N\l_level_int @
1296 \l_subtype_tl @
1297 \l_name_tl @
1298 \l_uid_tl
1299 } \l_tmpa_tl
1300
1301 % also, we somehow need to remember which cards exist.
1302 % Since it is hard to expand multiple copies during the typesetting loop later,
1303 % we simply copy the card now.
1304 \int_set:Nn \l_tmpa_int { 0 }
1305 \int_while_do:nNnn { \l_tmpa_int } < { \l_copies_int } {
1306 \clist_gput_right:Nx \g_cardbacks_clist {
1307 cardback @
1308 \l_type_tl @
1309 \int_use:N\l_level_int @
1310 \l_subtype_tl @
1311 \l_name_tl @
1312 \l_uid_tl
1313 }
1314 \int_incr:N \l_tmpa_int
1315 }
1316 }{
1317 \tl_new:c {
1318 \l_type_tl @
1319 \int_use:N\l_level_int @
1320 \l_subtype_tl @
1321 \l_name_tl @
1322 \l_uid_tl
1323 }
1324 \tl_set:Nn\l_tmpb_tl { #1 }
1325 \tl_put_right:Nx\l_tmpb_tl {, uid=\tl_use:N\l_uid_tl }
1326 \keys_precompile:nVN { card } \l_tmpb_tl \l_tmpa_tl
1327 % precompile is a local assignment, and there is no global variant.
1328 \tl_gset_eq:cN {
1329 \l_type_tl @
1330 \int_use:N\l_level_int @
1331 \l_subtype_tl @
1332 \l_name_tl @
1333 \l_uid_tl
1334 } \l_tmpa_tl
1335 % We are currently doing a front side, so we also save the card in the uid list.
1336 \tl_gset_eq:cN { card_by_uid @ \l_uid_tl } \l_tmpa_tl
1337 % also, we somehow need to remember which cards exist.
1338 % Since it is hard to expand multiple copies during the typesetting loop later,
1339 % we simply copy the card now.
1340 % Yes, this is unnecessary memory overhead, but when will you
1341 % ever have so many cards that it matters in practice?
1342 \int_set:Nn \l_tmpa_int { 0 }
1343 \int_while_do:nNnn { \l_tmpa_int } < { \l_copies_int } {
1344 \clist_gput_right:Nx \g_cards_clist {
1345 \l_type_tl @
1346 \int_use:N\l_level_int @
1347 \l_subtype_tl @
1348 \l_name_tl @
1349 \l_uid_tl
1350 }
1351 \int_incr:N \l_tmpa_int
1352 }
1353 \bool_if:NT \l_generatecardbacks_bool {
1354 \card:n { #1, back }
1355 }
1356 }
1357 \group_end:
1358 }
1359 % \end{macrocode}
1360 % \end{macro}
1361
1362 % \subsection{Generating Output}
1363
1364 % \begin{macro}{\typeset_card:nnn}
1365 % \cs{typeset_card} is what actually TikZes cards.
1366 % You should not have to call it directly, but in case you do, here is what it does.
1367 % The first argument is either empty or a card UID as generated by \cs{card}, that is,
1368 % the string \texttt{card_by_uid@<uid>}.
1369 % The second argument is a list of key-value pairs.
1370 % The third argument is either empty or an integer between 0 and 8.
1371 % The card to be typeset gets all the characteristics of the card specified
1372 % in the first argument. Then all the keys specified in the second argument
1373 % override those. If the first argument is empty, then naturally you must
1374 % specify all characteristics as key-value pairs in the second argument.
1375 % If the third argument is empty, a TikZ picture is then produced with no
1376 % special placement. Wrap it in a figure environment or whatever else you
1377 % want to do with the picture.
1378 % If the third argument is an integer, the card is placed at that index plus
1379 % one on the current page using the overlay mechanism. This is used by
1380 % the \cs{print_cards} macro.
1381 %
1382 % An M:tG card is 63x88 mm big. We use 64x89 mm to leave some room for error while cutting while still fitting inside a standard sleeve.
1383 % An A4 page is 210x297 mm.
1384 % In particular, a 3x3 portrait layout is optimal, since a landscape layout
1385 % only admits 2x4 cards.
1386 % \begin{macrocode}
1387 \cs_new:Nn \typeset_card:nnn {
1388
1389 \tl_if_blank:nF {#3} {
1390 % We calculate the offset of the lower left corner of the card
1391 % (henceforth referred to as the "base").
1392 \int_zero_new:N \l_xoffset_int
1393 \int_zero_new:N \l_yoffset_int
1394 \int_set:Nn \l_xoffset_int { % x offset in mm
1395 (
1396 \int_mod:nn { #3 - 1 } { 3 }
1397 ) * 66
1398 }
1399 \int_set:Nn \l_yoffset_int { % y offset in mm
1400 (
1401 2 -
1402 \int_div_truncate:nn { #3 - 1 } { 3 }
1403 ) * 91
1404 }
1405 }
1406
1407 \group_begin:
1408 \tl_if_blank:nF{#1}{
1409 \tl_use:c { #1 }
1410 }
1411 \tl_if_blank:nF{#2}{
1412 \keys_set:nx { card } { #2 }
1413 }
1414
1415 % The tags should always be sorted the same.
1416 \clist_sort:Nn \l_tags_clist {
1417 \str_compare:nNnTF { ##1 } < { ##2 } { \sort_return_same: } { \sort_return_swapped: }
1418 }
1419 % And let's keep a handy counter of the tags used.
1420 \bool_if:NF \l_back_bool {
1421 \clist_map_inline:Nn \l_tags_clist {
1422 \int_if_exist:cF { tagcounter @ ##1 }{
1423 \int_new:c { tagcounter @ ##1 }
1424 \clist_gput_right:Nn \g_existingtags_clist { ##1 }
1425 }
1426 \int_gincr:c { tagcounter @ ##1 }
1427 }
1428 }
1429
1430 % First, we figure out all the colours to use on the face of the card.
1431 \tl_if_empty:NTF\l_col_bg_tl{
1432 \colorlet{bg}{defaultbgcolour}
1433 }{
1434 \colorlet{bg}{\tl_use:N\l_col_bg_tl}
1435 }
1436 \tl_if_empty:NTF\l_col_frame_tl{
1437 \colorlet{marg}{defaultframecolour}
1438 }{
1439 \colorlet{marg}{\tl_use:N\l_col_frame_tl}
1440 }
1441 \tl_if_empty:NTF\l_col_separator_tl{
1442 \colorlet{separator}{marg}
1443 }{
1444 \colorlet{separator}{\tl_use:N\l_col_separator_tl}
1445 }
1446 \tl_if_empty:NTF\l_col_title_tl{
1447 \colorlet{box}{defaulttitlecolour}
1448 }{
1449 \colorlet{box}{\tl_use:N\l_col_title_tl}
1450 }
1451 \tl_if_empty:NTF\l_grad_title_tl{
1452 \colorlet{boxgradient}{box}
1453 }{
1454 \colorlet{boxgradient}{\tl_use:N\l_grad_title_tl}
1455 }
1456 \tl_if_empty:NTF\l_col_tags_tl{
1457 \colorlet{tagscolour}{box}
1458 }{
1459 \colorlet{tagscolour}{\tl_use:N\l_col_tags_tl}
1460 }
1461 \tl_if_empty:NTF\l_grad_tags_tl{
1462 \colorlet{tagsgradient}{boxgradient}
1463 }{
1464 \colorlet{tagsgradient}{\tl_use:N\l_grad_tags_tl}
1465 }
1466 \tl_if_empty:NTF\l_col_border_tl{
1467 \colorlet{border}{defaultbordercolour}
1468 }{
1469 \colorlet{border}{\tl_use:N\l_col_border_tl}
1470 }
1471
1472 % Now, if the back colours are linked, copy everything.
1473 % If not, initialise them to the default colours. They might get overridden
1474 % in the next step, stay tuned.
1475 \bool_if:NTF\l_linkcolours_bool {
1476 \colorlet{bbg}{bg}
1477 \colorlet{bmarg}{marg}
1478 \colorlet{bseparator}{separator}
1479 \colorlet{bbox}{box}
1480 \colorlet{bboxgradient}{boxgradient}
1481 \colorlet{btagscolour}{tagscolour}
1482 \colorlet{btagsgradient}{tagsgradient}
1483 \colorlet{bborder}{border}
1484 }{
1485 \colorlet{bbg}{defaultbgcolour}
1486 \colorlet{bmarg}{defaultframecolour}
1487 \colorlet{bseparator}{bmarg}
1488 \colorlet{bbox}{defaulttitlecolour}
1489 \colorlet{bboxgradient}{bbox}
1490 \colorlet{btagscolour}{bbox}
1491 \colorlet{btagsgradient}{bboxgradient}
1492 \colorlet{bborder}{defaultbordercolour}
1493 }
1494
1495 % All back colours that were explicitly specified override the above.
1496 \tl_if_empty:NF\l_bcol_bg_tl{
1497 \colorlet{bbg}{\tl_use:N\l_bcol_bg_tl}
1498 }
1499 \tl_if_empty:NF\l_bcol_frame_tl{
1500 \colorlet{bmarg}{\tl_use:N\l_bcol_frame_tl}
1501 }
1502 \tl_if_empty:NF\l_bcol_separator_tl{
1503 \colorlet{bseparator}{\tl_use:N\l_bcol_separator_tl}
1504 }
1505 \tl_if_empty:NF\l_bcol_title_tl{
1506 \colorlet{bbox}{\tl_use:N\l_bcol_title_tl}
1507 }
1508 \tl_if_empty:NF\l_bgrad_title_tl{
1509 \colorlet{bboxgradient}{\tl_use:N\l_bgrad_title_tl}
1510 }
1511 \tl_if_empty:NF\l_bcol_tags_tl{
1512 \colorlet{btagscolour}{\tl_use:N\l_bcol_tags_tl}
1513 }
1514 \tl_if_empty:NF\l_bgrad_tags_tl{
1515 \colorlet{btagsgradient}{\tl_use:N\l_bgrad_tags_tl}
1516 }
1517 \tl_if_empty:NF\l_bcol_border_tl{
1518 \colorlet{bborder}{\tl_use:N\l_bcol_border_tl}
1519 }
1520
1521 % Let the drawing begin.
1522 \tikz[
1523 remember~picture=\tl_if_blank:nTF{#3}{false}{true},
1524 overlay=\tl_if_blank:nTF{#3}{false}{true},
1525 minimum~size=0pt,
1526 outer~sep=0pt,
1527 inner~sep=0pt,
1528 ]{
1529 % BASE NODE
1530 \tl_if_blank:nTF{#3}{
1531 \node[] (base) at (0,0) {};
1532 }{
1533 \node[] (base) at (
1534 $ (current~page.south~west)
1535 + (0.8cm,1.5cm)
1536 + (\int_use:N \l_xoffset_int mm,\int_use:N \l_yoffset_int mm) $
1537 ) {};
1538 }
1539
1540 % card background
1541 \draw[
1542 fill=\bool_if:NTF\l_back_bool{bbg}{bg}
1543 ] (base) rectangle ($(base) + (64mm,89mm)$);
1544
1545 % colour frame
1546 \draw[
1547 line~width=2mm,
1548 color=\bool_if:NTF\l_back_bool{bmarg}{marg},
1549 ] \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1550 ($(base) + (2mm,89mm) $) -- ($(base) + (2mm,0mm) $) ;
1551 }
1552 {
1553 ($(base) + (0mm,2mm) $) -- ($(base) + (64mm,2mm) $) ;
1554 }
1555
1556 \draw[
1557 line~width=2mm,
1558 color=\bool_if:NTF\l_back_bool{bmarg}{marg},
1559 ] \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl
1560 {
1561 ($(base) + (62mm,89mm) $) -- ($(base) + (62mm,0mm) $) ;
1562 }
1563 {
1564 ($(base) + (0mm,87mm) $) -- ($(base) + (64mm,87mm) $) ;
1565 }
1566
1567 % SEPARATOR
1568 \bool_if:NTF \l_back_bool {
1569 \bool_if:NT \l_bseparator_bool {
1570 \path[
1571 draw=bseparator,
1572 line~width=1mm,
1573 ]
1574 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1575 ($(base) + (3mm,40mm)$) -- +(58mm,0mm);
1576 }{
1577 ($(base) + (3mm,44.5mm)$) -- +(58mm,0mm);
1578 }
1579 }
1580 }{
1581 \bool_if:NT \l_separator_bool {
1582 \path[
1583 draw=separator,
1584 line~width=1mm,
1585 ]
1586 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1587 ($(base) + (3mm,40mm)$) -- +(58mm,0mm);
1588 }{
1589 ($(base) + (3mm,44.5mm)$) -- +(58mm,0mm);
1590 }
1591 }
1592 }
1593
1594 % TITLE BOX
1595 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1596 \shade[
1597 bottom~color=\bool_if:NTF\l_back_bool{bbox}{box},
1598 top~color=\bool_if:NTF\l_back_bool{bboxgradient}{boxgradient},
1599 draw=none,
1600 rounded~corners=4mm,
1601 ]
1602 ($(base) + (0mm,89mm) $) -- ++(0mm,-15mm) --++(64mm,0mm) -- ++(0mm,15mm) --cycle;
1603 }{
1604 \shade[
1605 right~color=\bool_if:NTF\l_back_bool{bbox}{box},
1606 left~color=\bool_if:NTF\l_back_bool{bboxgradient}{boxgradient},
1607 draw=none,
1608 rounded~corners=4mm,
1609 ]
1610 ($(base) + (0mm,0mm) $) -- ++(0mm,89mm) --++(15mm,0mm) -- ++(0mm,-89mm) --cycle;
1611 }
1612
1613 % TAG BOX
1614 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1615 \shade[
1616 top~color=\bool_if:NTF\l_back_bool{btagscolour}{tagscolour},
1617 bottom~color=\bool_if:NTF\l_back_bool{btagsgradient}{tagsgradient},
1618 draw=none,
1619 rounded~corners=4mm,
1620 ]
1621 (base) -- ++(0mm,9mm) -- ++(64mm,0mm) -- ++(0mm,-9mm) --cycle;
1622 }{
1623 \shade[
1624 left~color=\bool_if:NTF\l_back_bool{btagscolour}{tagscolour},
1625 right~color=\bool_if:NTF\l_back_bool{btagsgradient}{tagsgradient},
1626 draw=none,
1627 rounded~corners=4mm,
1628 ]
1629 ($(base) + (64mm,0mm) $) -- ++(-9mm,0mm) -- ++(0mm,89mm) -- ++(9mm,0mm) --cycle;
1630 }
1631
1632 % Tags
1633 \node[
1634 anchor=center,
1635 align=center,
1636 font=\normalsize,
1637 text~width=50mm,
1638 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1639 ] (tags) at
1640 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl
1641 {
1642 ($ (base) + (32mm,6mm) + (0mm,-1.5mm) $)
1643 }
1644 {
1645 ($ (base) + (58mm,44.5mm) + (1.5mm,0mm) $)
1646 }
1647 {
1648 \bool_if:NTF \l_back_bool{
1649 \tl_if_empty:NF \l_btagbox_tl {
1650 \insert_attribute:n{\l_btagbox_tl}
1651 }
1652 } {
1653 \tl_if_empty:NTF \l_tagboxcontent_tl {
1654 \tl_if_empty:NF \l_tagbox_tl {
1655 \insert_attribute:n{\l_tagbox_tl}
1656 }
1657 }{
1658 \tl_use:N\l_tagboxcontent_tl
1659 }
1660 }
1661 };
1662
1663 % CARD BORDER
1664 \draw[
1665 color=\bool_if:NTF\l_back_bool{bborder}{border},
1666 line~width=2mm,
1667 rounded~corners=4mm,
1668 fill=none,
1669 ] (base) -- ++(0mm,89mm) -- ++(64mm,0mm) -- ++(0mm,-89mm) --cycle;
1670 % I could not find a way to make a TikZ path have rounded corners
1671 % only on one side, so instead we simply draw over it if the outer
1672 % corners are desired to be unrounded.
1673 \bool_if:NF\l_rounded_corners_bool{
1674 \draw[
1675 color=\bool_if:NTF\l_back_bool{bborder}{border},
1676 line~width=2mm,
1677 fill=none,
1678 ] (base) -- ++(0mm,89mm) -- ++(64mm,0mm) -- ++(0mm,-89mm) --cycle;
1679 }
1680
1681 % CARD NAME
1682 \node[
1683 anchor=center,
1684 align=center,
1685 font=\tl_use:N\l_modifyname_tl,
1686 text~width=\tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {54mm} {70mm} ,
1687 rotate=\tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1688 ] (title) at
1689 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl
1690 {
1691 ($ (base) + (32mm,81mm) $)
1692 } {
1693 ($ (base) + (8mm,44.5mm) $)
1694 }
1695 {
1696 \bool_if:NTF \l_back_bool
1697 {
1698 \tl_if_empty:NF \l_btitlebox_tl {
1699 \insert_attribute:n \l_btitlebox_tl
1700 }
1701 }
1702 {
1703 \tl_if_empty:NTF \l_titleboxcontent_tl
1704 {
1705 \tl_if_empty:NF \l_titlebox_tl {
1706 \insert_attribute:n \l_titlebox_tl
1707 }
1708 }
1709 {
1710 \l_titleboxcontent_tl
1711 }
1712 }
1713 };
1714
1715 % CORNER CONTENT
1716 % NORTH WEST
1717 \node[
1718 anchor=west ,
1719 align=left,
1720 font=\tl_use:N\l_nwtextsize_tl,
1721 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1722 minimum~size=5mm,
1723 ] (nwcontent) at
1724 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1725 ($(base)+(5mm,81.5mm)$)
1726 }{
1727 ($(base)+(7.5mm,5mm)$)
1728 }
1729 {
1730 \bool_if:NTF\l_back_bool {
1731 \tl_if_empty:NF\l_bnw_tl{
1732 \tl_use:N\l_bnw_tl
1733 }
1734 }{
1735 \tl_if_empty:NF\l_nwpre_tl{
1736 \tl_use:N\l_nwpretextsize_tl
1737 \tl_use:N\l_nwpre_tl\\[-1mm]
1738 }
1739 \tl_if_empty:NTF\l_nw_tl{
1740 \tl_use:N\l_nwcontent_tl
1741 }{
1742 \insert_attribute:n \l_nw_tl
1743 }
1744 \tl_if_empty:NF\l_nwpost_tl{
1745 \\[-2mm]
1746 \tl_use:N\l_nwposttextsize_tl
1747 \tl_use:N\l_nwpost_tl
1748 }
1749 }
1750 };
1751 % SOUTH WEST
1752 \node[
1753 anchor=west ,
1754 align=left,
1755 font=\tl_use:N\l_swtextsize_tl,
1756 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1757 minimum~size=5mm,
1758 ] (swcontent) at
1759 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1760 ($(base)+(5mm,5mm)$)
1761 }{
1762 ($(base)+(59mm,5mm)$)
1763 }
1764 {
1765 \bool_if:NTF\l_back_bool {
1766 \tl_if_empty:NF\l_bsw_tl{
1767 \tl_use:N\l_bsw_tl
1768 }
1769 }{
1770 \tl_if_empty:NF\l_swpre_tl{
1771 \tl_use:N\l_swpretextsize_tl
1772 \tl_use:N\l_swpre_tl\\[-1mm]
1773 }
1774 \tl_if_empty:NTF\l_sw_tl{
1775 \tl_use:N\l_swcontent_tl
1776 }{
1777 \insert_attribute:n \l_sw_tl
1778 }
1779 \tl_if_empty:NF\l_swpost_tl{
1780 \\[-2mm]
1781 \tl_use:N\l_swposttextsize_tl
1782 \tl_use:N\l_swpost_tl
1783 }
1784 }
1785 };
1786 % NORTH EAST
1787 \node[
1788 anchor=east,
1789 align=right,
1790 font=\tl_use:N\l_netextsize_tl,
1791 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1792 minimum~size=5mm,
1793 ] (necontent) at
1794 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1795 ($(base)+(59mm,81.5mm)$)
1796 }{
1797 ($(base)+(7.5mm,84mm)$)
1798 }
1799 {
1800 \bool_if:NTF\l_back_bool {
1801 \tl_if_empty:NF\l_bne_tl{
1802 \tl_use:N\l_bne_tl
1803 }
1804 } {
1805 \tl_if_empty:NF\l_nepre_tl{
1806 \tl_use:N\l_nepretextsize_tl
1807 \tl_use:N\l_nepre_tl\\[-1mm]
1808 }
1809 \tl_if_empty:NTF\l_ne_tl{
1810 \tl_use:N\l_necontent_tl
1811 }{
1812 \insert_attribute:n \l_ne_tl
1813 }
1814 \tl_if_empty:NF\l_nepost_tl{
1815 \\[-2mm]
1816 \tl_use:N\l_neposttextsize_tl
1817 \tl_use:N\l_nepost_tl
1818 }
1819 }
1820 };
1821 % SOUTH EAST
1822 \node[
1823 anchor=east,
1824 align=right,
1825 font=\tl_use:N\l_setextsize_tl,
1826 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1827 minimum~size=5mm,
1828 ] (secontent) at
1829 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1830 ($(base)+(59mm,5mm)$)
1831 }{
1832 ($(base)+(59mm,84mm)$)
1833 }
1834 {
1835 \bool_if:NTF\l_back_bool {
1836 \tl_if_empty:NF\l_bse_tl{
1837 \tl_use:N\l_bse_tl
1838 }
1839 } {
1840 \tl_if_empty:NF\l_sepre_tl{
1841 \tl_use:N\l_sepretextsize_tl
1842 \tl_use:N\l_sepre_tl\\[-1mm]
1843 }
1844 \tl_if_empty:NTF\l_se_tl{
1845 \tl_use:N\l_secontent_tl
1846 }{
1847 \insert_attribute:n \l_se_tl
1848 }
1849 \tl_if_empty:NF\l_sepost_tl{
1850 \\[-2mm]
1851 \tl_use:N\l_seposttextsize_tl
1852 \tl_use:N\l_sepost_tl
1853 }
1854 }
1855 };
1856
1857 % PLAYTESTING INFORMATION
1858 \bool_if:NF \l_back_bool {
1859 \bool_if:NT \l_playtestinfo_bool {
1860 \node[
1861 anchor=south~west,
1862 rotate=\tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {90}{180},
1863 ] (type) at
1864 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1865 ($(base)+(62.7mm,10mm)$)
1866 }{
1867 ($(base)+(54mm,87.7mm)$)
1868 }{
1869 \tiny
1870 \textcolor{black!70}{
1871 \l_type_tl{} ~ -- ~ \l_subtype_tl{} ~ -- ~ v\l_version_tl{}
1872 }
1873 };
1874 }
1875 }
1876
1877 % CARD TEXT
1878 \bool_if:NF \l_back_bool {
1879 \tl_if_eq:NNF \l_type_tl \const_monsterstring_tl {
1880 \node[
1881 anchor=north~west,
1882 font=\tl_use:N\l_textsize_tl,
1883 text~width=\tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {50mm}{40mm},
1884 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0}{90},
1885 minimum~height=30mm,
1886 ] (text) at
1887 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1888 ($ (base) + (5mm,40mm) $)
1889 }{
1890 ($ (base) + (20mm,5mm) $)
1891 }
1892 {
1893 \tl_use:N \l_text_tl
1894 };
1895
1896 % MORE TEXT
1897 \tl_if_blank:VF \l_moretext_tl {
1898 \tl_trim_spaces:N \l_moretext_tl
1899 \node[
1900 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1901 anchor=south~west,
1902 align=left,
1903 font=\l_moretextsize_tl,
1904 text~width=50mm,
1905 ] (goalline) at
1906 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1907 ($ (base) + (5mm,10mm) $)
1908 }{
1909 ($ (base) + (54mm,5mm) $)
1910 } {
1911 \l_moretext_tl
1912 };
1913 }
1914 }
1915 }
1916
1917 % ART
1918 \bool_if:NF \l_back_bool {
1919 \tl_if_empty:NF\l_art_tl{
1920 \node[
1921 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1922 anchor=center,
1923 ] (backgraphics) at
1924 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1925 ($ (base) + (32mm,57mm) $)
1926 }{
1927 ($ (base) + (35mm,65.5mm) $)
1928 }{
1929 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1930 \includegraphics[
1931 height=31mm,
1932 width=56mm,
1933 keepaspectratio
1934 ]{\tl_use:N\l_art_tl}
1935 }{
1936 \includegraphics[
1937 width=40mm,
1938 height=38mm,
1939 keepaspectratio
1940 ]{\tl_use:N\l_art_tl}
1941 }
1942 };
1943 }
1944 }
1945
1946 % BACK ART
1947 \bool_if:NT \l_back_bool {
1948 \tl_if_empty:NF\l_backart_tl{
1949 \node[
1950 rotate= \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {0} {90} ,
1951 anchor=center,
1952 ] (backgraphics) at
1953 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1954 ($ (base) + (30mm,42.5mm) $)
1955 }{
1956 ($ (base) + (35mm,42.5mm) $)
1957 }{
1958 \tl_if_eq:NNTF \l_orientation_tl \const_portrait_tl {
1959 \includegraphics[
1960 width=56mm,
1961 height=31mm,
1962 keepaspectratio
1963 ]{\tl_use:N\l_backart_tl}
1964 }{
1965 \includegraphics[
1966 height=38mm,
1967 width=40mm,
1968 keepaspectratio
1969 ]{\tl_use:N\l_backart_tl}
1970 }
1971 };
1972 }
1973 }
1974 }
1975
1976 \group_end:
1977 }
1978 % \end{macrocode}
1979 % \end{macro}
1980 % \begin{macro}{\print_cards:n}
1981 % This command takes a list of key-value pairs as specificed
1982 % in the \texttt{cardlist} definition.
1983 % It iterates over all existing cards and calls \cs{typeset_card:nnn} repeatedly,
1984 % inserting page breaks along the way.
1985 % \begin{macrocode}
1986 \cs_new:Nn \print_cards:n {
1987 \keys_set:nn { cardlist } { #1 }
1988
1989 % If desired, sort all cards alphabetically by type, subtype, and card name.
1990 \bool_if:NT \l_sort_bool {
1991 \clist_sort:Nn \g_cards_clist {
1992 \str_compare:nNnTF { ##1 } < { ##2 }
1993 { \sort_return_same: }
1994 { \sort_return_swapped: }
1995 }
1996 \clist_sort:Nn \g_cardbacks_clist {
1997 \str_compare:nNnTF { ##1 } < { ##2 }
1998 { \sort_return_same: }
1999 { \sort_return_swapped: }
2000 }
2001 }
2002
2003 % Loop over all cards, figuring out where to place them.
2004 \int_zero_new:N \l_i_int
2005 \int_set:Nn \l_i_int { 9 } % this is just a better zero
2006 \clist_map_inline:Nn \g_cards_clist {
2007 \int_incr:N \l_i_int
2008 \int_compare:nNnT { \l_i_int } > { 9 } {
2009 \newpage
2010 \pagenumbering{gobble}
2011 \thispagestyle{empty}
2012 \int_set:Nn \l_i_int { 1 }
2013 }
2014 \typeset_card:nnn { ##1 } {} { \int_use:N \l_i_int }
2015 }
2016
2017 % All faces are generated. If back sides are desired, we do those now.
2018 \bool_if:NT\l_generatecardbacks_bool {
2019 \clist_map_inline:Nn \g_cardbacks_clist {
2020 \int_incr:N \l_i_int
2021 \int_compare:nNnT { \l_i_int } > { 9 } {
2022 \newpage
2023 \pagenumbering{gobble}
2024 \thispagestyle{empty}
2025 \int_set:Nn \l_i_int { 1 }
2026 }
2027 \typeset_card:nnn { ##1 } {} { \int_use:N \l_i_int }
2028 }
2029 }
2030
2031 % Debugging message: show the tags.
2032 \clist_sort:Nn \g_existingtags_clist {
2033 \str_compare:nNnTF { ##1 } < { ##2 } { \sort_return_same: } { \sort_return_swapped: }
2034 }
2035 \clist_map_inline:Nn \g_existingtags_clist {
2036 \msg_term:nnxx { cardgame } { tagcount } { ##1 } { \int_use:c { tagcounter @ ##1 } }
2037 }
2038 }
2039 % \end{macrocode}
2040 % \end{macro}
2041
2042 % \begin{macro}{\list_card:n}
2043 % This command produces a single row suitable for including in a tabularray.
2044 % The only way to do this seems to be to build a token list for the entire table
2045 % body and then expand it all at once. See:
2046 % https://tex.stackexchange.com/questions/736567/making-forloop-works-with-tabularray-it-works-with-tabularx
2047 %
2048 % The macro takes as its sole argument an entry from \cs{g_cards_clist}, which is
2049 % of course a token list of precompiled key-value assignments.
2050 %
2051 % We use a global token list variable which is cleared with
2052 % \cs{tl_gclear} inside \cs{list_cards} (the function after
2053 % this one). The reason for this is that we have to wrap the
2054 % code of \cs{list_card} inside a group to prevent card
2055 % attributes from spilling.
2056 % \begin{macrocode}
2057 \tl_new:N\g_cardtblr_tl
2058 \cs_new:Nn \list_card:n {
2059
2060 \group_begin:
2061 \tl_use:c { #1 }
2062
2063 % The tags should always be sorted the same.
2064 \clist_sort:Nn \l_tags_clist {
2065 \str_compare:nNnTF { ##1 } < { ##2 } { \sort_return_same: } { \sort_return_swapped: }
2066 }
2067
2068 % note: because texts can contain newlines, the x expansion
2069 % is necessary here because we need to surround the cell content
2070 % with additional braces.
2071 \tl_gput_right:Nx\g_cardtblr_tl{{\tl_use:N\l_name_tl}}
2072 \tl_gput_right:Nn\g_cardtblr_tl{&}
2073 \tl_gput_right:Nx\g_cardtblr_tl{{\tl_use:N\l_text_tl}}
2074 \tl_gput_right:Nn\g_cardtblr_tl{&}
2075 \tl_gput_right:Nx\g_cardtblr_tl{{\tl_use:N\l_rulings_tl}}
2076 \tl_gput_right:Nn\g_cardtblr_tl{\\}
2077
2078 \group_end:
2079 }
2080 % \end{macrocode}
2081 % \end{macro}
2082
2083 % \begin{macro}{\list_cards:n}
2084 % The internal command to make the table of cards.
2085 % It takes as its argument key-value pairs as defined by \texttt{cardlist}.
2086 % \begin{macrocode}
2087 \cs_new:Nn \list_cards:n {
2088 \keys_set:nn { cardlist } { #1 }
2089 % sort all cards alphabetically by type, subtype, and card name.
2090 \bool_if:NT \l_sort_bool {
2091 \clist_sort:Nn \g_cards_clist {
2092 \str_compare:nNnTF { ##1 } < { ##2 }
2093 { \sort_return_same: }
2094 { \sort_return_swapped: }
2095 }
2096 \clist_sort:Nn \g_cardbacks_clist {
2097 \str_compare:nNnTF { ##1 } < { ##2 }
2098 { \sort_return_same: }
2099 { \sort_return_swapped: }
2100 }
2101 }
2102
2103 \tl_gclear:N\g_cardtblr_tl
2104 \clist_map_inline:Nn \g_cards_clist {
2105 \list_card:n { ##1 }
2106 }
2107
2108 \begin{tblr}[expand=\g_cardtblr_tl]{
2109 colspec = {XXX}, colsep = 8mm, hlines = {2pt, white},
2110 row{odd} = {azure8}, row{even} = {gray8},
2111 row{1} = {2em,azure2,fg=white,font=\bfseries\sffamily},
2112 row{2-Z} = {1em}
2113 }
2114 Name & Text & Rulings\\
2115 \g_cardtblr_tl
2116 \end{tblr}
2117 }
2118 % \end{macrocode}
2119 % \end{macro}
2120
2121 % \subsection{User-Exposed Functions}
2122 % For usage notes, see the user manual.
2123 % \begin{macro}{\Card}
2124 % There is probably a better way to do this than these nested conditionals, but my knowledge of how \LaTeX3 handles arguments and key-value pairs is not deep enough.
2125 % \begin{macrocode}
2126 \NewDocumentCommand\Card{ O{} m m }{
2127 \IfBlankTF{#2}{
2128 \IfBlankTF{#3}{
2129 \card:n{
2130 #1,
2131 }
2132 }{
2133 \card:n{
2134 #1,
2135 text={#3},
2136 }
2137 }
2138 }{
2139 \IfBlankTF{#3}{
2140 \card:n{
2141 #1,
2142 name={#2}
2143 }
2144 }{
2145 \card:n{
2146 #1,
2147 text={#3},
2148 name={#2}
2149 }
2150 }
2151 }
2152 }
2153 % \end{macrocode}
2154 % \end{macro}
2155
2156 % \begin{macro}{\DeclareCardType}
2157 % If no parent type is given, this just creates a wrapper for \cs{Card}.
2158 % To inherit from a parent, we just wrap said parent.
2159 % \begin{macrocode}
2160 \NewDocumentCommand\DeclareCardType{O{} m m}{
2161 \IfBlankTF{#1}{
2162 \expandafter\NewDocumentCommand\csname#2\endcsname{O{} m m}{
2163 \Card[#3,##1]{##2}{##3}
2164 }
2165 }{
2166 \expandafter\NewDocumentCommand\csname#2\endcsname{O{} m m}{
2167 \csname#1\endcsname[#3,##1]{##2}{##3}
2168 }
2169 }
2170 }
2171 % \end{macrocode}
2172 % \end{macro}
2173 % \begin{macro}{\ShowCard}
2174 % If no argument is given, we access the last element of the global card list.
2175 % Otherwise, we reconstruct the name under which the card was saved by uid.
2176 % \begin{macrocode}
2177 \cs_generate_variant:Nn\typeset_card:nnn{onn}
2178 \NewDocumentCommand\ShowCard{ o }{
2179 \IfNoValueTF{#1}{
2180 \typeset_card:nnn{\clist_item:Nn\g_cards_clist{-1}}{}{}
2181 }{
2182 \typeset_card:onn{card_by_uid @ #1}{}{}
2183 }
2184 }
2185 % \end{macrocode}
2186 % \end{macro}
2187 % \begin{macro}{\PrintCards}
2188 % \begin{macrocode}
2189 \NewDocumentCommand\PrintCards{ O{} }{
2190 \print_cards:n{#1}
2191 }
2192 % \end{macrocode}
2193 % \end{macro}
2194 % \begin{macro}{\ListCards}
2195 % \begin{macrocode}
2196 \NewDocumentCommand\ListCards{ O{} }{
2197 \list_cards:n{#1}
2198 }
2199 % \end{macrocode}
2200 % \end{macro}
2201 % \begin{macrocode}
2202 %</package>
2203 % \end{macrocode}
2204 %
2205 % \end{implementation}
2206 %
2207 % \PrintChanges
2208 % \PrintIndex