Git Product home page Git Product logo

namedef's Introduction

namedef

Named parameters in TeX definitions

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

\def\SayHello#1%
  {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:

\def\Say#1#2%
  {#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:

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

then adding another argument before the existing ones is trivial:

\named\def\Say#[greeting]#[subject]%
  {#[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 LaTeX 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

http://www.latex-project.org/lppl.txt

and version 1.3c or later is part of all distributions of LaTeX 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).

namedef's People

Contributors

muzimuzhi avatar phelypeoleinik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

namedef's Issues

Extended \newcommand: why not provided?

Thanks for this very nice, useful and surprisingly only now invented package!

When I started to read its documentation, I thought I was going to ask you an implementation of named \newcommand and then, reading further, came to the "Extended \newcommand" paragraph: nice, but not for a beginner :) Hence: why isn't it provided by namedef?

I also read "... but since a \def is used later with no checking, the behaviour is not exactly the same as you’d get with \newcommand in this regard.": I guess you are talking about a \newcommand that can not be redefined by \newcommand but only by \renewcommand, right? In such a case, would be nice if the implementation I seek would provide this checking :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.