# Allen J. Hall

Materials Science & Engineering, Productivity, and Life

## LaTeX Tip: NewCommand

For those friends of mine currently attempting to work in LaTeX to code Materials Science and Engineering related tidbits…

Here’s a quick tip. Tired of typing all those crazy math commands for your material’s name? Simply use a new command. Here’s are a couple examples…

%Simpler way of writing CUINSE2:
\newcommand{\cis}{CuInSe$_{2}$}

%Simpler way of writing CUINGASE2:
\newcommand{\cigs}{CuIn$_{(1-x)}$Ga$_{x}$Se$_{2}$}

%Simpler way of writing CUGASE2:
\newcommand{\cgs}{CuGaSe$_{2}$}

To see how this looks in compiled LaTeX output and another example, click “More”…

Add that to the top of your latex doc (below the document class stuff of course), and then when you need to type the name of CIS for instance, simply type: “\cis{}” Much faster for those underscores or more complicated material names.

The output will look like this (the way I currently have math mode enabled) for my \cigs{} command similar to the above:

For those Miller Bravais directions, there are a few ways to do it:

% form of lattice planes
\newcommand{\lattplaneform}[1]{\ensuremath{\{#1\}}}

The above will take anything you put after the new command like so: “\lattplaneform{0 0 1}” and turn it into the planeform: {0 0 1}. Now, that’s fine, but you can gain a bit more control if you do something like this:

% New Command for Lattice Vectors
\newcommand{\lattplaneform}[3]{\ensuremath{\{#1\:#2\:#3\}}}

Notice that the “\:” is a finer control over spacing in math-mode (see lshort.pdf for more on math-mode spacing). Now, we call the command like so: \lattplaneform{1}{1}{3} which will output: {1 1 3} with finer spacing. We can also add overlines for negative numbers: \lattplaneform{1}{1}{\overline{3}}.

Output will look like so for my \complexlattplane{} command.  I added the $_{Tetragonal}$ after the newcommand: