summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xkeymask
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-12-27 03:02:10 +0000
committerNorbert Preining <norbert@preining.info>2023-12-27 03:02:10 +0000
commita017c8624fa1cc7d2781f6f4e59e4bd12e7050f1 (patch)
tree297488965603056462abc889dbee46943be8c566 /macros/latex/contrib/xkeymask
parent13571bacab1894379c1ec2ae255c676db2f1664a (diff)
CTAN sync 202312270302
Diffstat (limited to 'macros/latex/contrib/xkeymask')
-rw-r--r--macros/latex/contrib/xkeymask/README36
-rw-r--r--macros/latex/contrib/xkeymask/xkeymask.pdfbin0 -> 128411 bytes
-rw-r--r--macros/latex/contrib/xkeymask/xkeymask.sty109
-rw-r--r--macros/latex/contrib/xkeymask/xkeymask.tex123
4 files changed, 268 insertions, 0 deletions
diff --git a/macros/latex/contrib/xkeymask/README b/macros/latex/contrib/xkeymask/README
new file mode 100644
index 0000000000..2ac9e6099e
--- /dev/null
+++ b/macros/latex/contrib/xkeymask/README
@@ -0,0 +1,36 @@
+xkeymask v1.0
+-------------
+
+This package is an extension of the xkeyval package by Hendri Adriaens that offers additional macros for "masking" certain keys.
+
+See for more information the pdf documentation of this package.
+
+
+Installation
+------------
+
+CTAN:/macros/latex/contrib/xkeymask: official location
+ |
+ |- README : should not be installed
+ |- xkeymask.tex : should not be installed
+ |- xkeymask.pdf : /doc/latex/xkeymask
+ |- xkeymask.sty : /tex/latex/xkeymask
+
+See the documentation of your LaTeX distribution or the TeX Frequently Asked Questions for more information on installing xkeymask into your LaTeX distribution
+(https://texfaq.org/#installing).
+
+
+License
+-------
+
+Copyright (C) 2022-2023 Ramkumar Ramachandra
+
+This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3c of this license or (at your option) any later version. The latest version of this license can be found at https://www.latex-project.org/lppl.txt.
+
+This work has the LPPL maintenance status "maintained".
+
+This Current Maintainer is Ramkumar Ramachandra.
+
+This work consists of the file xkeymask.sty.
+
+The following files constitute the xkeymask bundle and must be distributed as a whole: README, xkeymask.sty, xkeymask.tex, xkeymask.pdf.
diff --git a/macros/latex/contrib/xkeymask/xkeymask.pdf b/macros/latex/contrib/xkeymask/xkeymask.pdf
new file mode 100644
index 0000000000..bd52d93c26
--- /dev/null
+++ b/macros/latex/contrib/xkeymask/xkeymask.pdf
Binary files differ
diff --git a/macros/latex/contrib/xkeymask/xkeymask.sty b/macros/latex/contrib/xkeymask/xkeymask.sty
new file mode 100644
index 0000000000..492e55c5f2
--- /dev/null
+++ b/macros/latex/contrib/xkeymask/xkeymask.sty
@@ -0,0 +1,109 @@
+% xkeymask package by Ramkumar Ramachandra.
+%%
+%% --------------------------------------------
+%% Copyright (C) 2022-2023 Ramkumar Ramachandra
+%% --------------------------------------------
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.3c of this license or (at your option)
+%% any later version. The latest version of this license
+%% can be found at:
+%% https://www.latex-project.org/lppl.txt
+%% and version 1.3c or later is part of all distributions
+%% of LaTeX version 2008/05/04 or later.
+%%
+%% This work has the LPPL maintenance status "maintained".
+%%
+%% This Current Maintainer is Ramkumar Ramachandra.
+%%
+%% This work consists of the file xkeymask.sty.
+%%
+%% The following files constitute the xkeymask bundle and
+%% must be distributed as a whole:
+%% README, xkeymask.sty, xkeymask.tex, xkeymask.pdf.
+%%
+\RequirePackage{kvoptions, xkeyval}
+\ProvidesPackage{xkeymask}[v1.0 An extension of xkeyval with a mask]
+
+% Option processing
+\newif\ifxkeymask@prefix
+\DeclareStringOption{prefix}
+\AddToKeyvalOption*{prefix}{\xkeymask@prefixtrue}
+\ProcessKeyvalOptions*
+
+\ifxkeymask@prefix
+ % We patch xkeyval's \setkeys to use a mask to ignore keys
+ \makeatletter
+ % Our global mask
+ \def\XKM@mask{}
+
+ % First we define \appendmask
+ \long\def\XKM@appendmask[#1]{
+ \XKV@for@o\XKV@fams\XKV@tfam{
+ \xdef\XKM@hdr{\XKV@prefix\XKV@tfam @}
+ \XKV@for@o{#1}\XKV@tempa{
+ % Remove spaces around key name
+ \expandafter\KV@@sp@def\expandafter\XKV@tempa\expandafter{\XKV@tempa}
+ \XKV@addtolist@x\XKM@mask{\XKM@hdr\XKV@tempa}
+ }
+ }
+ }
+ \def\appendmask{\XKV@testopta{\XKV@testoptc\XKM@appendmask}}
+
+ % Query the mask for a key
+ \long\def\XKM@ifinmask[#1]#2#3{
+ \XKV@checksanitizea{#1}\XKV@tempc
+ \XKV@for@o\XKV@fams\XKV@tfam{
+ \XKV@for@o\XKV@tempc\XKV@tempb{
+ \xdef\XKM@hdr{\XKV@prefix\XKV@tfam @}
+ \xdef\XKV@tempd{\XKV@prefix\XKV@tfam @\XKV@tempb}
+ \@expandtwoargs\in@\XKV@tempd\XKM@mask
+ \ifin@
+ #2
+ \else
+ #3
+ \fi
+ }
+ }
+ }
+ \def\ifinmask{\XKV@testopta{\XKV@testoptc\XKM@ifinmask}}
+
+ % A quick way to clear the mask
+ \def\clearmask{\global\let\XKM@mask\@empty}
+
+ % Now we override the definition of \XKV@setkeys
+ \long\def\XKM@setkeys[#1]#2{
+ \XKV@checksanitizea{#2}\XKV@resb
+ \let\XKV@resa\@empty
+ \XKV@for@o\XKV@fams\XKV@tfam{
+ \XKV@for@o\XKV@resb\XKV@tempb{
+ \expandafter\XKV@g@tkeyname\XKV@tempb=\@nil\XKV@tempc
+ % Remove spaces around key name
+ \expandafter\KV@@sp@def\expandafter\XKV@tempc\expandafter{\XKV@tempc}
+ \xdef\XKV@tempd{\XKV@prefix\XKV@tfam @\XKV@tempc}
+ % If \XKV@tempd is in \XKM@mask,
+ % remove the corresponding kv from \XKV@resb
+ \@expandtwoargs\in@\XKV@tempd\XKM@mask
+ \ifin@\else\XKV@addtolist@o\XKV@resa\XKV@tempb\fi
+ }
+ }
+ \ifnum\XKV@depth=\z@\let\XKV@rm\@empty\fi
+ \expandafter\XKV@s@tkeys\expandafter{\XKV@resa}{#1}
+ \let\CurrentOption\@empty
+ }
+
+ % A dispatcher to \XKM@setkeys or \XKV@setkeys
+ \long\def\XKM@setkeys@dispatch{
+ \xdef\XKV@tempa{\xkeymask@prefix @}
+ \ifx\XKV@prefix\XKV@tempa
+ \expandafter\XKM@setkeys
+ \else
+ \expandafter\XKV@setkeys
+ \fi
+ }
+
+ % Finally, override \setkeys itself to call the dispatcher
+ \def\setkeys{\XKV@testopta{\XKV@testoptc\XKM@setkeys@dispatch}}
+ \makeatother
+\fi
diff --git a/macros/latex/contrib/xkeymask/xkeymask.tex b/macros/latex/contrib/xkeymask/xkeymask.tex
new file mode 100644
index 0000000000..4f5e472f80
--- /dev/null
+++ b/macros/latex/contrib/xkeymask/xkeymask.tex
@@ -0,0 +1,123 @@
+% xkeymask package by Ramkumar Ramachandra.
+%%
+%% --------------------------------------------
+%% Copyright (C) 2022-2023 Ramkumar Ramachandra
+%% --------------------------------------------
+%%
+%% This work may be distributed and/or modified under the
+%% conditions of the LaTeX Project Public License, either
+%% version 1.3c of this license or (at your option)
+%% any later version. The latest version of this license
+%% can be found at:
+%% https://www.latex-project.org/lppl.txt
+%% and version 1.3c or later is part of all distributions
+%% of LaTeX version 2008/05/04 or later.
+%%
+%% This work has the LPPL maintenance status "maintained".
+%%
+%% This Current Maintainer is Ramkumar Ramachandra.
+%%
+%% This work consists of the file xkeymask.sty.
+%%
+%% The following files constitute the xkeymask bundle and
+%% must be distributed as a whole:
+%% README, xkeymask.sty, xkeymask.tex, xkeymask.pdf.
+%%
+\documentclass[a4paper]{ltxdoc}
+\usepackage{minted, amsmath, framed}
+\usepackage[margin=0.8in]{geometry}
+\usepackage[prefix=bonak]{xkeymask}
+
+\makeatletter
+\define@cmdkey[bonak]{frame}{D}{(#1)}
+\define@cmdkey[bonak]{layer}{D}{(#1)}
+\define@cmdkey[bonak]{layer}{d}{(#1)}
+\define@cmdkey[bonak]{painting}{D}{(#1)}
+\define@cmdkey[bonak]{painting}{E}{(#1)}
+\define@cmdkey[bonak]{painting}{d}{(#1)}
+\makeatother
+
+\newcommand{\prim}[6]{
+ \ensuremath{\mathsf{{#1}}_{#2}^{#3,#4,#5}}
+ \setkeys*[bonak]{#1}{#6}}
+
+\newcommand{\framep}[5]{\prim{frame}{#1}{#2}{#3}{#4}{#5}}
+\newcommand{\layer}[5]{\prim{layer}{#1}{#2}{#3}{#4}{#5}}
+\newcommand{\painting}[5]{\prim{painting}{#1}{#2}{#3}{#4}{#5}}
+
+\newcommand{\eqnarg}[3]{\ifinmask[bonak]{#1}[#2]{\{#2:#3\}}{(#2:#3)}}
+\begin{document}
+\title{The \texttt{xkeymask} package}
+\author{Ramkumar Ramachandra}
+\maketitle
+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:
+
+\begin{minted}{latex}
+ \documentclass{article}
+ \usepackage{amsmath}
+ \usepackage[prefix=bonak]{xkeymask}
+
+ \makeatletter
+ \define@cmdkey[bonak]{frame}{D}{(#1)}
+ \define@cmdkey[bonak]{layer}{D}{(#1)}
+ \define@cmdkey[bonak]{layer}{d}{(#1)}
+ \define@cmdkey[bonak]{painting}{D}{(#1)}
+ \define@cmdkey[bonak]{painting}{E}{(#1)}
+ \define@cmdkey[bonak]{painting}{d}{(#1)}
+ \makeatother
+
+ \newcommand{\prim}[6]{
+ \ensuremath{\mathsf{{#1}}_{#2}^{#3,#4,#5}}
+ \setkeys*[bonak]{#1}{#6}}
+
+ \newcommand{\framep}[5]{\prim{frame}{#1}{#2}{#3}{#4}{#5}}
+ \newcommand{\layer}[5]{\prim{layer}{#1}{#2}{#3}{#4}{#5}}
+ \newcommand{\painting}[5]{\prim{painting}{#1}{#2}{#3}{#4}{#5}}
+
+ \newcommand{\eqnarg}[3]{\ifinmask[bonak]{#1}[#2]{\{#2:#3\}}{(#2:#3)}}
+
+ \begin{document}
+ With mask:
+ \appendmask[bonak]{layer}[D]
+ \appendmask[bonak]{painting}[D,E]
+ \appendmask[bonak]{cohfiller}[c]
+ \begin{align*}
+ \eqnarg{cohlayer}{d}{\framep{m}{n}{p}{q}{D=D}} \\
+ \eqnarg{cohlayer}{l}{\layer{m}{n}{p}{q}{D=D, d=d}} \\
+ \eqnarg{cohfiller}{c}{\painting{m}{n}{p}{q}{D=D, E=E, d=d}} \\
+ \end{align*}
+ Without mask:
+ \clearmask
+ \begin{align*}
+ \eqnarg{cohlayer}{d}{\framep{m}{n}{p}{q}{D=D}} \\
+ \eqnarg{cohlayer}{l}{\layer{m}{n}{p}{q}{D=D, d=d}} \\
+ \eqnarg{cohfiller}{c}{\painting{m}{n}{p}{q}{D=D, E=E, d=d}} \\
+ \end{align*}
+ \end{document}
+\end{minted}
+
+\newpage
+produces the following output:
+
+\begin{framed}
+ With mask:
+ \appendmask[bonak]{layer}[D]
+ \appendmask[bonak]{painting}[D,E]
+ \appendmask[bonak]{cohfiller}[c]
+ \begin{align*}
+ \eqnarg{cohlayer}{d}{\framep{m}{n}{p}{q}{D=D}} \\
+ \eqnarg{cohlayer}{l}{\layer{m}{n}{p}{q}{D=D, d=d}} \\
+ \eqnarg{cohfiller}{c}{\painting{m}{n}{p}{q}{D=D, E=E, d=d}} \\
+ \end{align*}
+ Without mask:
+ \clearmask
+ \begin{align*}
+ \eqnarg{cohlayer}{d}{\framep{m}{n}{p}{q}{D=D}} \\
+ \eqnarg{cohlayer}{l}{\layer{m}{n}{p}{q}{D=D, d=d}} \\
+ \eqnarg{cohfiller}{c}{\painting{m}{n}{p}{q}{D=D, E=E, d=d}} \\
+ \end{align*}
+\end{framed}
+
+\section*{Full source code listing}
+\inputminted{latex}{xkeymask.sty}
+\end{document}