[NTG-context] the difference between \def and \define

Marco Patzer homerow at lavabit.com
Mon Apr 15 16:07:03 CEST 2013


On 2013–04–15 Tim Li wrote:

> What's the difference between \def and \define?

\define is basically the same as \unexpanded\def. It uses a slightly
different syntax for specifying optional arguments:

  \define[3]\foo{First: #1, Second: #2, Third: #3}
  \unexpanded\def\foo#1#2#3{First: #1, Second: #2, Third: #3}

Furthermore, \define displays a message if the command is already
defined:

  system   > command '\foo' is already defined

However, ConTeXt happily overwrites the existing macro.

> Can I use \define to replace all \def?

There is \defineexpandable, which uses the same syntax as \define,
but it's a simple \def, without \unexpanded which is the closest
replacement.

I don't think named parameters are possible with \define, but maybe
I'm mistaken.

  \def\bar#first#second{First: #first, Second: #second}

For you information, there's also

  \starttexdefinition mycmd #1
    …
  \stoptexdefinition

  \starttexdefinition mycmd $#first #second
    …
  \stoptexdefinition


  \starttexdefinition unexpanded mycmd #first #second
    …
  \stoptexdefinition


Marco
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://www.ntg.nl/pipermail/ntg-context/attachments/20130415/41c68292/attachment.pgp>


More information about the ntg-context mailing list