Skip to content

Instantly share code, notes, and snippets.

@AdamGagorik
Created October 13, 2015 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamGagorik/bdd05d3aa71c3fae1d32 to your computer and use it in GitHub Desktop.
Save AdamGagorik/bdd05d3aa71c3fae1d32 to your computer and use it in GitHub Desktop.
CreateDocumentParameter
\makeatletter
\DeclareDocumentCommand{\setvalue}{m o m}{%
\IfNoValueTF{#2}{%
% NO INDEX
\expandafter\DeclareDocumentCommand\csname @#1\endcsname{}{#3}%
}{%
% INDEX
\expandafter\DeclareDocumentCommand\csname @#1@#2\endcsname{}{#3}%
}%
}%
%
\DeclareDocumentCommand{\getvalue}{m o}{%
\IfNoValueTF{#2}{%
% NO INDEX
\ifcsname @#1\endcsname%
\csname @#1\endcsname%
\else%
\textcolor{red}{@#1}\xspace%
\fi%
}{%
% INDEX
\ifcsname @#1@#2\endcsname%
\csname @#1@#2\endcsname%
\else%
\textcolor{red}{@#1@#2}%
\fi%
}%
}%
%
\DeclareDocumentCommand{\CreateDocumentParameter}{m o G{undefined}}{%
\IfNoValueTF{#2}{%
% NO INDEX
\setvalue{#1}{#3}%
}{%
% INDEX
\setvalue{#1}[#2]{#3}%
}%
\expandafter\DeclareDocumentCommand\csname #1\endcsname{o g}{%
\IfNoValueTF{##2}{%
\getvalue{#1}[##1]\xspace%
}{%
\setvalue{#1}[##1]{##2}%
}%
}%
}%
\makeatother
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment