1

I'd like to print a symbol and the command to get the symbol. For example,\bomb\ (\verb|\bomb|). To make a command to save some keystrokes, I came up with this command \newcommand{\symb}[1]{#1\ (\verb|#1|)}. However, I get some compilation error \verb ended by end of line. with wrong results.

\documentclass{article}

\usepackage{fourier}
\usepackage{marvosym}
\newcommand{\symb}[1]{#1\ (\verb|#1|)}

\begin{document}

Fourier
\begin{itemize}
    \item \symb{\danger}
    \item \bomb\ (\verb|\bomb|)
    \item \grimace\ (\verb|\grimace|)
\end{itemize}

\end{document}

enter image description here

What's wrong and what might be the solution?

prosseek
  • 6,033
  • You can't use \verb inside of a macro, as generally verbatim content is not possible, at least not this way. –  Jan 20 '18 at 19:37

1 Answers1

4

It is too late to use \verb after the argument has been tokenised but you can do:

\documentclass{article}

\usepackage{fourier}
\usepackage{marvosym}
\newcommand{\symb}[1]{#1\ (\texttt{\string#1})}

\begin{document}

Fourier
\begin{itemize}
    \item \symb{\danger}
    \item \bomb\ (\verb|\bomb|)
    \item \grimace\ (\verb|\grimace|)
\end{itemize}

\end{document}
David Carlisle
  • 757,742