Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to define a command using verbatim like in the commented line in the following code.

\documentclass{article}
    \usepackage{amsmath,amsfonts,amssymb}

%   \newcommand{\example}[1]{\verb!#1! : #1}

\begin{document}

\noindent \verb!$\textbf{A}^\intercal$! : $\textbf{A}^\intercal$
\\
\example{$\textbf{A}^\intercal$}$

\end{document}

How can I acheive this? Is it possible to give the argument without the dollars?

share|improve this question
    
    
Thanks for the link but it does not help me... –  projetmbc Oct 7 '11 at 20:54
add comment

1 Answer

up vote 4 down vote accepted

The question that @Marco refers to Verbatim text can't be shown correctly in pdf and the referenced Why doesn’t verbatim work within attempt to explain the difficulties with verbatim commands within macros.

But based on your code in the MWE \newcommand{\example}[1]{\verb!#1! : #1} it appears that you want to be able to show the LaTeX code and its output:

enter image description here

One way to do that would be to use the LTXexample environment from the showexpl package:

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{xcolor}
\usepackage{showexpl}

\lstdefinestyle{demoLatexStyle}{
    basicstyle=\small\ttfamily,
    numbers=none,
    frame=none,
    backgroundcolor=\color{yellow},
    pos=r
}

\begin{document}
\begin{LTXexample}[style=demoLatexStyle]
$\textbf{A}^\intercal$
\end{LTXexample}
\end{document}
share|improve this answer
    
Thanks for this. –  projetmbc Oct 8 '11 at 13:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.