Matching brackets and `$..$`

I am trying to match brackets on ‘$ … $’ as well as the usual ‘{…}’, etc. using this code as an item in my extension list:

let editor = new EditorView({
  state: EditorState.create({
    extensions: [
      basicSetup
    , myTheme
    , bracketMatching({brackets : "(){}[]$$"})
    , ...

Higher up I have the line

import {bracketMatching} from "@codemirror/matchbrackets"

but the editor doesn’t match the first and last ‘$’ in “$x^2$”. Same for (x^2). Is my config wrong?

Also, I’d like to have auto-close for dollar signs just as for parentheses, etc. This last point is actually the most important, but I don’t know how to do it (continuing to study the docs).

Note. I also tried bracketMatching({brackets : "(){}[]<>"}) on the theory that perhaps the start
and end characters have to be different. However, saying “<” or “<foo” doesn’t provide the terminating
character. My guess is that the above line of code is not actually doing anything. (???)

1 Like

Bracket matching only works if the brackets are different, indeed. Bracket closing seems to work for $, if you configure it (myLanguage.data.of({closeBrackets: {brackets: "$$"}}))

Thanks so much! Alas, I’m still not understanding some key points (my bad):

1.
To test whether I was going in the right direction, I tried the below in my extension list:

, closeBrackets( {brackets : ["(", "[", "{", "'", '"', "<"]})

The editor worked as before, but “<” was not matched. What am I missing here?

(( I do have , bracketMatching( {brackets : "(){}[]<>"}) in extensions ))

2.

Not sure how to use your suggestion. I tried simply

, myLanguage.data.of({closeBrackets: {brackets: "$$"}})

in my extension list but unsurprisingly I got a myLanguage is undefined error. How/where
would I define myLanguage? (( I think I have to rig up a TeX language parser – am looking at the template rep now.))

Thanks again for all your help.

closeBrackets takes no argument.

Use the data property of whatever language you are using in your editor.

My example was actually misleading, brackets should be an array indeed, not a string (though that will also kind of work). So {brackets: ["(", "$", etc]}.