Debian Codegraph @

texmf-dist/doc/latex/storecmd/storecmd-guide.tex

raw
1 \documentclass[
2 use-a4-paper,
3 use-10pt-font,
4 final-version,
5 use-UK-English,
6 fancy-section-headings,
7 frame-section-numbers,
8 para-abstract-style,
9 input-config-file,
10 no-hyperref-messages,
11 wrapquote
12 ]{amltxdoc}
13
14 \makeatletter
15 \hfuzz1pt
16 \makeindex
17 \usepackage{makeidx}
18 \subtitlefont{\bf\sf}
19
20 \useshortdoccmds
21
22 \begin{document}
23
24 \begin{frontmatter}
25 \title{The \texttt{\color{blue}storecmd} Package\titleref{t1}}
26 \titlenotes[t1]{%
27 The package is available at \url{\titleurltext}.
28 This user manual corresponds to version~0.0.2 of the package.
29 }
30 \subtitle{Define command and save its name in a container file or macro}
31 \titleurl{http://www.ctan.org/tex-archive/macros/latex/contrib/storecmd/}
32 \author{Ahmed Musa\Email{[email protected]}\\Preston, Lancashire, UK}
33
34 \end{frontmatter}
35
36
37 \hrule height.5pt depth.5pt width\textwidth
38 \vskip 1ex plus 1pt minus 1pt
39 \begingroup
40 \hypersetup{linkcolor=blue}\tableofcontents
41 \endgroup
42 \hrule height.5pt depth.5pt width\textwidth
43
44
45 \docsection(sec:intro){Introduction}
46
47 This package provides macros for command definition that save the name of the command being defined in a file or a macro container. For ease of reference, we refer to macros for command definition as \quoted{master macros}, and the macro that stores the defined commands as the \quoted{container macro}. The file that stores the defined commands is the \quoted{container file}. In this package there are two categories of master macros for command definition: one category has a syntax similar to that of \tex's \hx{\def} while the other category has the syntax of \latex's \hx{\newcommand}. Only one master macro is available in the first category. Naturally, commands defined by the master macro of the first category can have their parameters delimited in the usual way. When the user uses one of the master macros for command definition from the second category (\ie, one of those that have a syntax similar to that of \hx{\newcommand}), some or all of the parameters of the defined command can be delimited, as desired by the command author. Normally, parameters of commands defined by \latex's \hx{\newcommand} can't be delimited.
48
49 The package can also be used as a debugging tool, or at least as a command location tool: namely, to store the names of defined commands and the sources in which they are defined. This can be realized by using the \fx{showsource} package option. However, this will track only the commands defined by the master macros of this package. It is safe to assign \hhx'{\newcommand, \renewcommand} to \ffx'{\newsavecmd, \renewsavecmd}, respectively. But, for rather obvious reasons, it is not advisable to simply replace the native \hhx'{\global,\long,\protected,\def,\gdef} by the master macros of this package\footnote{One reason for this is that, for example, you can't do \ftfx{\stcglobal\let\x\y} or \ftfx{\stcglobal\@tempswatrue} because \ftffx'{\stcprotected,\stcglobal} are tailor made for the commands \ftffx'{\defsavecmd, \newsavecmd, \renewsavecmd}.}.
50
51
52 \docsection{Motivation}
53
54 The package was written in response to a post on \ltshref{https://groups.google.com/forum/
55 #!topic/comp.text.tex/o14P2e83o4A}{comp.text.tex} for a macro that will define commands and also save the commands being defined in a file or a container macro, \eg, for spelling exceptions on editors that don't support \tex syntax.
56
57
58 \docsection{Package options}
59
60 The package options are described in \sref{tab:pkgoptions}.
61
62 \extrarowheight=2pt
63 \arrayrulecolor{yellow}
64 \begin{tabularx}{\linewidth}{|m{3cm}|m{2.5cm}|X|}
65 \caption{Package options\label{tab:pkgoptions}}\\\hline
66 \rowcolor{pink}
67 \bfseries Option&\bfseries Default&\bfseries Meaning\\\hline
68 \endfirsthead
69 \hline
70 \multicolumn{3}{|l|}{\emph{Continued from last page}}\\\hline
71 \bfseries Option&\bfseries Default&\bfseries Meaning\\\hline
72 \endhead
73 \multicolumn{3}{|r|}{\emph{Continued on next page}}\\\hline
74 \endfoot
75 \hline
76 \endlastfoot
77 \fxi{neversave} & \texttt{false} & Never save/store the new command name in the container file or container macro. The new commands will still be defined.\\\hline
78 \fxi{storerenew} & \texttt{false} & Allow the storage of a command name that has already been stored. This is used by \fx{\renewsavecmd}.\\\hline
79 \fxi{overwrite} & \texttt{false} & Allow overwrite of an existing container file or container macro.\\\hline
80 \fxi{storefile} & \fxi{containerfile} & Container file name.\\\hline
81 \fxi{storecmd} & \fxi{containermacro} & Container macro name.\\\hline
82 \fxi{showsource} & \texttt{false} & Show the name of the source file of the command.\\\hline
83 \fxi{verbose} & \texttt{true} & Give extra information in the transcript file. Turn this option off if you don't like or need such information, but only minimal information is actually logged.\\\hline
84 \end{tabularx}
85
86 When a boolean option is given without value, its value is assumed to be \hx{true}.
87
88
89 \docsection{User commands}
90
91 Three master macros are provided for storing command names:
92
93 \start{newmacro}[\defsavecmd,\newsavecmd,\renewsavecmd]
94 \defsavecmd|A(cmd)|A(param){|A(defn)}
95 \newsavecmd|A(cmd)[|A(nparam)][|A(default)]{|A(defn)}
96 \renewsavecmd|A(cmd)[|A(nparam)][|A(default)]{|A(defn)}
97 \finish{newmacro}
98 \fxi*{\defsavecmd,\newsavecmd,\renewsavecmd}
99
100 Here \ang{cmd} is the command name, \ang{param} is the parameter list, \ang{nparam} is the number of parameters, \ang{default} is the default value of the first parameter/argument, and \ang{defn} is the replacement text. In \fx{\defsavecmd}, the \ang{param} list is as in \tex's \hx{\def}; in \ffx'{\newsavecmd, \renewsavecmd}, the \ang{nparam} and \ang{default} are as in \hx{\newcommand}. Both \ffx'{\defsavecmd, \renewsavecmd} will overwrite an existing command, but \fx{\newsavecmd} will not do so.
101
102 The commands \ffx'{\defsavecmd, \newsavecmd, \renewsavecmd} may be prefixed by \fx{\stcglobal} and/or \fx{\stcprotected} to yield global or robust definitions, respectively. For example,
103
104 \start{example}[\stcglobal,\stcprotected]
105 \defsavecmd\cmda#1#2{xxx#1#2}
106 |R(\stcglobal)\defsavecmd\cmdb#1#2{xxx#1#2}
107 |R(\stcglobal)\newsavecmd\cmdc[2]{xxx#1#2}
108 |R(\stcprotected\stcglobal)\renewsavecmd*\cmda[2][zz]{\def\y##1{##1xxx}}
109 \finish{example}
110 \fxi*{\stcglobal,\stcprotected}
111
112
113 \docsubsection{Delimited parameters}
114
115 The parameters of \fx{\defsavecmd} can readily be delimited as in the case of \tex's \hx{\def}. The parameters of \ffx'{\newsavecmd, \renewsavecmd} can be delimited as follows:
116
117 \start'{newmacro}[Delimited parameters]
118 \newsavecmd|A(cmd)[|A(param)][|A(default)]|(|A(delimiters)|){|A(defn)}
119 \renewsavecmd|A(cmd)[|A(param)][|A(default)]|(|A(delimiters)|){|A(defn)}
120 \finish{newmacro}
121
122 The \ang{delimiters}, given here in parenthesis, have the syntax
123
124 \start'{newmacro}[Delimited parameters]
125 1|A(delim1) 2|A(delim2) ... 9|A(delim9)
126 \finish{newmacro}
127
128 where \ang{delim1} is the delimiter for the first parameter, etc. Only the parameters with delimiters are to be specified in \ang{delimiters}. For example,
129
130 \start'{example}[Delimited parameters]
131 \newsavecmd\cmda[2]|(1\@nil 2\@mil|){xxx#1#2}
132 \newsavecmd\cmdb[9][yy]|(3\@nil 4\@mil 6\@nnil|){xxx#1#2#3...#9}
133 \finish{example}
134
135 When the first argument is optional, then it can't have a delimiter, since the delimiter for that parameter is already \quotedfx{[]}.
136
137
138 \docsection{Examples}
139
140 The following example is available in the accompanying \file{storecmd-example} file:
141
142 \start{example}[\defsavecmd,\newsavecmd,\stcglobal, etc]
143 \documentclass{article}
144 % Container commands are also accepted as package options, but in this
145 % case `catoptions' must be loaded before \usepackage{storecmd}.
146 % Eg,
147 % \usepackage{catoptions}
148 % \usepackage[storecmd=\mycommands]{storecmd}
149 %
150 % Uncomment the next line to test what happens when an existing container
151 % command is being refilled:
152 % \def\mycommands{}
153
154 \usepackage[
155 storerenew=true,storecmd=mycommands,storefile=mycommands
156 ]{storecmd}
157
158 \defsavecmd\cmda#1#2{xxx#1#2}
159 \stcglobal\defsavecmd\cmdb#1#2{xxx#1#2}
160 \stcglobal\newsavecmd\cmdc[2]{xxx#1#2}
161 \stcglobal\newsavecmd\cmdd[2][yy]{xxx#1#2}
162 \stcprotected\stcglobal\renewsavecmd*\cmda[2][zz]{\def\y##1{##1xxx}}
163 \stcprotected\newsavecmd\cmde[2]|(1\@nil 2\@mil|){xxx#1#2}
164 \newsavecmd\cmdf[9][yy]|(3\@nil 9\@mil|){xxx#1#2#3...#9}
165
166 % Try \show\mycommands or see file `mycommands.tex'.
167
168 \begin{document}
169 Blackberry lily.
170 \end{document}
171 \finish{example}
172 \fxi*{\defsavecmd,\newsavecmd,\renewsavecmd}
173
174
175 \docsection(sec:version-hist){Version history}
176
177 The \stsign on the right-hand side of the following lists means the subject features in the package but is not reflected anywhere in this user guide.
178
179 \begin{versionhist}
180 \begin{version}{0.0.2}{2011/10/22}
181 \item User guide completed.\vsecref*
182 \end{version}
183 \begin{version}{0.0.1}{2011/10/17}
184 \item First public release.\vsecref*
185 \end{version}
186 \end{versionhist}
187
188 \newpage
189 \ltsindexpreamble{Index numbers refer to page numbers.}
190 \ltsindexpreambleformat{\centering}
191 \ltsindexcolumns\tw@
192
193 \printindex
194
195 \end{document}