Latex-workshop: Using \( for starting a mathematical expression completes with ) rather than \), also quotation marks.

Created on 12 Aug 2017  路  7Comments  路  Source: James-Yu/LaTeX-Workshop

The suggested formatting for mathematical expressions is \( ... \) for inline expressions and \[ ... \] for displays. However, LaTeX Workshop matches parentheses and brackets without respect to these rules, so typing in \( will have it complete with \( ... ), same with square brackets. It should probably match a \( with a \) at the end.

Also, left ticks, which in TeX are used for lefthand quotation marks, are automatically matched with apostrophes on the second half, as it should be, but if you insert a quote containing apostrophes inside

`` ...aasdf's... '',

they are removed from the end of the quote. I think this is a bug.

Most helpful comment

Open File > Preferences > User Snippets, select "LaTeX" in the dialog and a file named "latex.json" should open.

Paste the above snippet to the appropriate place inside the file and save. After that try typing the following inside a TeX file --im (which is my chosen prefix) and press tab. VSCode should now replace the prefix with \(...\).

All 7 comments

I will look into the first issue soon.

As to the quotation problem, I'm afraid this is constrained by how vscode auto-pairs these tokens. The basic rule is, if the token-to-be-inserted is on the right of the cursor, no new tokens will be inserted.

Or I may mis-interpret the issue.

@James-Yu Yeah, I guess that's a vscode limitation. You might be able to fix it by pairing `` with '' as actual paired tokens, because '' will probably not appear in words.

Unfortunately, the math mode pairing for \( is not supported by vscode. Specifically,

    "autoClosingPairs": [
        ["{", "}"],
        ["[", "]"],
        ["(", ")"],
        ["$", "$"],
        ["`", "'"],
        ["\\(", "\\)"]
    ],

won't work. There can be some dirty hack like listening to user input and programatically add an addtional \. However, I am hesitated to do so since it can be against vscode's design principle, and quality control can be a big issue. Though I will push a small fix on the pairing of ` and '. Further discussion is welcomed.

Can you add an option to disable paren and bracket pairing then? Having it half working is worse for my workflow than not working at all.

Also, I might submit an upstream issue, and I'll link that issue here, if you could explain the limitation to them if I get it wrong!

For anyone reading this and trying to find a workaround: one can create a user snippet like this:

    "Inline math": {
    "prefix": "--im",
    "body": "\\(${1:...}\\)"
}

Typing the prefix and hitting tab will complete with the body and the dots selected.

thanks! Where do I put that? Settings? Also, what do you mean typing the prefix?

Open File > Preferences > User Snippets, select "LaTeX" in the dialog and a file named "latex.json" should open.

Paste the above snippet to the appropriate place inside the file and save. After that try typing the following inside a TeX file --im (which is my chosen prefix) and press tab. VSCode should now replace the prefix with \(...\).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jlelong picture jlelong  路  4Comments

sidmishraw picture sidmishraw  路  3Comments

iainmstott picture iainmstott  路  5Comments

fsonntag picture fsonntag  路  4Comments

s-ilic picture s-ilic  路  3Comments