Generalparameter passing to \verb|| environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
csmgroup
Posts: 25
Joined: Sat Jul 17, 2010 6:58 pm

parameter passing to \verb|| environment

Post by csmgroup »

I happen to write the following code over and over again.

Code: Select all

{\color{blue}\verb|>|} {\footnotesize\verb|HI|} 
So, I came up with the following code to make it a command.

Code: Select all

\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 $, \ ...

Code: Select all


\documentclass{article}

\newcommand{\result}[2]{%
{\color{#1}\verb|>|} {\footnotesize\verb|#2|} 
}

\usepackage{color}

\begin{document}
{\color{blue}\verb|>|} {\footnotesize\verb|HI|} 

\result{red}{HI}

\end{document}
Attachments
Screen shot 2010-08-03 at 3.55.16 PM.png
Screen shot 2010-08-03 at 3.55.16 PM.png (6.96 KiB) Viewed 2047 times
Last edited by csmgroup on Wed Aug 04, 2010 4:43 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: parameter passing to \verb|| environment

Post by frabjous »

Do you really need to use \verb here rather than e.g., \texttt? I think that would solve your problem.
csmgroup
Posts: 25
Joined: Sat Jul 17, 2010 6:58 pm

Re: parameter passing to \verb|| environment

Post by csmgroup »

Thanks for the answer, I agree to use \texttt for this purpose.
Post Reply