[Tex/LaTex] Create a command for a different font


I'm pretty new to Latex and I am writing my thesis. I would like to use a command that I can essentially change the font of a few words in-line or separate (like an equation).

I have computer commands that I would like to display in a different font (Courier New) than the rest of the document. I have heard that I could either modify the \emph{} command or create a new command like \comp{} that changes the font.

I don't know how to do either. Is there a package that already does this for me? Thanks for your help


Next you need to position the robot arm by using the command \comp{Home}.


\comp{cd folder ./trajectory.exe}

Best Answer

What you want is a macro. Wikibooks has excellent tutorial on the topic. As for the code environment, use the listings package: Wikibooks, CTAN.

Here is a quick example of what you can do. The \newcommands there make three, well, new commands: \compbox, \compline, and \comp.

numbers = left,
numberstyle = \tiny,
numbersep = 5pt,
} %% Many other options!



Hit the \compbox{F5} key. Next you need to position the
robot arm by using the command \compline{Home}. Now run
this on the terminal:

 \comp{texdoc listings}

Which should open \comp{listings} documentation.
Then you can write something like this:

import math
import sys
def cube(x):
    return x*x*x
# An example of Python code
# in LaTeX



Related Question