Debian Codegraph @

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

raw
1 \documentclass{article}
2
3 \usepackage{etex}
4 \usepackage{xifthen}
5 \usepackage[ascii]{inputenc}
6 \usepackage[T1]{fontenc}
7 \usepackage[warn]{textcomp}
8 \usepackage[a4paper, pdftex, margin=1.5in]{geometry}
9 \usepackage{lmodern}
10 \usepackage{typetex}
11 \usepackage{cmdstring}
12 \usepackage{microtype}
13 \usepackage{xcolor}
14 \usepackage{url}
15 \usepackage[bottom,hang]{footmisc}
16 \usepackage[babel]{csquotes}
17 \usepackage[british]{babel}
18 \usepackage{hyperref}
19
20 \setcounter{secnumdepth}{-\maxdimen}
21
22 \newcommand*{\pack}{\textsf}
23
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
26 \newcommand*{\setdate}{}
27 \def \setdate #1/#2/#3#4{%
28 \year = #1
29 \month = #2
30 \day = #3#4
31 }
32
33 \makeatletter
34 \newcommand*{\getfileinfo}[1]{%
35 \def \filename {#1}%
36 \def \@tempb ##1 ##2 ##3\relax ##4\relax {%
37 \def \filedate {##1}%
38 \def \fileversion {##2}%
39 \def \fileinfo {##3}%
40 }%
41 \edef \@tempa {\csname ver@#1\endcsname}%
42 \expandafter \@tempb \@tempa \relax ? ? \relax \relax
43 }
44 \makeatother
45
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48 \title {The \pack{cmdstring} Package}
49 \author {Josselin Noirel}
50 \date {%
51 \getfileinfo{cmdstring.sty}
52 \expandafter \setdate \filedate
53 \today\ (\fileversion)}
54
55 \begin{document}
56
57 \maketitle
58
59 \begin{abstract}
60 For programmers, it is quite common to use the \emph{name} of a~macro
61 (for instance `foo' for the macro \cmd{foo}, in other words, the letters
62 \emph{f}, \emph{o}, and~\emph{o}). For this purpose, it is customary
63 to call \cmd{string} which does this sort of things\dots\ except that it
64 prepends the escape character, controlled by the counter \cmd{escapechar},
65 in front of the name. The traditional ways of getting rid of it, is to
66 set \cmd{escapechar} to~$-1$ (without forgetting to restore the proper
67 value at the end of the process) or to make use of \cmd{@gobble}.
68 The former has the drawback not to be expandible while the second isn't
69 completely reliable. Here we extend the expandible methods to make it
70 reliable.
71 \end{abstract}
72
73 Use this package with
74 %
75 \begin{texcode}
76 \cmd[1]{usepackage}{cmdstring}
77 \end{texcode}
78 or
79 \begin{texcode}
80 \cmd[1]{RequirePackage}{cmdstring}
81 \end{texcode}
82 %
83 Then whatever the value of \cmd{escapechar},
84 \tex{\cmd{cmdstring} {\meta{command}}} will give correct result. For
85 instance `\tex{\cmd{cmdstring}~\cmd{documentclass}}' gives `\cmdstring
86 \documentclass'; `\tex{\cmd{cmdstring}~\cmd{\\}}' gives `\cmdstring \\;
87 `\tex{\cmd{cmdstring}~\cmd{\SPACE}}' gives `\cmdstring \ ', i.e., the
88 command name without the escape~character.
89
90 \newpage
91
92 A~small test can be performed for all representative values of
93 \cmd{escapechar}
94 %
95 \begin{texcode}
96 \cmd{count}255 = -11 \newline
97 \cmd{loop} \cmd{escapechar} = \cmd{count}255 \newline
98 \ \ [\cmd{cmdstring} \cmd{documentclass}] \newline
99 \ \ [\cmd{cmdstring} \cmd{\\}] \newline
100 \ \ [\cmd{cmdstring} \cmd{\ }] \newline
101 \ \ \cmd{ifnum} \cmd{count}255 < 300 \cmd{advance} \cmd{count}255 by 1 \newline
102 \cmd{repeat}
103 \end{texcode}
104 %
105 which gives
106 %
107 \begin{list}{}{}
108 \item \font \tempfonta = ec-lmtt8 at 5pt
109 \tempfonta \baselineskip = 5.5pt \raggedright
110 \count255 = -11
111 \loop
112 \escapechar = \count255
113 [\cmdstring \documentclass]\nobreak\ %
114 [\cmdstring \\]\nobreak\ %
115 [\mbox{\cmdstring \ }]
116 \ifnum \count255 < 300
117 \advance \count255 by 1
118 \repeat \par
119 \end{list}
120
121 \end{document}