I am writing text that should be displayed as a code block with some fancy math mode characters.
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstinline[mathescape=true]{Integer $\not \sim$ String}
\end{document}
This renders as expected. However, I want to wrap this use of \lstinline in a customily named command, to be able to easily change colouring, type family, etc.. for all occurrences later on. What I want is:
\documentclass{article}
\usepackage{listings}
\begin{document}
\newcommand{\codem}[1]{\lstinline[mathescape=true]{#1}}
\codem{Integer $\not \sim$ String}
\end{document}
However, this does not compile and complains with the message:
! Improper alphabetic constant.
<to be read again>
\not
l.622 \codem{Integer $\not \sim$ String}
?
! Missing $ inserted.
<inserted text>
$
l.622 \codem{Integer $\not \sim$ String}
Why can't I wrap \lstinline here, and how can I achieve a similar abstraction?
\codem
works if you define it as\newcommand{\codem}{\lstinline[mathescape=true]}
\lstinline{foo}
literally writes is arguments, so\lstinline{#1}
ought to actually just write#1
.