I happen to write the following code over and over again.
{\color{blue}\verb|>|} {\footnotesize\verb|HI|}
So, I came up with the following code to make it a command.
\newcommand{\result}[2]{%
{\color{#1}\verb|>|} {\footnotesize\verb|#2|}
}
The problem is that the result is not what I expected, there are |
characters attached.
What might be wrong? I need to have the verbatim
environment kept as the result can contain some characters something like $
, \
...
\documentclass{article}
\newcommand{\result}[2]{%
{\color{#1}$>$} {\footnotesize \verb|#2|}
}
\usepackage{color}
\begin{document}
{\color{blue}\verb|>|} {\footnotesize\verb|HI|}
\result{red}{HI}
\end{document}
ADDED
- For the original source,
\verb|>|
should have been$>$
. I updated the source example. Following Willie's answer, I modified the command
\newcommand{\result}[2]{{\color{#1}$>$} {\footnotesize\texttt{#2}}}
It seems fine, but with multicols
environment, the footnotesize
font, gives some blank spaces before its printing of characters. I attach the screen capture and source code.
It seems that line break causes this problem, by adding \mbox
inside the \texttt
, I could remove the blank.
\newcommand{\result}[2]{{\color{#1}$>$} {\footnotesize\texttt{\mbox{#2}}}}
\documentclass{article}
\usepackage{multicol}
\usepackage{tikz}
\newcommand{\result}[2]{{\color{#1}$>$} {\footnotesize\texttt{\mbox{#2}}}}
\newcommand{\resultp}[2]{{\color{#1}$>$} {\small\texttt{\mbox{#2}}}}
\usepackage{color}
\begin{document}
\begin{multicols*}{2}
\noindent\result{green}{Welcome to my project! These are your args: (a b c)}\\ \result{green}{hello}\\ \result{green}{HI my\string_name}
\vskip 2ex
\noindent\resultp{green}{Welcome to my project! These are your args: (a b c)}\\ \resultp{green}{hello}\\ \resultp{green}{HI}
\end{multicols*}
\end{document}