coq-community / vsc-conceal

Prettify Symbols Mode for Visual Studio Code [maintainer=@rtetley]
MIT License
53 stars 6 forks source link

Simultaneous conceals don't work on text #15

Closed rayhagimoto closed 3 years ago

rayhagimoto commented 3 years ago

I have been trying to configure my conceal settings so that I can conceal something like \ket{\psi} to display as |𝜓⟩. (I already have a rule for replacing characters such as \psi.) Another example would be to display \ket{abc} as |abc⟩.

I thought this might be possible by instructing all instances of \ket{ to be replaced with | and to contextually replace } with the context "pre" : "\\\\ket{.*". In full:

{ "ugly": "\\\\ket\\{", "pretty": "|"}, { "ugly": "}", "pretty": "⟩", "pre": "\\\\ket\\{.*"}

Each half seems to work independently: Both off: image First on/second off: image First off/second on: image

But when I use both together only one of the conceals is performed:

Both on: image

It seems like one conceal is affecting the context of the other. I have tried a bunch of other attempts to fix this issue and can't figure it out.

rayhagimoto commented 3 years ago

I managed to fix the problem! It looks like it was an issue with regex consuming matches so that both rules couldn't be enforced at the same time.

Here is the fix: (I also added a rule for \bra{[something]} Without conceal: image

With conceal: image

The code: image

{ "ugly": "(?:\\\\ket{)", "pretty": "|", "style": {"color": "#E5C07B"}}, { "ugly": "(?<=\\\\ket{[^}]+)}", "pretty": "⟩", "style": {"color": "#E5C07B"}},

{ "ugly": "(?:\\\\bra{)", "pretty": "⟨", "style": {"color": "#E5C07B"}}, { "ugly": "(?<=\\\\bra{[^}]+)}", "pretty": "|", "style": {"color": "#E5C07B"}}

the colour was chosen to match the theme I'm using akamud.vscode-theme-onedark

I found this forum post useful, although I had to translate the regex from vim's syntax to JS.