Hot answers tagged

19

The different is that \verb is an inline verbatim environment so that everything inside it is taken literally, even what would otherwise be considered a command. This also happens to use a monospace font because it is usually use to insert some codes (so that special characters don't pose any issue). On the other hand, \tt (and you really should be using ...


3

You can't have verbatim-like environments in the arguments to \ifthen. But you can use the primitive conditionals. \documentclass{article} \usepackage{listing} \usepackage[framed]{matlab-prettifier} \newcounter{ctr} \setcounter{ctr}{1} \lstnewenvironment{myMP} {\lstset{style={Matlab-editor}}} {} \begin{document} \ifnum\value{ctr}=1 \begin{myMP} a = 1 ...


2

You can use \defverbatim{\foo}{\begin{verbatim}...\end{verbatim}} \documentclass{beamer} \begin{document} \begin{frame}[fragile] \defverbatim{\testslide}{\begin{verbatim}test slide 1 $E=mc^2$\end{verbatim}} \only<1>{% \testslide } \only<2>{ test slide 2 } \end{frame} \end{document}


2

As I commented, \verb can neither appear in a macro definition nor argument. However, depending on your need, this may suffice. One saves a verbbox in advance, and can pass that as an argument. \documentclass{article} \usepackage{xcolor,verbatimbox} \newcommand{\test}[1]{{\color{blue}#1}} \usepackage{siunitx,booktabs} \begin{document} This works ...


2

You could use cprotect, but you should think twice before using \verb when, perhaps,\texttt` might suffice. \documentclass{article} \usepackage{xcolor,cprotect} \newcommand{\test}[1]{\textcolor{blue}{#1}} \begin{document} This works \verb+\num{6.022e-23}+ \cprotect\test{This is a test of a \verb+\num{6.022e-23}+} \end{document} If you have several ...


1

Here, I save the listing in a temporary \vbox, and only conditionally print it out. \documentclass{minimal} \usepackage{ifthen} \newcounter{ctr} \setcounter{ctr}{1} \usepackage{listing} \usepackage[framed]{matlab-prettifier} \lstnewenvironment{myMP}{% \lstset{style={Matlab-editor}}% }{} \begin{document} \setbox0=\vbox{% \begin{myMP} ...



Only top voted, non community-wiki answers of a minimum length are eligible