Difference between revisions of "Command/define"

From Wiki
Jump to navigation Jump to search
 
(24 intermediate revisions by 5 users not shown)
Line 3: Line 3:
 
|attributes=
 
|attributes=
 
}}
 
}}
 +
 +
== [[Help:Reference|Syntax]] (autogenerated) ==
 +
<syntax>define</syntax>
  
 
== [[Help:Reference|Syntax]] ==
 
== [[Help:Reference|Syntax]] ==
Line 15: Line 18:
 
   <tr valign="top" class="third">
 
   <tr valign="top" class="third">
 
     <td class="cmd">{...}</td>
 
     <td class="cmd">{...}</td>
     <td><i>text</i> </td>
+
     <td>''macro contents''</td>
 
   </tr>
 
   </tr>
 
</table>
 
</table>
Line 21: Line 24:
  
 
== Description ==  
 
== Description ==  
<tt>\define</tt> is like the TeX primitive <tt>\def</tt>: it defines a new TeX macro. Unlike
 
<tt>\def</tt>, it will not allow you to redefine an already defined command.
 
  
The optional (bracketed) argument denotes the number of parameters you can give  
+
* In MkII, {{cmd|define}} is like the TeX primitive {{tex|def}}: it defines a new TeX macro.
to your command. text is the result when the macro gets expanded. <tt>\define</tt> is
+
* In MkIV {{cmd|define}} is like {{tex|unexpanded}}{{tex|def}}
not <tt>\long</tt>, that means you cannot use <tt>\par</tt> inside the arguments.
+
: and \defineexpandable is like {{tex|def}}.
 +
The optional bracketed argument denotes the number of parameters you can give  
 +
to your command. ''macro contents'' is the result when the macro gets expanded.  
 +
 
 +
== Pitfalls ==
 +
<code>\define</code> does not use {{tex|long}}; that means that in MkII
 +
multiple paragraphs (e.g. through {{tex|par}} or <tt>\endgraf</tt>)
 +
inside arguments will not work.
 +
 
 +
The name of the new command may not include numbers.
  
== comment ==
+
== Example ==
<pre>
 
is there any bonus when I use \define instead of \def? -PG
 
</pre>
 
  
 +
<context mode=mkiv source="yes">
 +
% wiki mode=mkiv
  
 +
\define\hello{Good morning}
  
== Example ==
+
% 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}
  
<context source="yes">
+
% You can use non-ASCII characters in MkIV, but not in MkII.
\define[1]\hello{Good morning, #1!}
+
% This example is compiled using mkiv.
 +
\define[1]\KüFst{Küstenfunkstelle, #1!}
  
 
\starttext
 
\starttext
\hello{mom}
+
\hello
 +
 
 +
\KüFst{12}
 +
 
 
\stoptext
 
\stoptext
 
</context>
 
</context>
  
 
== See also ==
 
== See also ==
[http://en.wikibooks.org/wiki/TeX/def http://en.wikibooks.org/wiki/TeX/def]
+
* {{tex|def}}
  
<!-- something like [[cmd:goto|\goto]] -->
+
== Help from ConTeXt-Mailinglist/Forum ==
 +
All issues with:
 +
{{Forum|{{SUBPAGENAME}}}}
  
[[Category:Reference/en|define]]
+
[[Category:Command/Internals|define]]

Latest revision as of 16:22, 11 November 2019

\define

Syntax (autogenerated)

\define[...]\command{...}
[...]number
\commandcsname
{...}content


Syntax

\define[...]\command{...}
[...] number
{...} macro contents


Description

and \defineexpandable is like \def.

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

Pitfalls

\define does not use \long; that means that 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: