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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
\documentclass{article}
\usepackage{etex}
\usepackage[ascii]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[warn]{textcomp}
\usepackage[a4paper, pdftex, margin=1.5in]{geometry}
\usepackage{lmodern}
\usepackage{typetex}
\usepackage{xnewcommand}
\usepackage{microtype}
\usepackage{xcolor}
\usepackage{url}
\usepackage[bottom,hang]{footmisc}
\usepackage[babel]{csquotes}
\usepackage[british]{babel}
\usepackage{hyperref}
\setcounter{secnumdepth}{-\maxdimen}
\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
\newcommand*{\pack}{\textsf}
\title {The \pack{xnewcommand} package}
\author {Josselin Noirel\\\url{http://www.jnoirel.fr/}}
\date {%
\getfileinfo{xnewcommand.sty}%
\expandafter \setdate \filedate
\today\ (\fileversion)}
\begin{document}
\maketitle
\tableofcontents
\begin{abstract}
For most purposes, the features of \cmd{newcommand} suffice.
Nonetheless, \cmd{newcommand} lacks some interesting features like
the ability to make definition global or to use the \cmd{protected}
prefix supplied by \eTeX. This---surprisingly small---package makes
possible to pass an~optional argument \cmd{newcommand} so that is
becomes possible to use the \cmd{global} and \cmd{protected}
prefixes.
\end{abstract}
\section{Usage}
Load the package with
%
\begin{texcode}
\cmd[1]{usepackage}{xnewcommand}
\end{texcode}
%
Then \cmd{newcommand} can take an additional optional argument:
%
\begin{texcode}
\cmd[syntax,5]{newcommand}[prefix]{command}[number][default]{definition}
\end{texcode}
%
where \meta{prefix} can be any valid prefix or combination of them:
%
\begin{description}
\item [\cmd{long}] The command will accept `long arguments', in
other words, its arguments may contain ends
of paragraph (explicit \cmd{par} or empty
lines);
\item [\cmd{global}] The command is defined globally, in other
words, the definition won't be confined to
the current group;
\item [\cmd{protected}] The command will be robust in moving
arguments and won't undergo systematic
expansion at the beginning of tabular cells;
\item [\cmd{outer}] Makes the macro \cmd{outer} (not very useful,
but included for the sake of completeness).
\end{description}
The same syntax applies to the commands \cmd{renewcommand},
\cmd{DeclareRobustCommand}, \cmd{newenvironment} and
\cmd{renewenvironment}.
\section{Remarks}
It should not break anything. The normal syntax is preserved:
%
\begin{texcode}
\cmd[syntax,2]{newcommand}{command}{definition}
\end{texcode}
%
is equivalent to
%
\begin{texcode}
\cmd[3]{newcommand}[\cmd{long}]{\<command\>}{\<definition\>}
\end{texcode}
%
and
%
\begin{texcode}
\cmd[syntax,2]{newcommand}*{command}{definition}
\end{texcode}
%
is equivalent to
%
\begin{texcode}
\cmd[3]{newcommand}[]{\<command\>}{\<definition\>}
\end{texcode}
%
Any macro that uses \cmd{star@or@long} will inheritate the features
described above.
\section{Examples}
Global definition:
%
\begin{texcode}
\cmd{newcommand}[\cmd{global}]\marg{command}\marg{definition}
\end{texcode}
%
Protected definition:
%
\begin{texcode}
\cmd{newcommand}[\cmd{protected}]\marg{command}\marg{definition}
\end{texcode}
%
Combination of both:
%
\begin{texcode}
\cmd{newcommand}[\cmd{global} \cmd{protected}]\marg{command}\marg{definition}
\end{texcode}
\end{document}
|