1

In my package there are several messages like this:

\msg_new:nnn { my-module }
  { something-not-define }
  { "#1"~cannot~be~defined,~a~command~with~the~same~name~has~already~existed. }

where #1 is the name of a command. I would like to add a backslash before it, but don't know how -- I've tried \string or \protect, but \string\ #1 produce an extra space while \string\#1 simply become \#1 in the final message.

Jinwen
  • 8,518

1 Answers1

3

I usually use \iow_char:N \\:

\msg_new:nnn { my-module }
  { something-not-define }
  {
    "\iow_char:N \\#1"~cannot~be~defined,~a~command~
    with~the~same~name~has~already~exists.
  }

but you can also use \c_backslash_str:

\msg_new:nnn { my-module }
  { something-not-define }
  {
    "\c_backslash_str #1"~cannot~be~defined,~a~command~
    with~the~same~name~has~already~exists.
  }

\c_backslash_str is a string variable that contains a \12, while \iow_char:N turns the following \⟨char⟩ into ⟨char⟩, so it works for other characters like \{, \}, #, and %, that usually can't be easily written.