如何在vscode片段中使用双反斜杠`\\`

时间:2019-02-05 01:01:08

标签: visual-studio-code vscode-settings

我要使此代码段起作用:

axios.post('/login', {
    email: user.username,
    password: user.password
}).then(response => {
    .then(response => {
        console.log(response)
        //response.data.authenticated will return true if user has been authenticated 
    })
}).catch(err => {
   console.log(err)
})

以使其格式化为此

"General matrix": {
    "prefix": "general-matrix-n-n-with-a-elements",
    "body": [
        "\\begin{equation}",
        "\t \\begin{bmatrix}",
        "\t\t a_{11} & a_{12} & a_{13} & \\dots  & a_{1n} \\\\ ",
        "\t\t a_{21} & a_{22} & a_{23} & \\dots  & a_{2n} \\\\ ",
        "\t\t \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\ ",
        "\t\t a_{n1} & a_{n2} & a_{n3} & \\dots  & a_{nn}",
        "\t \\end{bmatrix}",
        "\\end{equation}",
    ],
    "description": "General n by n matrix"

但是反斜杠正在格式化为此

    \begin{equation}
    \begin{bmatrix}
            a_{11} & a_{12} & a_{13} & \dots  & a_{1n} \\
            a_{21} & a_{22} & a_{23} & \dots  & a_{2n} \\
            \vdots & \vdots & \vdots & \ddots & \vdots \\
            a_{n1} & a_{n2} & a_{n3} & \dots  & a_{nn}
    \end{bmatrix}
    \end{equation}

请注意,行尾没有双 \begin{equation} \begin{bmatrix} a_{11} & a_{12} & a_{13} & \dots & a_{1n} \ a_{21} & a_{22} & a_{23} & \dots & a_{2n} \ \vdots & \vdots & \vdots & \ddots & \vdots \ a_{n1} & a_{n2} & a_{n3} & \dots & a_{nn} \end{bmatrix} \end{equation} ,而是一个\\

1 个答案:

答案 0 :(得分:2)

只需再添加两个反斜杠,如下所示:

"General matrix": {
    "prefix": "general-matrix-n-n-with-a-elements",
    "body": [
        "\\begin{equation}",
        "\t \\begin{bmatrix}",
        "\t\t a_{11} & a_{12} & a_{13} & \\dots  & a_{1n} \\\\\\ ",
        "\t\t a_{21} & a_{22} & a_{23} & \\dots  & a_{2n} \\\\\\ ",
        "\t\t \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\\ ",
        "\t\t a_{n1} & a_{n2} & a_{n3} & \\dots  & a_{nn}",
        "\t \\end{bmatrix}",
        "\\end{equation}",
    ],
    "description": "General n by n matrix"
  }

要打印的代码段中的每个反斜杠都必须两次转义,因此,如果要输出2个,则每个反斜杠要额外增加2个,总共6个。