User control sequences in LaTex


Frequently used expressions in Latex can be reproduced with little effort by user control sequences. They are defined using newcommand and the syntax is,

 \newcommand{name}[num]{definition}

{name} : Name of the command you want to create
[num] : optional argument that specifies the number of argument that the newcommand accepts. Maximum of 9 argument are possible. If nothing is specified, treat it as zero arguments.
{definition} : definition of the command

The usefulness of this command can be better illustrated with the following example.

In a LaTeX document, for example, we want to write an expression g_m = \mu C_{ox} \frac{W}{L} (V_{GS}-V_T). In Latex this can be produced by writing,

  $g_m = \mu C_{ox} \frac{W}{L} (V_{GS}-V_T)$

Instead of writing lengthy expression/code every time, we can simply produce this by defining new control sequence(gmx, as in this example) for the above expression. The syntax for that is,

\newcommand{gmx}{g_m = \mu C_{ox} \frac{W}{L} (V_{GS}-V_T)}

Here gmx is the new command we defined.
Now call the new command $\gmx$ in the latex environment to produce,

    \[g_m = \mu C_{ox} \frac{W}{L} (V_{GS}-V_{T})\]

Let us say we want g_{mn} corresponding to V_{GSn} and g_{mp} corresponding to V_{GSp}. This can be achieved by passing optional arguments to this control sequence. The user control sequence is modified as follows to pass optional arguments.

\newcommand{gmx}[1]{g_{m#1} = mu C_{ox}frac{W}{L}(V_{GS#1}-V_T)}

Now $\gmx{1}$ produces,

    \[g_{m1} = \mu C_{ox} \frac{W}{L} (V_{GS1}-V_{T})\]

and $\gmx{n}$ produces,

    \[g_{mn} = \mu C_{ox} \frac{W}{L} (V_{GSn}-V_{T})\]

If nothing is specified as argument, i.e., $\gmx{}$, produces

    \[g_{m} = \mu C_{ox} \frac{W}{L} (V_{GS}-V_{T})\]

Leave a Comment