Changes

Jump to navigation Jump to search
=== Protecting internal macros ===
We can shield macros from users by using some special characters in their names. Some characters that TeX normally does not consider to be letters (and are therefore usedfor this purpose) are: <code>@</code>, <code>!</code> and <code>?</code>. Before and after the definition of protected macros, we have to change the <''catcode''> of these characters. This is done by <code>\unprotect</code> and <code>\protect</code>, for instance:
<texcode>
The newly defined command <code>\!test</code> can of course only be called upon when we are in the <code>\unprotect</code>'ed state, otherwise TeX reads the command <code>\!</code>, followed by the word <code>test</code> and probably complains loudly about not being in math mode.
General purpose low-level commands in the ConTeXt core sometimes contain one or more <code>@</code> signs.  Temporary values and definitions often start with two <code>!</code> markers, and macros that represent internal strings normally start with a single letter followed by a single exclamation mark, for example: <code>\v!off</code> stands for the meaning of ''off'' in the current interface language. More on this convention can be read in [[System Macros/Scratch Variables]].  Prefixes for parameter list assignments start with two <code>?</code> markers, like <code>\??ly</code>. This is explained in [[System Macros/Key Value Assignments]] The protection/and unprotection commands can be nested (unlike <code>\makeatletter</code> in LaTeX). This nesting ability is a convenience, since it allows one to use the protection pair regardless of whether protection is already turned on. It is a very good habit to always start your macro files with <code>\unprotect</code> and end them with <code>\protect</code>, even if you don't need to access internal commands right away.
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 <code>\unprotect</code> and end them with <code>\protect</code>.
| '''Top:''' [[System Macros]] | '''Next:''' [[System Macros/Mnemonics and Aliases|Mnemonics & Aliases]] >

Navigation menu