| 1 |
# namedef |
| 2 |
Named parameters in TeX definitions |
| 3 |
|
| 4 |
This package allows you to use names rather than numbers in TeX |
| 5 |
definitions. Usually a definition would look like: |
| 6 |
```tex |
| 7 |
\def\SayHello#1% |
| 8 |
{Hello, #1!} |
| 9 |
``` |
| 10 |
which is usually good enough. However sometimes when writing macros the |
| 11 |
programmer (I, at least) has a macro with several arguments, and then |
| 12 |
adding another argument before `#1` requires changing all the numbers |
| 13 |
in the definition: |
| 14 |
```tex |
| 15 |
\def\Say#1#2% |
| 16 |
{#1, #2!} |
| 17 |
``` |
| 18 |
which again, is usually fine most of the time. But sometimes the |
| 19 |
definition is rather long, and has a handful of arguments, so changing |
| 20 |
the order requires the programmer to change a lot of `#1` to `#2` in the |
| 21 |
code, which is tedious, at best. |
| 22 |
|
| 23 |
With `namedef` you can prefix your definition with `\named`, then every |
| 24 |
parameter should be given a name: |
| 25 |
```tex |
| 26 |
\named\def\SayHello#[subject]% |
| 27 |
{Hello, #[subject]!} |
| 28 |
``` |
| 29 |
then adding another argument before the existing ones is trivial: |
| 30 |
```tex |
| 31 |
\named\def\Say#[greeting]#[subject]% |
| 32 |
{#[greeting], #[subject]!} |
| 33 |
``` |
| 34 |
and to change the order of the arguments you just swap `#[greeting]` and |
| 35 |
`#[subject]` in the <code>⟨parameter text⟩</code>. No |
| 36 |
other changes required! |
| 37 |
|
| 38 |
Note that this can be (ab)used for writing macros, but it should |
| 39 |
probably be removed for publishing the code. |
| 40 |
|
| 41 |
--- |
| 42 |
|
| 43 |
This repository contains the source code `namedef.dtx` and the |
| 44 |
installation file `namedef.ins`. To create the package file |
| 45 |
`namedef.sty`, run: |
| 46 |
``` |
| 47 |
tex namedef.ins |
| 48 |
``` |
| 49 |
and to produce the documentation, run: |
| 50 |
``` |
| 51 |
pdflatex namedef.ins |
| 52 |
``` |
| 53 |
|
| 54 |
--- |
| 55 |
|
| 56 |
Copyright (C) 2019--2020 Phelype Oleinik |
| 57 |
|
| 58 |
This work may be distributed and/or modified under the conditions of |
| 59 |
the LaTeX Project Public License, either version 1.3c of this license |
| 60 |
or (at your option) any later version. The latest version of this |
| 61 |
license is in |
| 62 |
|
| 63 |
http://www.latex-project.org/lppl.txt |
| 64 |
|
| 65 |
and version 1.3c or later is part of all distributions of LaTeX |
| 66 |
version 2005/12/01 or later. |
| 67 |
|
| 68 |
This work is "maintained" (as per the LPPL maintenance status) |
| 69 |
by Phelype Oleinik. |
| 70 |
|
| 71 |
Please send bug reports or feature requests at the project repository: |
| 72 |
https://github.com/PhelypeOleinik/namedef |
| 73 |
or by e-mail (contact info in the source file). |