jlelong / vscode-latex-basics

LaTeX grammars for Visual Studio Code
MIT License
19 stars 10 forks source link

Highlight Julia code #14

Closed jlelong closed 2 years ago

jlelong commented 2 years ago

Originally posted by @JamieMair in James-Yu/LaTeX-Workshop#3054

When I am using a package to enable proper typesetting of Julia code, the syntax highlighting does not use the Julia syntax highlighting, but the default latex highlighting. This is shown below: image This becomes an issue when using special characters: image

To Reproduce [Required]

Insert code as shown above. This can be useful for the verbatim package as well.

jlelong commented 2 years ago

@JamieMair Can you post the tex content of your example? What packages are defining the environments juliaconsole and juliaverbatim?

JamieMair commented 2 years ago

I am using a copy of this template - https://github.com/sisl/tufte_algorithms_book

In the introduction.TeX file in the chapters, you can find examples of the Julia related environments working (there a few different ones).

I believe they use a version of the pythontex package with a custom lexer to do the syntax highlighting in the PDF. As far as I can tell, the Julia latex environments are defined in pythontex.sty

Maybe it would be useful to have an optional setting in which you can specify the syntax highlighting for different environments. For example:

"vscode-latex-basics.syntax.environments": {
    "juliaverbatim": ".jl"
    "juliaconsole": ". jl"
... Etc
}
JamieMair commented 2 years ago

Perhaps this line https://github.com/jlelong/vscode-latex-basics/blob/5f26a6daf70352a6f3f40b3b4437a605f5d954ee/syntaxes/LaTeX.tmLanguage.json#L466 needs to be modified to be like https://github.com/jlelong/vscode-latex-basics/blob/5f26a6daf70352a6f3f40b3b4437a605f5d954ee/syntaxes/LaTeX.tmLanguage.json#L485 Which has support for pythontex environments.

JamieMair commented 2 years ago

https://github.com/jlelong/vscode-latex-basics/pull/15 - The proposed changed seemed to work fine.

jlelong commented 2 years ago

Close by #15

jlelong commented 2 years ago

Maybe it would be useful to have an optional setting in which you can specify the syntax highlighting for different environments. For example:

"vscode-latex-basics.syntax.environments": {
    "juliaverbatim": ".jl"
    "juliaconsole": ". jl"
... Etc
}

Unfortunately, it is not possible to use configuration variables in TextMate grammars. Only semantic highlighting can be configured by the user but for the time being we consider it out of the scope of the extension.