Debian Codegraph @

texmf-dist/doc/latex/xkeymask/xkeymask.tex

raw
1 % xkeymask package by Ramkumar Ramachandra.
2 %%
3 %% --------------------------------------------
4 %% Copyright (C) 2022-2023 Ramkumar Ramachandra
5 %% --------------------------------------------
6 %%
7 %% This work may be distributed and/or modified under the
8 %% conditions of the LaTeX Project Public License, either
9 %% version 1.3c of this license or (at your option)
10 %% any later version. The latest version of this license
11 %% can be found at:
12 %% https://www.latex-project.org/lppl.txt
13 %% and version 1.3c or later is part of all distributions
14 %% of LaTeX version 2008/05/04 or later.
15 %%
16 %% This work has the LPPL maintenance status "maintained".
17 %%
18 %% This Current Maintainer is Ramkumar Ramachandra.
19 %%
20 %% This work consists of the file xkeymask.sty.
21 %%
22 %% The following files constitute the xkeymask bundle and
23 %% must be distributed as a whole:
24 %% README, xkeymask.sty, xkeymask.tex, xkeymask.pdf.
25 %%
26 \documentclass[a4paper]{ltxdoc}
27 \usepackage{minted, amsmath, framed}
28 \usepackage[margin=0.8in]{geometry}
29 \usepackage[prefix=bonak]{xkeymask}
30
31 \makeatletter
32 \define@cmdkey[bonak]{frame}{D}{(#1)}
33 \define@cmdkey[bonak]{layer}{D}{(#1)}
34 \define@cmdkey[bonak]{layer}{d}{(#1)}
35 \define@cmdkey[bonak]{painting}{D}{(#1)}
36 \define@cmdkey[bonak]{painting}{E}{(#1)}
37 \define@cmdkey[bonak]{painting}{d}{(#1)}
38 \makeatother
39
40 \newcommand{\prim}[6]{
41 \ensuremath{\mathsf{{#1}}_{#2}^{#3,#4,#5}}
42 \setkeys*[bonak]{#1}{#6}}
43
44 \newcommand{\framep}[5]{\prim{frame}{#1}{#2}{#3}{#4}{#5}}
45 \newcommand{\layer}[5]{\prim{layer}{#1}{#2}{#3}{#4}{#5}}
46 \newcommand{\painting}[5]{\prim{painting}{#1}{#2}{#3}{#4}{#5}}
47
48 \newcommand{\eqnarg}[3]{\ifinmask[bonak]{#1}[#2]{\{#2:#3\}}{(#2:#3)}}
49 \begin{document}
50 \title{The \texttt{xkeymask} package}
51 \author{Ramkumar Ramachandra}
52 \maketitle
53 This package is an extension of the \texttt{xkeyval} package by Hendri Adriaens that offers macros for ``masking'' certain keys, so that they are not used in certain places. The package was originally written for the purposes of the \href{https://github.com/artagnon/bonak}{bonak} project, for hiding certain keys in certain places, and has been released for a wider audience. The idea is that one first imports the package with a desired ``prefix'' in the document preamble, and then creates masks use at certain points in the document. The mask can also be queried or cleared at some later point. The main user interface is provided by the |\appendmask|, |\clearmask|, and |\ifinmask| commands. The following example:
54
55 \begin{minted}{latex}
56 \documentclass{article}
57 \usepackage{amsmath}
58 \usepackage[prefix=bonak]{xkeymask}
59
60 \makeatletter
61 \define@cmdkey[bonak]{frame}{D}{(#1)}
62 \define@cmdkey[bonak]{layer}{D}{(#1)}
63 \define@cmdkey[bonak]{layer}{d}{(#1)}
64 \define@cmdkey[bonak]{painting}{D}{(#1)}
65 \define@cmdkey[bonak]{painting}{E}{(#1)}
66 \define@cmdkey[bonak]{painting}{d}{(#1)}
67 \makeatother
68
69 \newcommand{\prim}[6]{
70 \ensuremath{\mathsf{{#1}}_{#2}^{#3,#4,#5}}
71 \setkeys*[bonak]{#1}{#6}}
72
73 \newcommand{\framep}[5]{\prim{frame}{#1}{#2}{#3}{#4}{#5}}
74 \newcommand{\layer}[5]{\prim{layer}{#1}{#2}{#3}{#4}{#5}}
75 \newcommand{\painting}[5]{\prim{painting}{#1}{#2}{#3}{#4}{#5}}
76
77 \newcommand{\eqnarg}[3]{\ifinmask[bonak]{#1}[#2]{\{#2:#3\}}{(#2:#3)}}
78
79 \begin{document}
80 With mask:
81 \appendmask[bonak]{layer}[D]
82 \appendmask[bonak]{painting}[D,E]
83 \appendmask[bonak]{cohfiller}[c]
84 \begin{align*}
85 \eqnarg{cohlayer}{d}{\framep{m}{n}{p}{q}{D=D}} \\
86 \eqnarg{cohlayer}{l}{\layer{m}{n}{p}{q}{D=D, d=d}} \\
87 \eqnarg{cohfiller}{c}{\painting{m}{n}{p}{q}{D=D, E=E, d=d}} \\
88 \end{align*}
89 Without mask:
90 \clearmask
91 \begin{align*}
92 \eqnarg{cohlayer}{d}{\framep{m}{n}{p}{q}{D=D}} \\
93 \eqnarg{cohlayer}{l}{\layer{m}{n}{p}{q}{D=D, d=d}} \\
94 \eqnarg{cohfiller}{c}{\painting{m}{n}{p}{q}{D=D, E=E, d=d}} \\
95 \end{align*}
96 \end{document}
97 \end{minted}
98
99 \newpage
100 produces the following output:
101
102 \begin{framed}
103 With mask:
104 \appendmask[bonak]{layer}[D]
105 \appendmask[bonak]{painting}[D,E]
106 \appendmask[bonak]{cohfiller}[c]
107 \begin{align*}
108 \eqnarg{cohlayer}{d}{\framep{m}{n}{p}{q}{D=D}} \\
109 \eqnarg{cohlayer}{l}{\layer{m}{n}{p}{q}{D=D, d=d}} \\
110 \eqnarg{cohfiller}{c}{\painting{m}{n}{p}{q}{D=D, E=E, d=d}} \\
111 \end{align*}
112 Without mask:
113 \clearmask
114 \begin{align*}
115 \eqnarg{cohlayer}{d}{\framep{m}{n}{p}{q}{D=D}} \\
116 \eqnarg{cohlayer}{l}{\layer{m}{n}{p}{q}{D=D, d=d}} \\
117 \eqnarg{cohfiller}{c}{\painting{m}{n}{p}{q}{D=D, E=E, d=d}} \\
118 \end{align*}
119 \end{framed}
120
121 \section*{Full source code listing}
122 \inputminted{latex}{xkeymask.sty}
123 \end{document}