I am trying to define a command which contains a tabbing environment. However, when I try to use the \lstinline command from the listings package it produces the "Improper Alphabetic Constant" error if I use a backslash.

When the same code is carried out without being contained within my defined command it works fine. Also, the \lstinline command works in the command without a backslash.

Why is this and how can I solve it so that I can place the tabbing environment in my defined command and still use \lstinline with a backslash?







For information, the following commands work without issue using the same document preamble.



  • Also I know it seems an odd thing to ask but the actual use involves a longer command which I defined and changes to various packages which I have made. I just simplified it down to the root of the problem. If you want more information let me know.
    – Eddie
    Commented Apr 21, 2018 at 0:07
  • 1
    Escape the backslash: \TabVerb{\lstinline|\\Hello|}?
    – Troy
    Commented Apr 21, 2018 at 6:39
  • lstinline, like all verbatim commands can not be used in the argument or definition of another command Commented Apr 21, 2018 at 7:14
  • David test the last command I wrote with the document preamble I specified, or Troy's suggestion. I assure you that \lstinline will work in the argument of a command
    – Eddie
    Commented Apr 21, 2018 at 11:50

1 Answer 1


The method provided by Troy works (not sure how to mark his comment as the answer to give him credit). Simply escape the backslash with another backslash:


Alternatively, use the cprotect package alongside the command \cMakeRobust to prevent having many backslashes all over the place. (Simply place the following after the definition of the command)


Note that the use of the cprotect package and \cMakeRobust also enables the use of \verb in the command if it is preferred over \lstinline.

  • Also if someone could copy and paste this answer and I will give you credit (preferably Troy), it seems odd that I would answer my own question
    – Eddie
    Commented Apr 21, 2018 at 14:34

You must log in to answer this question.

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