-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathprint-definition.tex
40 lines (37 loc) · 922 Bytes
/
print-definition.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
\RequirePackage{fvextra}
\RequirePackage{xcolor}
\newcommand{\printDef}[1]{%
\begingroup
\ttfamily
% output command
\noindent\hspace*{-\parindent}\color{blue}%
\textbackslash\Verb*|#1|%
\normalcolor\par
% output definition of \cs{#1}
\toString{#1}%
\list{}{\leftmargin=2em\topsep=0pt\parsep=0pt\partopsep=0pt}%
\item[]\expandafter\meaning\csname \csname l_tmpa_tl\endcsname\endcsname
\endlist
\endgroup
\vskip\topsep
}
\newcommand{\printAndRunCode}[1]{%
\addvspace{2\topsep}%
\begingroup
\ttfamily
\noindent\hspace*{-\parindent}\color{orange}%
\Verb*|#1|%
\normalcolor\par
\endgroup
#1%
}
% add \string in front of each token in #1
% based on https://tex.stackexchange.com/a/44444
\ExplSyntaxOn
\cs_new:Npn \toString #1
{
\tl_set:Nn \l_tmpa_tl {#1}
\regex_replace_all:nnN { . } { \c{string} \0 } \l_tmpa_tl
\tl_set:Nx \l_tmpa_tl { \l_tmpa_tl }
}
\ExplSyntaxOff