• No results found

Define command and save its name in a container file or macro

N/A
N/A
Protected

Academic year: 2021

Share "Define command and save its name in a container file or macro"

Copied!
5
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

is provided ‘as it is,’ without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose.

MMXI c

The storecmd Package I

Define command and save its name in a container file or macro

Ahmed Musa

Preston, Lancashire, UK

22nd October 2011

Contents

1 Introduction 1

2 Motivation 2

3 Package options 2

4 User commands 2

4.1 Delimited parameters . . . . 3

5 Examples 3

6 Version history 4

Index 5

1 Introduction

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 ‘master macros,’ and the macro that stores the defined commands as the ‘container macro.’ The file that stores the defined commands is the ‘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 \def while the other category has the syntax of L

A

TEX’s \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 (i. e., one of those that have a syntax similar to that of \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 L

A

TEX’s \newcommand can’t be delimited.

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 showsource package option. However, this will track only the commands defined by the master macros of this package. It is safe to assign \newcommand and \renewcommand to

\newsavecmd and \renewsavecmd, respectively. But, for rather obvious reasons, it is not advisable

IThe package is available athttp://www.ctan.org/tex-archive/macros/latex/contrib/storecmd/. This user

(2)

to simply replace the native \global, \long, \protected, \def and \gdef by the master macros of this package

.

2 Motivation

The package was written in response to a post on comp.text.tex for a macro that will define commands and also save the commands being defined in a file or a container macro, e. g., for spelling exceptions on editors that don’t support TEX syntax.

3 Package options

The package options are described in Table 1.

Table 1: Package options

Option Default Meaning

neversave false Never save/store the new command name in the con- tainer file or container macro. The new commands will still be defined.

storerenew false Allow the storage of a command name that has already been stored. This is used by \renewsavecmd.

overwrite false Allow overwrite of an existing container file or con- tainer macro.

storefile containerfile Container file name.

storecmd containermacro Container macro name.

showsource false Show the name of the source file of the command.

verbose 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.

When a boolean option is given without value, its value is assumed to be true.

4 User commands

Three master macros are provided for storing command names:

New macro: \defsavecmd ,\newsavecmd ,\renewsavecmd

1

\defsavecmdhcmdihparami{hdefni}

2

\newsavecmdhcmdi[hnparami][hdefaulti]{hdefni}

3

\renewsavecmdhcmdi[hnparami][hdefaulti]{hdefni}

Here hcmdi is the command name, hparami is the parameter list, hnparami is the number of paramet- ers, hdefaulti is the default value of the first parameter/argument, and hdefni is the replacement text. In \defsavecmd, the hparam i list is as in TEX’s \def; in \newsavecmd and \renewsavecmd,

One reason for this is that, for example, you can’t do\stcglobal\let\x\yor\stcglobal\@tempswatruebecause

\stcprotectedand\stcglobalare tailor made for the commands\defsavecmd,\newsavecmdand\renewsavecmd.

(3)

the hnparami and hdefaulti are as in \newcommand. Both \defsavecmd and \renewsavecmd will overwrite an existing command, but \newsavecmd will not do so.

The commands \defsavecmd, \newsavecmd and \renewsavecmd may be prefixed by \stcglobal and/or \stcprotected to yield global or robust definitions, respectively. For example,

Example: \stcglobal ,\stcprotected

4

\defsavecmd\cmda#1#2{xxx#1#2}

5

\stcglobal\defsavecmd\cmdb#1#2{xxx#1#2}

6

\stcglobal\newsavecmd\cmdc[2]{xxx#1#2}

7

\stcprotected\stcglobal\renewsavecmd*\cmda[2][zz]{\def\y##1{##1xxx}}

4.1 Delimited parameters

The parameters of \defsavecmd can readily be delimited as in the case of TEX’s \def. The parameters of \newsavecmd and \renewsavecmd can be delimited as follows:

Delimited parameters

8

\newsavecmdhcmdi[hparami][hdefaulti](hdelimitersi){hdefni}

9

\renewsavecmdhcmdi[hparami][hdefaulti](hdelimitersi){hdefni}

The hdelimitersi, given here in parenthesis, have the syntax

Delimited parameters

10

1hdelim1i 2hdelim2i ... 9hdelim9i

where hdelim1i is the delimiter for the first parameter, etc. Only the parameters with delimiters are to be specified in hdelimitersi. For example,

Delimited parameters

11

\newsavecmd\cmda[2](1\@nil 2\@mil){xxx#1#2}

12

\newsavecmd\cmdb[9][yy](3\@nil 4\@mil 6\@nnil){xxx#1#2#3...#9}

When the first argument is optional, then it can’t have a delimiter, since the delimiter for that parameter is already ‘[]’.

5 Examples

The following example is available in the accompanying storecmd-example.tex file:

Example: \defsavecmd ,\newsavecmd ,\stcglobal , etc

13

\documentclass{article}

14

% Container commands are also accepted as package options, but in this

15

% case ‘catoptions’ must be loaded before \usepackage{storecmd}.

16

% Eg,

17

% \usepackage{catoptions}

18

% \usepackage[storecmd=\mycommands]{storecmd}

19

%

20

% Uncomment the next line to test what happens when an existing container

(4)

22

% \def\mycommands{}

23

\usepackage[

24

storerenew=true,storecmd=mycommands,storefile=mycommands

25

]{storecmd}

26

\defsavecmd\cmda#1#2{xxx#1#2}

27

\stcglobal\defsavecmd\cmdb#1#2{xxx#1#2}

28

\stcglobal\newsavecmd\cmdc[2]{xxx#1#2}

29

\stcglobal\newsavecmd\cmdd[2][yy]{xxx#1#2}

30

\stcprotected\stcglobal\renewsavecmd*\cmda[2][zz]{\def\y##1{##1xxx}}

31

\stcprotected\newsavecmd\cmde[2](1\@nil 2\@mil){xxx#1#2}

32

\newsavecmd\cmdf[9][yy](3\@nil 9\@mil){xxx#1#2#3...#9}

33

% Try \show\mycommands or see file ‘mycommands.tex’.

34

\begin{document}

35

Blackberry lily.

36

\end{document}

6 Version history

The star sign ( ? ) 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.

Version 0.0.2 [2011/10/22]

User guide completed. . . . ? Version 0.0.1 [2011/10/17]

First public release. . . . . ?

(5)

Index

Index numbers refer to page numbers.

containerfile . . . . 2

containermacro . . . . 2

\defsavecmd . . . . 2, 4 Files . . . . storecmd-example.tex . . . . 3

neversave . . . . 2

\newsavecmd . . . . 2, 4 overwrite . . . . 2

Packages . . . . storecmd . . . . 1

\renewsavecmd . . . . 2, 4 showsource . . . . 2

\stcglobal . . . . 3

\stcprotected . . . . 3

storecmd . . . . 2

storefile . . . . 2

storerenew . . . . 2

verbose . . . . 2

Referenties

GERELATEERDE DOCUMENTEN

• If you prefer to stay with the integral symbols provided by L A TEX(and possi- bly amsmath), but need other symbols from the wasy fonts, load the package with the

After these modifications, when users doesn’t load interchar, your package should behave as before, but when users load interchar package before your package, interchar will takes

The macro \ldf@finish takes care of looking for a configuration file, setting the main language to be switched on at \begin{document} and resetting the category code of @ to

The macro \ldf@finish takes care of looking for a configuration file, setting the main language to be switched on at \begin{document} and resetting the category code of @ to

The file english.dtx 1 defines all the language definition macros for the English language as well as for the American and Australian version of this language.. For the

10 Ιανουαρίου 2020 10 Φεβρουαρίου 2020 10 Μαρτίου 2020 10 Απριλίου 2020 10 Μαΐου 2020 10 Ιουνίου 2020 10 Ιουλίου 2020 10 Αυγούστου 2020 10 Σεπτεμβρίου

The macro \ldf@finish takes care of looking for a configuration file, setting the main language to be switched on at \begin{document} and resetting the category code of @ to

The macro \ldf@finish takes care of looking for a configuration file, setting the main language to be switched on at \begin{document} and resetting the category code of @ to