Prev Next LatexMacro

The Latex Macro Preprocessor

Syntax

Definition
\newcommand{\Name}{Text0}
\newcommand{\Name}[M]{Text0 #J1 ...  TextN-1 #JN TextN}

Usage
\Name
\Name{A1} ... {AM}

Definition
When running OMhelp with the -xml command line option, Latex macros can be defined and used in latex mode.

Global Scope
Macros defined using a \newcommand in the root section have global scope; i.e., are defined for all sections. This avoids having to entirely reprocess all the macros for each section (which could be time consuming for large numbers of macros). It is suggested that you put all these macros in one file using an inline latex command. (You cannot use a displayed latex command when you are just defining macros and there is no output to be displayed.)

Section Scope
Macros defined in sections, other than the root section, are limited in scope to the section they are defined in; i.e., they do not affect any other sections.

Name
The sequence of upper or lower case letters Name specifies the name of the macro.

Text
For K = 0 , ... , N , TextK is a sequence of characters. The character # does not appear in TextK except if directly preceded by a back slash; i.e., \#. In addition, TextK does not contain any } characters unless preceded by a matching { character.

M
The decimal digit M is between one and nine inclusive. It specifies the number of arguments connected to the corresponding \Name macro. If M is not present in the macro definition, it is implicitly zero in the discussion below.

N
The number of replacements made with each use of the macro is denoted by N .

JK
For K = 1 , ... , N , the decimal digit JK is between one and M . It specifies which argument is placed directly before TextK in the macro expansion.

Usage
If the macro \Name is defined with no arguments, the macro usage
     \
Name
has the replacement value
     
Text0
corresponding to the definition of \Name . If the macro \Name is defined with M arguments, the macro usage
     \
Name{A1} ... {AM}
has the replacement value
     
Text0 A1 Text_1 ... TextN-1 AN TextN
where N , and TextK for K = 1 , .. , N , corresponds to the definition of \Name .

Examples

No Arguments
The input
 
$latex \[
     \newcommand{\Dx}{ \frac{d \hspace{1ex} }{d x} }
     \Dx
\] $$
results in the output: @[@ \newcommand{\Dx}{ \frac{d \hspace{1ex} }{d x} } \Dx @]@

Two Arguments
The input
 
$latex \[
     \newcommand{\D}[2]{ \frac{d #1}{d #2} }
     \D{y}{x}
\] $$
results in the output: @[@ \newcommand{\D}[2]{ \frac{d #1}{d #2} } \D{y}{x} @]@

Using Pound Sign in a Macro
The input
 
$latex \[
     \newcommand{\Pound}{The \; pound \; sign \; \# \; must \; be \; escaped}
     \Pound
\] $$
results in the output: @[@ \newcommand{\Pound}{The \; pound \; sign \; \# \; must \; be \; escaped} \Pound @]@

Recursion
You can use macros inside of macros. In addition, you can defined macros inside of inline latex commands. For example, the input
 
$latex
     \newcommand{\one}[1]{#1}
     \newcommand{\two}[1]{\one{#1} \; #1}
     \newcommand{\three}[1]{\two{#1} \; #1}
     \newcommand{\four}[1]{\three{#1} \; #1}
$$
$latex \four{4}$$.
results in the output: @(@ \newcommand{\one}[1]{#1} \newcommand{\two}[1]{\one{#1} \; #1} \newcommand{\three}[1]{\two{#1} \; #1} \newcommand{\four}[1]{\three{#1} \; #1} @)@ @(@ \four{4} @)@.

Mathml
Macros combined with the mathml command can be used to define symbols not available in Standard Latex's math mode. For example, the MathML symbol Ropf is used in the input
 
$latex \[
     \newcommand{\Ropf}{
          \mathml{ <mi mathvariant='normal'> &\#x0211D; </mi> }
     }
     x \in \Ropf^n
\] $$
which results in the output @[@ \newcommand{\Ropf}{ \mathml{ &\#x0211D; } } x \in \Ropf^n @]@

Restrictions
If two macros are defined with the same value of Name , an error message is printed and OMhelp stops.

Nonstandard
Latex macros in OMhelp are different from those in standard Section 3.4.1 of Lamport's book . The following is a list of these differences:
  1. It is ok (not an error) to redefine any of the standard Latex commands.
  2. Macro replacement values cannot use other macros; i.e., the values A1 , ..., AM in a macro usage cannot use other macros.
  3. Macros defined in sections, other than the root section , have local scope; i.e., do not affect any other sections.

Input File: latex/LatexMacro.omh