Difference between revisions of "Command/define"

From Wiki
Jump to navigation Jump to search
m (Add note that this is mkiv code)
(Update: \define does, in fact, happily redefine stuff)
Line 21: Line 21:
  
 
== Description ==  
 
== Description ==  
<code>\define</code> is like the TeX primitive <code>\def</code>: it defines a new TeX macro. Unlike <code>\def</code>, '''<code>\define</code> can never redefine''' an already defined command.
+
<code>\define</code> is like the TeX primitive <code>\def</code>: it defines a new TeX macro. Unlike <code>\def</code>, <code>\define</code> will print an error to the log file if the new definition overwrites an existing command.
  
 
The optional bracketed argument denotes the number of parameters you can give  
 
The optional bracketed argument denotes the number of parameters you can give  

Revision as of 16:22, 27 September 2012

\define

Syntax

\define[...]\command{...}
[...] number
{...} text


Description

\define is like the TeX primitive \def: it defines a new TeX macro. Unlike \def, \define will print an error to the log file if the new definition overwrites an existing command.

The optional bracketed argument denotes the number of parameters you can give to your command. "text" is the result when the macro gets expanded.

Pitfalls

\define does not use \long, that means in MkII multiple paragraphs (e.g. through \par or \endgraf) inside arguments will not work.

The name of the new command may not include numbers.

Example

% wiki mode=mkiv

\define\hello{Good morning}

% You may not use numbers
% \define[1]\mp3{The ID3 Tag of the MP3 file is: #1}
% but this will work:
\define[1]\mpThree{The ID3 Tag of the MP3 file is: #1}

% You can use non-ASCII characters in MkIV, but not in MkII.
% This example is compiled using mkiv.
\define[1]\KüFst{Küstenfunkstelle, #1!}

\starttext
\hello

\KüFst{12}

\stoptext

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: