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. (???)
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: "$$"}}))
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.))
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]}.