In the following example I would like to shortcut the \lstinline with a shorter command such as \cd (code). Unfortunately it does not work with backslashes:



\lstinline{\ } % This works
\cd{\ } % This doesn't work


In the above example, the \lstinline{\ } works, but with \cd the backslash does not work. How to fix this?

1 Answer 1


Just avoid passing the argument and define

  • Should I need the braces around {\cd} ?
    – nowox
    Commented Aug 12, 2019 at 15:18
  • @nowox They're not strictly necessary but are considered good LaTeX style.
    – campa
    Commented Aug 12, 2019 at 20:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .