Difference between revisions of "Inside ConTeXt"

From Wiki
Jump to navigation Jump to search
(a paragraph about \protect added)
m (added texcode markup)
Line 3: Line 3:
 
== Using variables ==
 
== Using variables ==
  
\setvariables[namespace][key=value]
+
<texcode>
\getvariable{namespace}{key}
+
\setvariables[namespace][key=value]
 +
\getvariable{namespace}{key}
 +
</texcode>
  
 
== Defining new commands ==
 
== Defining new commands ==
Line 12: Line 14:
 
letters: <tt>@</tt>, <tt>!</tt> and <tt>?</tt>.  
 
letters: <tt>@</tt>, <tt>!</tt> and <tt>?</tt>.  
 
Before and after the use or definition of such protected commands in your input files, the catcode of these  
 
Before and after the use or definition of such protected commands in your input files, the catcode of these  
characters has to be changed. This is done by <tt>\unprotect</tt> and <tt>\protect</tt>:
+
characters has to be changed. This is done by <cmd>unprotect</cmd> and <cmd>protect</cmd>:
  
\unprotect
+
<texcode>
\def\!test{alfa}  
+
\unprotect
\protect  
+
\def\!test{alfa}  
 +
\protect  
 +
</texcode>
  
The newly defined command <tt>\!test</tt> can of course only be called upon when we are in the \unprotect ed state, otherwise TEX reads the command <tt>\!</tt>, followed by the word <tt>test</tt> (and probably complains loudly about not being in math mode). These protection/unprotection commands can be nested.  When the nesting becomes deeper than one level, the system reports the current protection level. It is a good habit to always start your macro files with <tt>\unprotect</tt> and end them with <tt>\protect</tt>.
+
The newly defined command <tt>\!test</tt> can of course only be called upon when we are in the <cmd>unprotect</cmd>ed state, otherwise TeX reads the command <tt>\!</tt>, followed by the word <tt>test</tt> (and probably complains loudly about not being in math mode). These protection/unprotection commands can be nested.  When the nesting becomes deeper than one level, the system reports the current protection level. It is a good habit to always start your macro files with <cmd>unprotect</cmd> and end them with <cmd>protect</cmd>.
  
 
+
'''See also''':
[[Commands with KeyVal arguments|Commands with Key=Value arguments]].
+
[[Commands with KeyVal arguments|Commands with Key=Value arguments]],
 
+
[[Commands with optional arguments]]
[[Commands with optional arguments]].
+
>

Revision as of 11:31, 2 September 2004

< Main Page

Using variables

\setvariables[namespace][key=value]
\getvariable{namespace}{key}

Defining new commands

Special characters in command names

Some commands have special characters in their names, that TeX normally does not consider to be letters: @, ! and ?. Before and after the use or definition of such protected commands in your input files, the catcode of these characters has to be changed. This is done by \unprotect and \protect:

\unprotect
\def\!test{alfa} 
\protect 

The newly defined command \!test can of course only be called upon when we are in the \unprotected state, otherwise TeX reads the command \!, followed by the word test (and probably complains loudly about not being in math mode). These protection/unprotection commands can be nested. When the nesting becomes deeper than one level, the system reports the current protection level. It is a good habit to always start your macro files with \unprotect and end them with \protect.

See also: Commands with Key=Value arguments, Commands with optional arguments >