Reputation: 854
I'm using vscode with the latex workshop extension, and I put the following in my latex.json file.
"newcommand": {
"prefix": "nc",
"body": [
"\\newcommand{\\$1}{$2}",
],
},
I expected nc
to expand to \newcommand{\}{}
, with placeholders after the backslash and in the second pair of braces. However, I'm getting \newcommand{$1}{}
with only one placeholder in the second pair of braces. Why is that? How can I get the desired behavior?
Upvotes: 0
Views: 429
Reputation: 28783
From the snippet doc
With \ (backslash), you can escape
$
,}
, and\
. Within choice elements, the backslash also escapes comma and pipe characters.
The following string is passed to the snippet engine: \newcommand{\$1}{$2}
\$
is interpreted as a literal $
We want the following string to be passed : \newcommand{\\$1}{$2}
Escaping this string for json gives
"\\newcommand{\\\\$1}{$2}"
Upvotes: 1