Difference between revisions of "System Macros/Mnemonics and Aliases"

From Wiki
Jump to navigation Jump to search
m (Had mistakenly deleted the example)
(general updates)
Line 3: Line 3:
 
== Mnemonics and aliases ==
 
== Mnemonics and aliases ==
  
In ConTeXt we sometimes manipulate the <''catcodes''> of certain characters. Because we are not that good at numbers, we introduce some symbolic names. This makes it easier to key in things like this:
+
=== Category codes ===
 +
 
 +
ConTeXt sometimes manipulates the <''catcodes''> of certain characters. Catcode values have predefined meanings, but TeX expects them to be given as bare numbers, and the precise mapping of functionality to numbers is hard to remember. Therefore, ConTeXt introduces some symbolic names. This makes it easier to key in things like this:
  
 
<texcode>
 
<texcode>
Line 9: Line 11:
 
</texcode>
 
</texcode>
  
All the mnemonics that are defined are
+
The mnemonics that are defined are
  
 
<texcode>
 
<texcode>
Line 32: Line 34:
  
 
Two of these symbolic names are actually used so often that they even have non-protected aliases: <code>\other</code> and <code>\active</code>.
 
Two of these symbolic names are actually used so often that they even have non-protected aliases: <code>\other</code> and <code>\active</code>.
 
We often need a space as defined in Plain TeX. Because ConTeXt cannot be sure that <code>\space</code> is not redefined, it internally uses an alias: <code>\normalspace</code>.
 
 
{{note|When dealing with ConTeXt, please remember to '''never''' (re-)define macros that start with <code>\normal...</code>. Weird, unexpected things can, and probably will, occur!}}
 
 
These are constant counters, corresponding to <code>0</code>, <code>1</code> and <code>-1</code>.
 
  
 
{{note|Beware: if you want to have access to @, !, and ? in macronames, use  
 
{{note|Beware: if you want to have access to @, !, and ? in macronames, use  
Line 47: Line 43:
 
</texcode>
 
</texcode>
  
instead of manipulating the catcode of @ directly. Protection macros handle nested usage.}}
+
instead of manipulating the catcode of @ directly. The protection macros handle nested usage.}}
 +
 
 +
 
 +
=== Stored primitives and macros ===
 +
 
 +
ConTeXt often needs to use or redefine commands that are explained in the TeXbook (be they primitives, or macros from the plain format). ConTeXt sometimes defines commands with those names itself, and sometimes it cannot be sure that such commands are not redefined by a user, so it saves quite a large number of these commands internally under a different name. For this, it uses their canonical name, prefixed with <code>normal</code>.
 +
 
 +
An example: a command that is often needed is a space macro as defined in Plain TeX. Because ConTeXt cannot be sure that <code>\space</code> is not redefined, it uses the alias <code>\normalspace</code>. When dealing with ConTeXt, please refrain from  (re-)defining macros that start with <code>\normal...</code>. Weird, unexpected things can - and probably will - happen if you do.
 +
 
 +
The full list is too long to repeat here, but it includes at least: all of the <code>\if</code>-related statements, all of the kerning and glue related commands, all of the box typesetting commands, all of the font definition commands, and quite a few math commands like <code>\left</code> and <code>\right</code>, <code>\over</code>, and <code>\in</code>.
 +
 
 +
=== Numerical constants ===
 +
 
 +
Because using a single command is sometimes easier to handle in a macro than the actual digits of a number,
 +
there are a few constants predefined (some of which are inherited from the plain format):
 +
 
 +
<texcode>
 +
\minusone        =    -1
 +
\zerocount      =    0
 +
\plusone        =    1 \@ne            =    1
 +
\plustwo        =    2 \tw@            =    2
 +
\plusthree      =    3 \thr@@          =    3
 +
\plusfour        =    4 \@iv            =    4
 +
\plusfive        =    5
 +
\plusten        =    10
 +
\sixt@@n        =    16
 +
\@cclv          =  255
 +
\@cclvi          =  256
 +
\@xc            =    90
 +
\plushundred    =  100
 +
\@clxx          =  180
 +
\plusthousand    =  1000 \@m              =  1000
 +
\plustenthousand = 10000 \@M              = 10000
 +
\@MM            = 20000
 +
</texcode>
 +
 
 +
In cases where there is both a ''user'' command and an ''internal'' command, like in <code>\plusone</code> versus <code>\@ne</code>, use of the ''user'' command is prefered.
  
 
< '''Prev:''' [[System Macros/Fundamentals|Fundamentals]] | '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Scratch Variables|Scratch Variables]] >
 
< '''Prev:''' [[System Macros/Fundamentals|Fundamentals]] | '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Scratch Variables|Scratch Variables]] >

Revision as of 14:13, 24 December 2006

< Prev: Fundamentals | Top: System Macros | Next: Scratch Variables >

Mnemonics and aliases

Category codes

ConTeXt sometimes manipulates the <catcodes> of certain characters. Catcode values have predefined meanings, but TeX expects them to be given as bare numbers, and the precise mapping of functionality to numbers is hard to remember. Therefore, ConTeXt introduces some symbolic names. This makes it easier to key in things like this:

\catcode'\@=\@@letter

The mnemonics that are defined are

\chardef\@@escape      =  0
\chardef\@@begingroup  =  1
\chardef\@@endgroup    =  2
\chardef\@@mathshift   =  3
\chardef\@@alignment   =  4
\chardef\@@endofline   =  5
\chardef\@@parameter   =  6
\chardef\@@superscript =  7
\chardef\@@subscript   =  8
\chardef\@@ignore      =  9
\chardef\@@space       = 10
\chardef\@@letter      = 11
\chardef\@@other       = 12   \chardef\other  = 12
\chardef\@@active      = 13   \chardef\active = 13
\chardef\@@comment     = 14

If you don't understand the names of the macros, you can look them up in the TeXbook.

Two of these symbolic names are actually used so often that they even have non-protected aliases: \other and \active.


NOTE: Beware: if you want to have access to @, !, and ? in macronames, use
\unprotect
\def\My@@MAcro{..}
\protect

instead of manipulating the catcode of @ directly. The protection macros handle nested usage.


Stored primitives and macros

ConTeXt often needs to use or redefine commands that are explained in the TeXbook (be they primitives, or macros from the plain format). ConTeXt sometimes defines commands with those names itself, and sometimes it cannot be sure that such commands are not redefined by a user, so it saves quite a large number of these commands internally under a different name. For this, it uses their canonical name, prefixed with normal.

An example: a command that is often needed is a space macro as defined in Plain TeX. Because ConTeXt cannot be sure that \space is not redefined, it uses the alias \normalspace. When dealing with ConTeXt, please refrain from (re-)defining macros that start with \normal.... Weird, unexpected things can - and probably will - happen if you do.

The full list is too long to repeat here, but it includes at least: all of the \if-related statements, all of the kerning and glue related commands, all of the box typesetting commands, all of the font definition commands, and quite a few math commands like \left and \right, \over, and \in.

Numerical constants

Because using a single command is sometimes easier to handle in a macro than the actual digits of a number, there are a few constants predefined (some of which are inherited from the plain format):

\minusone        =    -1
\zerocount       =     0
\plusone         =     1 \@ne             =     1
\plustwo         =     2 \tw@             =     2
\plusthree       =     3 \thr@@           =     3
\plusfour        =     4 \@iv             =     4
\plusfive        =     5
\plusten         =    10
\sixt@@n         =    16
\@cclv           =   255 
\@cclvi          =   256
\@xc             =    90
\plushundred     =   100
\@clxx           =   180
\plusthousand    =  1000 \@m              =  1000
\plustenthousand = 10000 \@M              = 10000
\@MM             = 20000

In cases where there is both a user command and an internal command, like in \plusone versus \@ne, use of the user command is prefered.

< Prev: Fundamentals | Top: System Macros | Next: Scratch Variables >