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?

  • You can't use \verb inside of a macro, as generally verbatim content is not possible, at least not this way. – user31729 Jan 20 '18 at 19:37
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}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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