Changes

Jump to navigation Jump to search
3,661 bytes added ,  23:12, 26 August 2013
Create page
{{Reference
|name=starttexdefinition
|attributes=
}}

== [[Help:Reference|Syntax]] ==
<table cellspacing="4" cellpadding="2" class="cmd">
<tr>
<td colspan="2" class="cmd">\starttexdefinition
<span class="first" style="color:red;"> ... </span><span class="second"> ... </span><span class="third"> ... </span><span class="fourth" >command</span><span class="fifth" > ... </span></td>
</tr>
<tr valign="top" class="first">
<td class="cmd">...</td>
<td>global (optional)</td>
</tr>
<tr valign="top" class="second">
<td class="cmd">...</td>
<td>unexpanded (optional)</td>
</tr>
<tr valign="top" class="third">
<td class="cmd">...</td>
<td>expanded (optional)</td>
</tr>
<tr valign="top" class="fifth">
<td class="cmd">...</td>
<td>#arguments</td>
</tr>
</table>


== Description ==

The {{code|starttexdefinition}} uses the {{code|start…stop}} syntax to define
new control sequences. They directly map to the brace-delimited definitions.
It's also possible to define commands that take arguments. Both, the numbered
syntax and the MkVI name-syntax are supported. To use MkVI syntax, save the
file as {{code|file.mkvi}} or place the line <tt>%% macros=mkvi</tt> at the
beginning of the document. The command features several modifier sequences,
which are demonstrated in the following examples.

== Example ==

<texcode>
%% \def\command{…}
\starttexdefinition command

\stoptexdefinition

%% \def\command#1#2{…}
\starttexdefinition command #1 #2

\stoptexdefinition

%% \def\command#name#options{…}
\starttexdefinition command #name #options

\stoptexdefinition

%% \unexpanded\def\command#name#options{…}
\starttexdefinition unexpanded command #name #options

\stoptexdefinition

%% \gdef\command{…}
\starttexdefinition global command

\stoptexdefinition

%% \unexpanded\gdef\command{…}
\starttexdefinition global unexpanded command

\stoptexdefinition

%% \unexpanded\edef\command#arg{…}
\starttexdefinition global unexpanded command #arg

\stoptexdefinition

%% \unexpanded\xdef\command#arg{…}
\starttexdefinition global unexpanded expanded command #arg

\stoptexdefinition
</texcode>

== Pitfalls ==

The order in which the modifier sequences {{code|global}}, {{code|unexpanded}}
and {{code|expanded}} appear matters. One difference between traditional
definitions and the start-stop environment is that spaces are ignored in the
{{code|texdefinition}} environment, so line endings don't have to be littered
with percent signs and the definitions tend to be more readable. This is
usually what is desired when writing macros. However, it has to be taken into
account when encapsulating Lua code.

<texcode>
%% no problems here
\def\somecommand
{\startluacode
if true then
else
end
\stopluacode}

\somecommand

%% this will fail
\starttexdefinition somecommand
\startluacode
if true then
else
end
\stopluacode
\stoptexdefinition

\somecommand
</texcode>

The above {{code|texdefinition}} example will fail, since the line endings,
which normally result in a space are ignored and the spaces collapsed, so Lua
receives {{code|if true thenelseend}}, which is not valid. The solution is to
add a space and place a percent sign, which will not be removed in that case.

<texcode>
%% this works
\starttexdefinition somecommand
\startluacode
if true then %%
else %%
end
\stopluacode
\stoptexdefinition

\somecommand
</texcode>

== See also ==
* {{tex|def}}
* {{cmd|define}}

== Help from ConTeXt-Mailinglist/Forum ==
All issues with:
{{Forum|{{SUBPAGENAME}}}}

[[Category:Command/Internals|starttexdefinition]]
69

edits

Navigation menu