Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend existing tmLanguage file

I am using Sublime Text 3, in this case to edit LaTeX. To further customize the syntax highlighting I would like to define a new scope that simply extends the shipped LaTeX.tmLanguage (to which I do not have access, not even to read). N.B. I have no interest to write my own tmLanguage-file, not even to download an existing, I just want to extend it, much like overloading a class in Python.

In particular I would like to add meta.footnote.latex to have a custom syntax highlight for \footnote{...} (one definition I found in https://github.com/bradrobertson/sublime-packages/blob/master/LaTeX/LaTeX.tmLanguage)

like image 840
Tom de Geus Avatar asked Oct 21 '25 03:10

Tom de Geus


1 Answers

You can use the include directive to import existing rules from a different file and override or extend its rules.

.tmLanguage:

<dict>
    <key>fileTypes</key>
    <array>
        <string>mylatex</string>
    </array>
    <key>name</key>
    <string>MyLatex</string>
    <key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>text.tex.latex</string>
        </dict>
        <!-- your rules -->
    </array>
    <key>scopeName</key>
    <string>text.tex.latex.mylatex</string>
</dict>

.sublime-syntax:

%YAML 1.2
---
name: MyLatex
file_extensions:
  - mylatex
scope: text.tex.latex.mylatex
contexts:
  main:
    - include: scope:text.tex.latex
    # your rules
like image 91
idleberg Avatar answered Oct 24 '25 12:10

idleberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!