jonschlinkert / sublime-markdown-extended

Top 100 Sublime Text plugin! Markdown syntax highlighter for Sublime Text, with extended support for GFM fenced code blocks, with language-specific syntax highlighting. YAML Front Matter. Works with ST2/ST3. Goes great with Assemble.
https://github.com/jonschlinkert
MIT License
660 stars 96 forks source link

combine latex and markdown highlighting #19

Closed puterleat closed 8 years ago

puterleat commented 11 years ago

Using inline latex is a pretty common pattern in markdown documents destined for conversion with pandoc.

For example, one might include the command \textsc{small caps text} in a pandoc markdown doc because markdown has no native syntax for small caps.

However at present I can't work out how to get both markdown and latex syntax highlighting active at the same time. It would also be nice if the document tree (for ctrl-R) recognised both markdown headings and \part{} \chapter{} and \section{} commands.

johncsnyder commented 9 years ago

I figured out a simple hack to include latex highlighting inline. seems to work well so far.

Inline math with e.g. $f(x) = x^2$ works.

Display math works also, with

$$ f(x) = x^2 $$

However, if I do \begin{equation} .... \end{equation} it screws up the highlighting for the rest of the document. Typically, I just use $$ anyways...

I haven't tested it extensively... but most latex commands (section, def, ref, cite etc...) display fine. And markdown code blocks are not affected (don't want latex highlighting in your python code!)

The hack is, at line 1788, there is a the inline key parameter. I simply added:

<dict>
<key>include</key>
<string>text.tex.latex</string>
</dict>

to the end of the array of patterns.

i.e.:

    <key>inline</key>
    <dict>
      <key>patterns</key>
      <array>
        <dict>
          <key>include</key>
          <string>#escape</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#ampersand</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#bracket</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#raw</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#bold</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#italic</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#line-break</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#image-inline</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#link-inline</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#link-inet</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#link-email</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#image-ref</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#link-ref-literal</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#link-ref</string>
        </dict>
        <dict>
          <key>include</key>
          <string>text.tex.latex</string>
        </dict>
      </array>
    </dict>
jonschlinkert commented 9 years ago

closing due to age

hadim commented 8 years ago

That would be a really usefull feature since one of the software which make me write markdown is pandoc. And pandoc allows raw LaTex commands.

Could you at least add syntax and color features for two things:

Thank you !

jonschlinkert commented 8 years ago

@hadim can you open a new issue to discuss? thanks