| 1 |
\documentclass{article} |
| 2 |
|
| 3 |
\usepackage{etex} |
| 4 |
\usepackage[ascii]{inputenc} |
| 5 |
\usepackage[T1]{fontenc} |
| 6 |
\usepackage[warn]{textcomp} |
| 7 |
\usepackage[a4paper, pdftex, margin=1.5in]{geometry} |
| 8 |
\usepackage{lmodern} |
| 9 |
\usepackage{typetex} |
| 10 |
\usepackage{xnewcommand} |
| 11 |
\usepackage{microtype} |
| 12 |
\usepackage{xcolor} |
| 13 |
\usepackage{url} |
| 14 |
\usepackage[bottom,hang]{footmisc} |
| 15 |
\usepackage[babel]{csquotes} |
| 16 |
\usepackage[british]{babel} |
| 17 |
\usepackage{hyperref} |
| 18 |
|
| 19 |
\setcounter{secnumdepth}{-\maxdimen} |
| 20 |
|
| 21 |
\newcommand*{\setdate}{} |
| 22 |
\def \setdate #1/#2/#3#4{% |
| 23 |
\year = #1 |
| 24 |
\month = #2 |
| 25 |
\day = #3#4 |
| 26 |
} |
| 27 |
|
| 28 |
\makeatletter |
| 29 |
\newcommand*{\getfileinfo}[1]{% |
| 30 |
\def \filename {#1}% |
| 31 |
\def \@tempb ##1 ##2 ##3\relax ##4\relax {% |
| 32 |
\def \filedate {##1}% |
| 33 |
\def \fileversion {##2}% |
| 34 |
\def \fileinfo {##3}% |
| 35 |
}% |
| 36 |
\edef \@tempa {\csname ver@#1\endcsname}% |
| 37 |
\expandafter \@tempb \@tempa \relax ? ? \relax \relax |
| 38 |
} |
| 39 |
\makeatother |
| 40 |
|
| 41 |
\newcommand*{\pack}{\textsf} |
| 42 |
|
| 43 |
\title {The \pack{xnewcommand} package} |
| 44 |
\author {Josselin Noirel\\\url{http://www.jnoirel.fr/}} |
| 45 |
\date {% |
| 46 |
\getfileinfo{xnewcommand.sty}% |
| 47 |
\expandafter \setdate \filedate |
| 48 |
\today\ (\fileversion)} |
| 49 |
|
| 50 |
\begin{document} |
| 51 |
|
| 52 |
\maketitle |
| 53 |
|
| 54 |
\tableofcontents |
| 55 |
|
| 56 |
\begin{abstract} |
| 57 |
For most purposes, the features of \cmd{newcommand} suffice. |
| 58 |
Nonetheless, \cmd{newcommand} lacks some interesting features like |
| 59 |
the ability to make definition global or to use the \cmd{protected} |
| 60 |
prefix supplied by \eTeX. This---surprisingly small---package makes |
| 61 |
possible to pass an~optional argument \cmd{newcommand} so that is |
| 62 |
becomes possible to use the \cmd{global} and \cmd{protected} |
| 63 |
prefixes. |
| 64 |
\end{abstract} |
| 65 |
|
| 66 |
\section{Usage} |
| 67 |
|
| 68 |
Load the package with |
| 69 |
% |
| 70 |
\begin{texcode} |
| 71 |
\cmd[1]{usepackage}{xnewcommand} |
| 72 |
\end{texcode} |
| 73 |
% |
| 74 |
Then \cmd{newcommand} can take an additional optional argument: |
| 75 |
% |
| 76 |
\begin{texcode} |
| 77 |
\cmd[syntax,5]{newcommand}[prefix]{command}[number][default]{definition} |
| 78 |
\end{texcode} |
| 79 |
% |
| 80 |
where \meta{prefix} can be any valid prefix or combination of them: |
| 81 |
% |
| 82 |
\begin{description} |
| 83 |
\item [\cmd{long}] The command will accept `long arguments', in |
| 84 |
other words, its arguments may contain ends |
| 85 |
of paragraph (explicit \cmd{par} or empty |
| 86 |
lines); |
| 87 |
|
| 88 |
\item [\cmd{global}] The command is defined globally, in other |
| 89 |
words, the definition won't be confined to |
| 90 |
the current group; |
| 91 |
|
| 92 |
\item [\cmd{protected}] The command will be robust in moving |
| 93 |
arguments and won't undergo systematic |
| 94 |
expansion at the beginning of tabular cells; |
| 95 |
|
| 96 |
\item [\cmd{outer}] Makes the macro \cmd{outer} (not very useful, |
| 97 |
but included for the sake of completeness). |
| 98 |
\end{description} |
| 99 |
|
| 100 |
The same syntax applies to the commands \cmd{renewcommand}, |
| 101 |
\cmd{DeclareRobustCommand}, \cmd{newenvironment} and |
| 102 |
\cmd{renewenvironment}. |
| 103 |
|
| 104 |
\section{Remarks} |
| 105 |
|
| 106 |
It should not break anything. The normal syntax is preserved: |
| 107 |
% |
| 108 |
\begin{texcode} |
| 109 |
\cmd[syntax,2]{newcommand}{command}{definition} |
| 110 |
\end{texcode} |
| 111 |
% |
| 112 |
is equivalent to |
| 113 |
% |
| 114 |
\begin{texcode} |
| 115 |
\cmd[3]{newcommand}[\cmd{long}]{\<command\>}{\<definition\>} |
| 116 |
\end{texcode} |
| 117 |
% |
| 118 |
and |
| 119 |
% |
| 120 |
\begin{texcode} |
| 121 |
\cmd[syntax,2]{newcommand}*{command}{definition} |
| 122 |
\end{texcode} |
| 123 |
% |
| 124 |
is equivalent to |
| 125 |
% |
| 126 |
\begin{texcode} |
| 127 |
\cmd[3]{newcommand}[]{\<command\>}{\<definition\>} |
| 128 |
\end{texcode} |
| 129 |
% |
| 130 |
Any macro that uses \cmd{star@or@long} will inheritate the features |
| 131 |
described above. |
| 132 |
|
| 133 |
\section{Examples} |
| 134 |
|
| 135 |
Global definition: |
| 136 |
% |
| 137 |
\begin{texcode} |
| 138 |
\cmd{newcommand}[\cmd{global}]\marg{command}\marg{definition} |
| 139 |
\end{texcode} |
| 140 |
% |
| 141 |
Protected definition: |
| 142 |
% |
| 143 |
\begin{texcode} |
| 144 |
\cmd{newcommand}[\cmd{protected}]\marg{command}\marg{definition} |
| 145 |
\end{texcode} |
| 146 |
% |
| 147 |
Combination of both: |
| 148 |
% |
| 149 |
\begin{texcode} |
| 150 |
\cmd{newcommand}[\cmd{global} \cmd{protected}]\marg{command}\marg{definition} |
| 151 |
\end{texcode} |
| 152 |
|
| 153 |
\end{document} |