CTAN Comprehensive TeX Archive Network

Directory macros/generic/namedef



Named parameters in definitions

This package allows you to use names rather than numbers in definitions. Usually a definition would look like:

  {Hello, #1!}

which is usually good enough. However sometimes when writing macros the programmer (I, at least) has a macro with several arguments, and then adding another argument before #1 requires changing all the numbers in the definition:

  {#1, #2!}

which again, is usually fine most of the time. But sometimes the definition is rather long, and has a handful of arguments, so changing the order requires the programmer to change a lot of #1 to #2 in the code, which is tedious, at best.

With namedef you can prefix your definition with \named, then every parameter should be given a name:

  {Hello, #[subject]!}

then adding another argument before the existing ones is trivial:

  {#[greeting], #[subject]!}

and to change the order of the arguments you just swap #[greeting] and #[subject] in the ⟨parameter text⟩ . No other changes required!

Note that this can be (ab)used for writing macros, but it should probably be removed for publishing the code.

This repository contains the source code namedef.dtx and the installation file namedef.ins. To create the package file namedef.sty, run:

tex namedef.ins

and to produce the documentation, run:

pdflatex namedef.ins

Copyright (C) 2019–2020 Phelype Oleinik

This work may be distributed and/or modified under the conditions of the Project Public License, either version 1.3c of this license or (at your option) any later version. The latest version of this license is in


and version 1.3c or later is part of all distributions of version 2005/12/01 or later.

This work is "maintained" (as per the LPPL maintenance status) by Phelype Oleinik.

Please send bug reports or feature requests at the project repository: https://github.com/PhelypeOleinik/namedef or by e-mail (contact info in the source file).

Download the contents of this package in one zip archive (630.2k).

namedef – definitions with named parameters

This package provides a prefix \named to be used in definitions so that parameters can be identified by their name rather than by number, giving parameters a semantic rather than syntactic meaning, making it easy to understand long definitions.

A usual definition reads:

      \def\SayHello#1{Hello, #1!}

but with namedef you can replace #1 by, say, #[person]:

      \named\def\SayHello#[person]{Hello, #[person]!}

and \named will figure out the numbering of the parameters for you.

Bug trackerhttps://github.com/PhelypeOleinik/namedef/issues
Version1.0 2020-06-20
LicensesThe Project Public License 1.3c
Copyright2019–2020 Phelype Oleinik
MaintainerPhelype Oleinik
Contained inTeX Live as namedef
MiKTeX as namedef
TopicsDefining Macro
Generic Macros
Experimental 3
Guest Book Sitemap Contact Contact Author