summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/cmdstring/cmdstring.tex
blob: 767c6fe1bb8545902007b17d314aac5f0f96ff58 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
\documentclass{article}

\usepackage{etex}
\usepackage{xifthen}
\usepackage[ascii]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[warn]{textcomp}
\usepackage[a4paper, pdftex, margin=1.5in]{geometry}
\usepackage{lmodern}
\usepackage{typetex}
\usepackage{cmdstring}
\usepackage{microtype}
\usepackage{xcolor}
\usepackage{url}
\usepackage[bottom,hang]{footmisc}
\usepackage[babel]{csquotes}
\usepackage[british]{babel}
\usepackage{hyperref}

\setcounter{secnumdepth}{-\maxdimen}

\newcommand*{\pack}{\textsf}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*{\setdate}{}
\def \setdate #1/#2/#3#4{%
  \year  = #1
  \month = #2
  \day   = #3#4
}

\makeatletter
\newcommand*{\getfileinfo}[1]{%
  \def \filename {#1}%
  \def \@tempb ##1 ##2 ##3\relax ##4\relax {%
    \def \filedate    {##1}%
    \def \fileversion {##2}%
    \def \fileinfo    {##3}%
  }%
  \edef \@tempa {\csname ver@#1\endcsname}%
  \expandafter \@tempb \@tempa \relax ? ? \relax \relax
}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title  {The \pack{cmdstring} Package}
\author {Josselin Noirel}
\date   {%
  \getfileinfo{cmdstring.sty}
  \expandafter \setdate \filedate
  \today\ (\fileversion)}

\begin{document}

\maketitle

\begin{abstract}
  For programmers, it is quite common to use the \emph{name} of a~macro
  (for instance `foo' for the macro \cmd{foo}, in other words, the letters
  \emph{f}, \emph{o}, and~\emph{o}).  For this purpose, it is customary
  to call \cmd{string} which does this sort of things\dots\ except that it
  prepends the escape character, controlled by the counter \cmd{escapechar},
  in front of the name.  The traditional ways of getting rid of it, is to
  set \cmd{escapechar} to~$-1$ (without forgetting to restore the proper
  value at the end of the process) or to make use of \cmd{@gobble}.
  The former has the drawback not to be expandible while the second isn't
  completely reliable.  Here we extend the expandible methods to make it
  reliable.
\end{abstract}

Use this package with
%
\begin{texcode}
\cmd[1]{usepackage}{cmdstring}
\end{texcode}
or
\begin{texcode}
\cmd[1]{RequirePackage}{cmdstring}
\end{texcode}
%
Then whatever the value of \cmd{escapechar},
\tex{\cmd{cmdstring} {\meta{command}}} will give correct result.  For
instance `\tex{\cmd{cmdstring}~\cmd{documentclass}}' gives `\cmdstring
\documentclass'; `\tex{\cmd{cmdstring}~\cmd{\\}}' gives `\cmdstring \\;
`\tex{\cmd{cmdstring}~\cmd{\SPACE}}' gives `\cmdstring \ ', i.e., the
command name without the escape~character.

\newpage

A~small test can be performed for all representative values of
\cmd{escapechar}
%
\begin{texcode}
\cmd{count}255 = -11 \newline
\cmd{loop} \cmd{escapechar} = \cmd{count}255 \newline
\ \ [\cmd{cmdstring} \cmd{documentclass}]    \newline
\ \ [\cmd{cmdstring} \cmd{\\}]               \newline
\ \ [\cmd{cmdstring} \cmd{\ }]               \newline
\ \ \cmd{ifnum} \cmd{count}255 < 300 \cmd{advance} \cmd{count}255 by 1 \newline
\cmd{repeat}
\end{texcode}
%
which gives
%
\begin{list}{}{}
\item \font \tempfonta = ec-lmtt8 at 5pt
            \tempfonta \baselineskip = 5.5pt \raggedright
\count255 = -11
\loop
  \escapechar = \count255
  [\cmdstring \documentclass]\nobreak\ %
  [\cmdstring \\]\nobreak\ %
  [\mbox{\cmdstring \ }]
  \ifnum \count255 < 300
  \advance \count255 by 1
\repeat \par
\end{list}

\end{document}