diff options
author | Karl Berry <karl@freefriends.org> | 2016-04-20 21:52:58 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-04-20 21:52:58 +0000 |
commit | fe2d50f648a774c6f405d54b77ab8e5c2f37e4b6 (patch) | |
tree | 550832aeb2c5d7d63af10cb7770e0055e3056fae /Master/texmf-dist | |
parent | 658a820e8fce6fffa034e89505a59080716852ff (diff) |
multidef (20apr16)
git-svn-id: svn://tug.org/texlive/trunk@40637 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/multidef/README | 14 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/multidef/multidef-test.tex | 37 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/multidef/multidef.pdf | bin | 192897 -> 195375 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/multidef/multidef.dtx | 134 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/multidef/multidef.ins | 2 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/multidef/multidef.sty | 94 |
6 files changed, 229 insertions, 52 deletions
diff --git a/Master/texmf-dist/doc/latex/multidef/README b/Master/texmf-dist/doc/latex/multidef/README index dc667092475..645fdd0442a 100644 --- a/Master/texmf-dist/doc/latex/multidef/README +++ b/Master/texmf-dist/doc/latex/multidef/README @@ -1,6 +1,6 @@ - multidef.sty -- quickly define a bunch of similar commands + multidef.sty -- quickly define a series of similar commands (Nicolas Markey -- <multidef(at)markey.fr>) - version 1.00 -- 2016/03/14 + version 1.10 -- 2016/04/20 Package multidef provides a quick and easy way of declaring several @@ -21,6 +21,14 @@ and version 1.3 or later is part of all distributions of LaTeX version This work has the LPPL maintenance status `maintained'. The Current Maintainer of this work is Nicolas Markey. +---------------------------------------------------------------------- - +Changelog: + - v1.00 (2016/03/14): initial release + - v1.01 (2016/03/15): + * now uses trimspaces.sty if available + * [BUG] added \global for list of redefined macros + - v1.10 (2016/04/20): + * corrected wrong example in doc (thanks to Pedro Sanchez Terraf) + * added option 'robust' for defining robust commands diff --git a/Master/texmf-dist/doc/latex/multidef/multidef-test.tex b/Master/texmf-dist/doc/latex/multidef/multidef-test.tex new file mode 100644 index 00000000000..0161d8d6225 --- /dev/null +++ b/Master/texmf-dist/doc/latex/multidef/multidef-test.tex @@ -0,0 +1,37 @@ +\documentclass{article} +\usepackage{xspace} +\usepackage{dsfont} +\usepackage{multidef} + + +%% basic definition +\multidef[p=cal]{\ensuremath{\mathcal{#1}}}{A-Z} + +%% example with noerr, nowarn +\multidef[noerr,nowarn,suffix=name]{#1}{contents->Table des mati\`eres, + ref->R\'ef\'erences, + part->Partie} + +%% with one argument +\multidef[arg=1]{\ensuremath{\mathsf{#1}(##1)}}{first,last} + +%% global + robust +\makeatletter +\bgroup +\multidef[noerr,global,p=bb,args=1,robust] + {\@ifnextchar+{\ensuremath{\mathds{#1}^+}\@gobble} + {\ensuremath{\mathds{#1}}}} + {A,B,C,H,N,Q,R,T,Z, + Z , Z ,one->1} +\egroup + + +\begin{document} + +\section{\protect\(\bbZ\protect\) would fail if not robust} + +\calT\ should write $\mathcal T$ + +\first a should write $\mathsf{first}(a)$ + +\end{document} diff --git a/Master/texmf-dist/doc/latex/multidef/multidef.pdf b/Master/texmf-dist/doc/latex/multidef/multidef.pdf Binary files differindex ff6d04aa09e..fe32edcaf7c 100644 --- a/Master/texmf-dist/doc/latex/multidef/multidef.pdf +++ b/Master/texmf-dist/doc/latex/multidef/multidef.pdf diff --git a/Master/texmf-dist/source/latex/multidef/multidef.dtx b/Master/texmf-dist/source/latex/multidef/multidef.dtx index 11c80e93628..6f849e1cc9a 100644 --- a/Master/texmf-dist/source/latex/multidef/multidef.dtx +++ b/Master/texmf-dist/source/latex/multidef/multidef.dtx @@ -4,7 +4,7 @@ %<*driver> \documentclass{ltxdoc} \usepackage{doc} -\usepackage{multidef} +\usepackage{multidef-save} \usepackage{dsfont} \def\sty#1{\textsf{#1.sty}} @@ -14,14 +14,21 @@ %%%\AtBeginDocument{\CodelineIndex\EnableCrossrefs} %%%\AtEndDocument{\PrintIndex} \begin{document} - \def\docdate{2016/03/14} - \def\fileversion{1.00} + \def\docdate{2016/04/20} + \def\filedate{2016/04/20} + \def\fileversion{1.10} \DocInput{multidef.dtx} \end{document} %</driver> % % \fi -% \CheckSum{206} +% +% +% \changes{1.00}{2016/03/14}{Initial release} +% \changes{1.10}{2016/04/20}{Added def. of robust commands} +% +% +% \CheckSum{329} %% \CharacterTable %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z @@ -87,7 +94,7 @@ % calligraphic-font letters in math mode. With \pack{multidef} I now % simply write %\begin{verbatim} -%\multidef{\ensuremath{\mathcal{#1}}}{A-Z} +%\multidef[prefix=cal]{\ensuremath{\mathcal{#1}}}{A-Z} %\end{verbatim} % \multidef[prefix=cal]{\ensuremath{\mathcal{#1}}}{A-Z} % and write \cs{calG} to write~\calG. Here \texttt{A-Z} is a shorthand for the @@ -131,6 +138,34 @@ % % \section{The code} % +% \begin{macrocode} +\NeedsTeXFormat{LaTeX2e}[1994/12/01] +\ProvidesPackage{multidef}[2016/04/20 v1.10 definition of multiple commands] +% \end{macrocode} +% +% We begin with importing package \pack{trimspaces}, or to define its command +% \cs{trim@spaces}, in order to trim unwanted spaces in arguments: +%\begin{macro}{\trim@spaces} +% \begin{macrocode} +\IfFileExists{trimspaces.sty} + {\RequirePackage{trimspaces}} + {} +%% borrowing code from trimspaces, if package was not found. +\catcode`\Q=3 +\@ifundefined{trim@spaces} + {\PackageWarning{multidef} + {Package trimspaces.sty not found.^^JDefining \noexpand\trim@spaces myself} + \newcommand\trim@spaces[1]{% + \romannumeral-`\q\trim@trim@\noexpand#1Q Q% + } + \long\def\trim@trim@#1 Q{\trim@trim@@#1Q} + \long\def\trim@trim@@#1Q#2{#1}} + {} +\catcode`\Q=11 +%% +% \end{macrocode} +%\end{macro} +% % We use \pack{xkeyval} to handle package and command options. The package has % two options, \ttt{noerr} and~\ttt{nowarn}. The former tells % \pack{multidef} not to raise an error when redefining a command (default to @@ -169,13 +204,15 @@ % \item \ttt{arg} (and the equivalent \ttt{args}) can be used to define the % number of arguments of the series of commands to be defined. % \item \ttt{long} and \ttt{global} can be used to define \cs{long} and -% \cs{global} macros. +% \cs{global} macros, +% \item \ttt{robust} can be used to define robust commands. % \end{itemize} %\begin{macro}{prefix} %\begin{macro}{suffix} %\begin{macro}{arg} %\begin{macro}{long} %\begin{macro}{global} +%\begin{macro}{robust} % \begin{macrocode} \define@key{mdef}{prefix}{\def\@mdprefix{#1}} \define@key{mdef}{p}{\def\@mdprefix{#1}} @@ -183,15 +220,17 @@ \define@key{mdef}{s}{\def\@mdsuffix{#1}} \define@key{mdef}{arg}{\def\@mdargs{#1}} \define@key{mdef}{args}{\def\@mdargs{#1}} -\define@boolkeys{mdef}{long,global}[true] +\define@boolkeys{mdef}{long,global,robust}[true] \presetkeys{mdef} - {p=,s=,prefix=,suffix=,long=false,global=false,arg=0,args=0}{} + {p=,s=,prefix=,suffix=,long=false,global=false,robust=false, + arg=0,args=0}{} % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} %\end{macro} %\end{macro} +%\end{macro} % % % We define shorthands for defining series of commands indexed by letters of @@ -230,19 +269,19 @@ % the remainder of the list. %\begin{macro}{\@mdef} % \begin{macrocode} -\def\@mdef #1,#2\@end{\expandafter\def\expandafter\@arg - \expandafter{\romannumeral-\expandafter`\expandafter\.#1}% - \ifx\@arg\@mdef@az +\def\@mdef #1,#2\@end{% + \edef\@mdef@arg{\trim@spaces{#1}}% + \ifx\@mdef@arg\@mdef@az \expandafter\@mdef \@mdef@alphabet,\@end \else - \ifx\@arg\@mdef@AZ + \ifx\@mdef@arg\@mdef@AZ \expandafter\@mdef \@mdef@Alphabet,\@end \else - \expandafter\@@mdef\@arg->->->\@end + \expandafter\@@mdef\@mdef@arg->->->\@end \fi \fi - \def\@arg{#2}% - \ifx\@arg\@empty\else\@mdef #2\@end\fi} + \def\@mdef@arg{#2}% + \ifx\@mdef@arg\@empty\else\@mdef #2\@end\fi} % \end{macrocode} %\end{macro} % @@ -262,10 +301,12 @@ \def\@@mdef#1->#2->#3\@end{% \@ifundefined{\@mdprefix#1\@mdsuffix} {\@@@mdef{#1}{#2}} - {\edef\@mdef@redef{\the\@mdef@redeftok\@mdef@comma - \@backslashchar\@mdprefix#1\@mdsuffix} - \def\@mdef@comma{, } - \@mdef@redeftok=\expandafter{\@mdef@redef} + {\ifKV@mdef@nowarn\else + \edef\@mdef@redef{\the\@mdef@redeftok\@mdef@comma + \@backslashchar\@mdprefix#1\@mdsuffix} + \def\@mdef@comma{, } + \global\@mdef@redeftok=\expandafter{\@mdef@redef} + \fi \ifKV@mdef@noerr \@@@mdef{#1}{#2}% \ifKV@mdef@nowarn\else @@ -294,28 +335,65 @@ %\end{macro} %\end{macro} % -% Finally, \cs{@@@mdef} calls \cs{@mdef@def} with the appropriate -% arguments. This is where the commands are really defined. The definition -% uses \cs{@yargd@f}, following the definition of \cs{newcommand} in \LaTeX. +% Finally, \cs{@@@mdef} calls \cs{@mdef@def} or \cs{@mdef@robdef} (if option +% \ttt{robust} was passed) with the appropriate arguments. This is where the +% commands are really defined. The definitions of \cs{@mdef@def} and +% \cs{@mdef@robdef} use \cs{@yargd@f}, following the definition of +% \cs{newcommand} and \cs{DeclareRobustCommand} in \LaTeX. %\begin{macro}{\@@@mdef} %\begin{macro}{\@mdef@def} +%\begin{macro}{\@mdef@robdef} % \begin{macrocode} \def\@@@mdef#1#2{\def\@arg@{#2}% \ifx\@arg@\@empty - \@mdef@def{#1}{#1}% + \ifKV@mdef@robust + \expandafter\def\expandafter\@mdef@cmdname + \expandafter{\csname\@mdprefix#1\@mdsuffix\endcsname}% + \expandafter\@mdef@robdef\@mdef@cmdname{#1}% + \else + \@mdef@def{#1}{#1}% + \fi \else - \@mdef@def{#1}{#2}% + \ifKV@mdef@robust + \expandafter\def\expandafter\@mdef@cmdname + \expandafter{\csname\@mdprefix#1\@mdsuffix\endcsname} + \expandafter\@mdef@robdef\@mdef@cmdname{#2}% + \else + \@mdef@def{#1}{#2}% + \fi \fi} \def\@mdef@def#1#2{% - \let\reserved@b\@gobble - \ifKV@mdef@global\let\@mdglobal\global\else\let\@mdglobal\relax\fi - \ifKV@mdef@long\let\@mdlong\long\else\let\@mdlong\relax\fi - \def\l@ngrel@x{\@mdlong\@mdglobal} + \let\reserved@b\@gobble + \ifKV@mdef@global\let\@mdglobal\global\else\let\@mdglobal\relax\fi + \ifKV@mdef@long\let\@mdlong\long\else\let\@mdlong\relax\fi + \def\l@ngrel@x{\@mdlong\@mdglobal} \expandafter\expandafter\expandafter\@yargd@f\expandafter\@mdargs\csname \@mdprefix#1\@mdsuffix\expandafter\endcsname\expandafter{\@mdef@com{#2}} } +\def\@mdef@robdef#1#2{% + \edef\reserved@a{\string#1}% + \def\reserved@b{#1}% + \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}% + \global\edef#1{% + \ifx\reserved@a\reserved@b + \noexpand\x@protect + \noexpand#1% + \fi + \noexpand\protect + \expandafter\noexpand\csname + \expandafter\@gobble\string#1 \endcsname + }% + \let\reserved@b\@gobble + \ifKV@mdef@global\let\@mdglobal\global\else\let\@mdglobal\relax\fi + \ifKV@mdef@long\let\@mdlong\long\else\let\@mdlong\relax\fi + \def\l@ngrel@x{\@mdlong\@mdglobal} + \expandafter\expandafter\expandafter\@yargd@f\expandafter\@mdargs\csname + \expandafter\@gobble\string#1 \expandafter\endcsname + \expandafter{\@mdef@com{#2}} +} % \end{macrocode} %\end{macro} %\end{macro} +%\end{macro} % \Finale \endinput diff --git a/Master/texmf-dist/source/latex/multidef/multidef.ins b/Master/texmf-dist/source/latex/multidef/multidef.ins index 6c63ae9f4f1..65c26ff701e 100644 --- a/Master/texmf-dist/source/latex/multidef/multidef.ins +++ b/Master/texmf-dist/source/latex/multidef/multidef.ins @@ -1,6 +1,6 @@ %\NeedsTeXFormat{LaTeX2e}[1996/12/01] \input docstrip -\def\filedate{2016/03/14} +\def\filedate{2016/04/20} \let\MetaPrefix\DoubleperCent \preamble diff --git a/Master/texmf-dist/tex/latex/multidef/multidef.sty b/Master/texmf-dist/tex/latex/multidef/multidef.sty index 6d33e63c9eb..13b554c5703 100644 --- a/Master/texmf-dist/tex/latex/multidef/multidef.sty +++ b/Master/texmf-dist/tex/latex/multidef/multidef.sty @@ -6,7 +6,7 @@ %% %% multidef.dtx (with options: `package') %% -%% (c) 2016/03/14 Nicolas Markey <multidef at markey dot fr> +%% (c) 2016/04/20 Nicolas Markey <multidef at markey dot fr> %% %% This work may be distributed and/or modified under the conditions of %% the LaTeX Project Public License, either version 1.3 of this license @@ -37,6 +37,24 @@ %% Grave accent \` Left brace \{ Vertical bar \| %% Right brace \} Tilde \~} %% +\NeedsTeXFormat{LaTeX2e}[1994/12/01] +\ProvidesPackage{multidef}[2016/04/20 v1.10 definition of multiple commands] +\IfFileExists{trimspaces.sty} + {\RequirePackage{trimspaces}} + {} +%% borrowing code from trimspaces, if package was not found. +\catcode`\Q=3 +\@ifundefined{trim@spaces} + {\PackageWarning{multidef} + {Package trimspaces.sty not found.^^JDefining \noexpand\trim@spaces myself} + \newcommand\trim@spaces[1]{% + \romannumeral-`\q\trim@trim@\noexpand#1Q Q% + } + \long\def\trim@trim@#1 Q{\trim@trim@@#1Q} + \long\def\trim@trim@@#1Q#2{#1}} + {} +\catcode`\Q=11 +%% \RequirePackage{xkeyval} \define@boolkeys{mdef}{noerr,nowarn}[true] \DeclareOptionX{noerr}[true]{\setkeys{mdef}{noerr=#1}} @@ -59,9 +77,10 @@ \define@key{mdef}{s}{\def\@mdsuffix{#1}} \define@key{mdef}{arg}{\def\@mdargs{#1}} \define@key{mdef}{args}{\def\@mdargs{#1}} -\define@boolkeys{mdef}{long,global}[true] +\define@boolkeys{mdef}{long,global,robust}[true] \presetkeys{mdef} - {p=,s=,prefix=,suffix=,long=false,global=false,arg=0,args=0}{} + {p=,s=,prefix=,suffix=,long=false,global=false,robust=false, + arg=0,args=0}{} \def\@mdef@az{a-z} \def\@mdef@AZ{A-Z} \def\@mdef@alphabet{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z} @@ -70,28 +89,30 @@ \setkeys{mdef}{#1}% \def\@mdef@com##1{#2}% \@mdef#3,\@end} -\def\@mdef #1,#2\@end{\expandafter\def\expandafter\@arg - \expandafter{\romannumeral-\expandafter`\expandafter\.#1}% - \ifx\@arg\@mdef@az +\def\@mdef #1,#2\@end{% + \edef\@mdef@arg{\trim@spaces{#1}}% + \ifx\@mdef@arg\@mdef@az \expandafter\@mdef \@mdef@alphabet,\@end \else - \ifx\@arg\@mdef@AZ + \ifx\@mdef@arg\@mdef@AZ \expandafter\@mdef \@mdef@Alphabet,\@end \else - \expandafter\@@mdef\@arg->->->\@end + \expandafter\@@mdef\@mdef@arg->->->\@end \fi \fi - \def\@arg{#2}% - \ifx\@arg\@empty\else\@mdef #2\@end\fi} + \def\@mdef@arg{#2}% + \ifx\@mdef@arg\@empty\else\@mdef #2\@end\fi} \newtoks\@mdef@redeftok \def\@mdef@comma{} \def\@@mdef#1->#2->#3\@end{% \@ifundefined{\@mdprefix#1\@mdsuffix} {\@@@mdef{#1}{#2}} - {\edef\@mdef@redef{\the\@mdef@redeftok\@mdef@comma - \@backslashchar\@mdprefix#1\@mdsuffix} - \def\@mdef@comma{, } - \@mdef@redeftok=\expandafter{\@mdef@redef} + {\ifKV@mdef@nowarn\else + \edef\@mdef@redef{\the\@mdef@redeftok\@mdef@comma + \@backslashchar\@mdprefix#1\@mdsuffix} + \def\@mdef@comma{, } + \global\@mdef@redeftok=\expandafter{\@mdef@redef} + \fi \ifKV@mdef@noerr \@@@mdef{#1}{#2}% \ifKV@mdef@nowarn\else @@ -116,18 +137,51 @@ redefined commands (\the\@mdef@redeftok)}}} \def\@@@mdef#1#2{\def\@arg@{#2}% \ifx\@arg@\@empty - \@mdef@def{#1}{#1}% + \ifKV@mdef@robust + \expandafter\def\expandafter\@mdef@cmdname + \expandafter{\csname\@mdprefix#1\@mdsuffix\endcsname}% + \expandafter\@mdef@robdef\@mdef@cmdname{#1}% + \else + \@mdef@def{#1}{#1}% + \fi \else - \@mdef@def{#1}{#2}% + \ifKV@mdef@robust + \expandafter\def\expandafter\@mdef@cmdname + \expandafter{\csname\@mdprefix#1\@mdsuffix\endcsname} + \expandafter\@mdef@robdef\@mdef@cmdname{#2}% + \else + \@mdef@def{#1}{#2}% + \fi \fi} \def\@mdef@def#1#2{% - \let\reserved@b\@gobble - \ifKV@mdef@global\let\@mdglobal\global\else\let\@mdglobal\relax\fi - \ifKV@mdef@long\let\@mdlong\long\else\let\@mdlong\relax\fi - \def\l@ngrel@x{\@mdlong\@mdglobal} + \let\reserved@b\@gobble + \ifKV@mdef@global\let\@mdglobal\global\else\let\@mdglobal\relax\fi + \ifKV@mdef@long\let\@mdlong\long\else\let\@mdlong\relax\fi + \def\l@ngrel@x{\@mdlong\@mdglobal} \expandafter\expandafter\expandafter\@yargd@f\expandafter\@mdargs\csname \@mdprefix#1\@mdsuffix\expandafter\endcsname\expandafter{\@mdef@com{#2}} } +\def\@mdef@robdef#1#2{% + \edef\reserved@a{\string#1}% + \def\reserved@b{#1}% + \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}% + \global\edef#1{% + \ifx\reserved@a\reserved@b + \noexpand\x@protect + \noexpand#1% + \fi + \noexpand\protect + \expandafter\noexpand\csname + \expandafter\@gobble\string#1 \endcsname + }% + \let\reserved@b\@gobble + \ifKV@mdef@global\let\@mdglobal\global\else\let\@mdglobal\relax\fi + \ifKV@mdef@long\let\@mdlong\long\else\let\@mdlong\relax\fi + \def\l@ngrel@x{\@mdlong\@mdglobal} + \expandafter\expandafter\expandafter\@yargd@f\expandafter\@mdargs\csname + \expandafter\@gobble\string#1 \expandafter\endcsname + \expandafter{\@mdef@com{#2}} +} %% %% %% End of file `multidef.sty'. |