Is there any difference between defining a variable using \def and using \define, when used without a number inside square brackets, e.g. \def\somecommand{\percent} and \define\somecommand{\percent}? Can I always use \define in places where \def can be used?

  • 6
    From what I see, \define\xyz{...}, when \xyz is already defined issues a warning, but performs the definition anyway. Of course \def doesn't issue any warning.
    – egreg
    Commented May 7, 2012 at 16:51

1 Answer 1


For reference: There are two definitions of \define: The first one in syst-aux.mkiv shows the behavior Egreg mentioned in his comment: if the macro is already defined, it leaves it as it is. (A companion, \redefine allows you to overwrite the current definition of macro regardless of its being in use.) Ironically, this preliminary definition is overwritten without note as soon as the format loads core-sys.mkiv (while \redefine stays around forever).

The actual definition of the \define macro as provided by the user interface does not only check for previously defined control sequences of the same name, but also serves as some kind of short notation for mandatory arguments. It has the scheme

\define [<digit>] <macro> {<definition>}

where the first argument, a digit, specifies the number of arguments the new macro is going to accept. Obviously this can result in shorter definitions. For comparison, the selector

\sevenofnine abcdefghi\par

requires some less typing with the \define macro:


Thus these definitions may result in more readable code -- which is always a good thing when writing TEX.

Unfortunately the \define wrapper takes away a good deal of the expressiveness of plain \def’s. In Context, you will have noticed, macros taking optional arguments are commonplace with respect to the user inteface. For example you simply can’t replace the second \definition in below snippet with an equivalent expression using \define:



That’s because with \define you can’t specify the argument delimiters (here: brackets) necessary for optional arguments, so basically your macros are limited to taking mandatory (braced) arguments only. For the same reason there is no way to define cheap \{start|stop}something environments either:

%%%            ^^^^^^^^ not possible

(The user interface for this is \definestartstop (cf. core-sys.mkiv), anyways.)

Finally, nowadays the most important drawback of \define is that it does not allow for mkvi-style arguments. There is simply no way to refer to a parameter by its name if you can’t assign it one in the first place.

% macros=mkvi


So if you want to do some serious macro writing, you will soon learn to avoid \define, while it is safe for less complex tasks.

  • Thank you for this helpful answer. Point of clarification: when you say "mkiv-style arguments", does that mean named arguments, like #optional in your example? Do you have a reference for where I can read more about those?
    – LarsH
    Commented Nov 13, 2013 at 15:27
  • 2
    @LarsH Yes, MkVI (not MkIV!) macros are the ones with (optional) parameter names. I’m not sure there exists any user-level documentation besides the source: the preprocessor code can be found in luat-mac.lua (for Context) and luatex-preprocessor.lua for Luatex-Plain. Hth. Commented Nov 13, 2013 at 16:24
  • Sorry, my mistake.
    – LarsH
    Commented Nov 13, 2013 at 16:27
  • 2
    I don't know if this was the case at the time of writing this answer but today macros defined using \define are e-TeX protected. To have it expandable one has to use \defineexpandable (or plain \def). Commented Sep 27, 2016 at 20:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .