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 . 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,
Let us say we want corresponding to
and
corresponding to
. 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,
and $\gmx{n}$ produces,
If nothing is specified as argument, i.e., $\gmx{}$, produces