I want to create a command that will format code in a certain way. In this case I want code to be italic and red. So instead of doing \textcolor{red}{\textit code} I want to make a function, if you will, to do it for me with less lines of code. My understanding of it so far is very... basic. I just started using latex, this is what I have so far.
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\newcommand{\code}[1]{\textcolor{ForestGreen}{\textit #1}}
But this only prints out the first letter in italic. The colour seems fine though. Any help and explanations would be wonderously helpful.


\newcommand{\code}[1]{\textcolor{ForestGreen}{\textit{#1}}}? Also, no need to loadcolorandxcolor; it's enough to loadxcolor. – Gonzalo Medina Jun 7 '12 at 21:37\textitrequires an argument: you want to say\textcolor{red}{\textit{code}}in your original method. And you need to say\code{code}, not\code code. – egreg Jun 7 '12 at 21:40ForestGreen):\newcommand{\code}[2][ForestGreen]{\textcolor{#1}{\textit{#2}}}. The\code{text}will produce italics inForestGreen, and\code[red]{text}will produce italics in red. – Peter Grill Jun 7 '12 at 21:44