1

How can I customize the syntax highlighting in Sublime Text 3? In particular, I'd like to ignore text delimeted by $ (as well as suppressing the 'closing' $ whenever I type $).

I am using LaTeXTools.

I have tried to use PackageResourceViewer: Open Resource, and viewing the LaTeX.sublime-syntax YAML resource, but the only line relating to $ that I could see is:

 - match: '(?:<|>)(\{)\$(\})'
      scope: meta.column-specials.latex
      captures:
        1: punctuation.definition.column-specials.begin.latex
        2: punctuation.definition.column-specials.end.latex
    - include: scope:text.tex

I don't understand this syntax.

1

The reason you can't find the rule is because, in the current version of the syntax, it's not in LaTeX.sublime-syntax, but in TeX.sublime-syntax, where you'll find:

- match: \$\$
  captures:
    0: punctuation.definition.string.begin.tex
  push:
    - meta_scope: string.other.math.block.tex
    - match: \$\$
      captures:
        0: punctuation.definition.string.end.tex
      pop: true
    - include: scope:text.tex.math
    - include: main

and

- match: \$
  captures:
    0: punctuation.definition.string.begin.tex
  push:
    - meta_scope: string.other.math.tex
    - match: \$
      captures:
        0: punctuation.definition.string.end.tex
      pop: true
    - match: \\\$
      scope: constant.character.escape.tex
    - include: scope:text.tex.math
    - include: main

You can change the meta_scope property. I'd recommend changing the first to meta.environment.math.block.dollar.latex and the second to meta.environment.math.inline.dollar.latex, as these are the scopes used in the revision of the LaTeX syntax that will be in the next beta, and they will ensure that math mode completions will continue to work. If you don't care about math mode completions, you can change them to whatever you want.

Overriding the $ keybindings is quite a bit different. Select Preferences | Key Bindings – User and add the following key binding:

{"keys": ["$"], "command": "insert_snippet", "args": {"contents": "\\$"}, 
    "context": [
        {"key": "selector", "operator": "equal", "operand": "text.tex.latex"}
    ] 
}

Bear in mind that this is one entry in a JSON list so the file should start with [ end with ] and you need a comma before it if there are preceding entries, etc. (See the docs on this). This simply tells ST to insert a $ when you type $ in a LaTeX document.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.