Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LaTeX] rewrite syntaxes #370

Merged
merged 56 commits into from
Jul 22, 2016
Merged

[LaTeX] rewrite syntaxes #370

merged 56 commits into from
Jul 22, 2016

Conversation

randy3k
Copy link
Contributor

@randy3k randy3k commented May 9, 2016

close #340

The follow up PR for #340, things to be done

  • syntax_test files
  • ~~~handle accents~~~ (It seems it is not necessary)
  • math scope naming (no objection?)
  • itemize/enumerate etc scope naming (no objection?)
  • remove incompatible regex patterns
  • fix R/Rd (R Documentation) and Haskell/Literate Haskell
  • cite commands
  • POSIX regex
  • minted package

There are many changes, I just list the important breaking changes

  • math mode: string.other.math.tex -> meta.environment.math
  • itemize/enumerate/description/list scopes are now
    • meta.environment.list.itemize.latex
    • meta.environment.list.enumerate.latex
    • meta.environment.list.description.latex
    • meta.environment.list.list.latex
  • Added symbol lists for labels and sections
  • The syntaxes for Beamer and Memoir were removed (I think no one is actually using these syntax files).
    External packages' support can be added to the packages pattern of LaTeX syntax.

@csch0 @msiniscalchi @ig0774 Do you have any comments? This PR will certainly break your packages. We might have to discuss the naming convention of the scopes.

@randy3k randy3k force-pushed the latex branch 11 times, most recently from 632c39b to e753c50 Compare May 9, 2016 20:46
@wbond
Copy link
Member

wbond commented May 10, 2016

I added a list item to remove incompatible regex patterns

@wbond
Copy link
Member

wbond commented May 10, 2016

This will also affect the R/Rd (R Documentation).sublime-syntax and Haskell/Literate Haskell.sublime-syntax files.

@randy3k randy3k force-pushed the latex branch 2 times, most recently from 8ea5672 to cac8db8 Compare May 10, 2016 16:28
@randy3k
Copy link
Contributor Author

randy3k commented May 10, 2016

Will fix them too.

@randy3k randy3k force-pushed the latex branch 2 times, most recently from 8eddab1 to 4a0c364 Compare May 10, 2016 18:02
@r-stein
Copy link
Contributor

r-stein commented May 10, 2016

Just a few points:

  • It would be nice to add \ensuremath to the math commands
  • I think it would be useful to add a meta scope for environments in which the tex commands are treated verbatim, e.g. lstlisting or verbatim. A usecase would be to define keybindings like:
  {
    "keys": ["\""], "command": "insert_snippet", "args": {"contents": "``$0''"},  "context": [
      { "key": "selector", "operator": "equal", "operand": "text.tex.latex - (meta.environment.verbatim.latex, meta.environment.math.latex)" }
    ]
  }
  • are you planing to support more packages (e.g. minted, comment,...) and additional listing languages?

@randy3k
Copy link
Contributor Author

randy3k commented May 10, 2016

  • \ensuremath sounds like a good idea.
  • verbatim now receives the scope meta.function.verbatim.latex, but to be consistent, I guess it should be renamed as meta.environment.verbatim.latex.
  • the plan is to add packages which are commonly used. And adding such packages should help in highlighting or defining keybinds.

@ig0774
Copy link

ig0774 commented May 10, 2016

One regression I've noticed is that this syntax doesn't properly handle commands in optional arguments where there is a specific rule for the main command. For example, in a command like:

\makebox[\linewidth]{...}

\linewidth isn't properly recognised as a command.

@randy3k
Copy link
Contributor Author

randy3k commented May 11, 2016

The issue related optional arguments is new to this syntax as the original syntax doesn't detect optional arguments at all (at least for \makebox). I have an idea on how to fix it, but it will take some time since I want to do it more generally.

@randy3k randy3k force-pushed the latex branch 3 times, most recently from 0ef2120 to 0b3d250 Compare May 11, 2016 05:20
@r-stein
Copy link
Contributor

r-stein commented May 11, 2016

General ST question: is it possible (in the colorscheme or elsewhere) to present a scope in super- or subscript position? It would be nice to show something like $x^2$ as $x^²$.

@FichteFoll
Copy link
Collaborator

FichteFoll commented May 11, 2016

No.
Only regular, bold and italics are supported. Textmate also supports underline, but Sublime Text does not render this.

I also wouldn't be too pleased by this tbh.

@r-stein
Copy link
Contributor

r-stein commented May 11, 2016

Okay thanks. I personally think this and named foldings like \alpha to α and \label{...} to [l] increases the readability of tex files.

@randy3k
Copy link
Contributor Author

randy3k commented May 11, 2016

@r-stein I would let other packages to handle it. Some users may not like this idea.

@r-stein
Copy link
Contributor

r-stein commented May 11, 2016

@randy3k As far ich know this is not possible in ST, it was just a general comment :)

@wbond
Copy link
Member

wbond commented Jul 15, 2016

@Eyenseo Yes, syntaxes are global to Sublime Text, and are not per-project.

@@ -552,7 +552,7 @@ contexts:
4: variable.parameter.function.latex
5: punctuation.definition.group.brace.end.latex
push:
- meta_scope: meta.environment.math.block.be.latex
- meta_content_scope: meta.environment.math.block.be.latex
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, shall this also be applied to \[\] and \(\) and $$ and $ pairs?
Though, it may break BracketHighlighter or make BracketHighlighter hard to highlight brackets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not apply this to those pairs, because it would break bracket highlighter and I don't see disadvantages for it.
Since it should have the same or a special highlighting and it has only 1-2 chars and is therefore to short to use hotkeys inside. However I agree, that it might look less consistent.
Nonetheless I think this is the best solution to do it like this.

@FichteFoll
Copy link
Collaborator

FichteFoll commented Jul 16, 2016

I've been using this syntax for a while now and reported everything I noticed so far. This is obviously a great improvement over the current LaTeX syntax but people will need to adapt to changes since things are highlighted differently now (e.g. entity.name.label for \label definitions) but more consistent. When JavaScript was changed they had to as well and that affected a lot more people.

The only remaining thing is inline Python highlighting which is seemingly broken "just for me". Since I did work on the syntax that relates to the resulting highlighting, I should be able to know why it behaves that way, but I don't just from thinking about it and I lack the time to actually investigate into it. I have a couple more changes planned for the Python syntax and will take a look at this again once I find time for that.

So far, this is getting a big 👍 from me. If users spot errors once they start using the changes in their setup, we can always fix those later.

@ig0774
Copy link

ig0774 commented Jul 16, 2016

I agree this is a major improvement over the previous syntax.

One small regression I've noticed is that commands in optional brackets after \cite commands don't get highlighted properly. (The same thing happens with \ref, but I don't think any of the major variants of \ref allow optional arguments anyways).

screen shot 2016-07-16 at 15 17 15

Not really a big a deal though.

@randy3k
Copy link
Contributor Author

randy3k commented Jul 17, 2016

@ig0774 fixed.

@r-stein
Copy link
Contributor

r-stein commented Jul 17, 2016

It might be worth to discuss to omit the scope punctuation.definition.backslash.latex for each \ in the commands (\command), because ST seems to change the soft wrap behavior.
See also https://forum.sublimetext.com/t/word-wrapping-in-latex-files-st-st2/1403 and SublimeText/LaTeXTools#643

@randy3k
Copy link
Contributor Author

randy3k commented Jul 17, 2016

Firstly, just want to clarify, it does not seem that I have the splitting issue.

Secondly, I would rather keep the scope for potential different highlight via color scheme. Some users may be interested in highlighting backslashes with a different color.

@ig0774
Copy link

ig0774 commented Jul 17, 2016

It still occurs for me with the latest version of the syntax:

screen shot

Frankly, however, I'm indifferent to what is done. For me, syntax highlighting still makes it clear its a command when the wrapping occurs, and I can see some small benefit to being able to highlight backslashes.

@randy3k
Copy link
Contributor Author

randy3k commented Jul 17, 2016

I see, I could reproduce it now. My suggestion is to not do soft wrap, do hard wrap instead. Hard wrap also improves the results in reverse synctex search from the pdf.

@r-stein
Copy link
Contributor

r-stein commented Jul 20, 2016

Small remark: math is currently not highlighted inside \newcommand:

example_math

@randy3k
Copy link
Contributor Author

randy3k commented Jul 20, 2016

@r-stein it is intended. The content inside the bracket can create all sort of issues.

Consider

\newcommand{\foo}{\begin{equation}}
\newcommand{\bla}{\[}

If we start to match the content, it will be difficult to close the scope, so only commands and constants are highlighted inside the bracket. This is actually the whole reason I started this re-write.

@r-stein
Copy link
Contributor

r-stein commented Jul 20, 2016

Ah okay I agree.

@wbond
Copy link
Member

wbond commented Jul 22, 2016

Thank you for all of your work on this @randy3k.

And thank you to everyone who has been reviewing it and giving feedback.

@musm
Copy link

musm commented Jul 28, 2016

I tried testing this out. I placed the LaTeX directory obtained from github to %appdata%/Sublime Text 3/Packages

Firing a tex document gives:
image

@randy3k randy3k deleted the latex branch September 11, 2016 05:56
deathaxe pushed a commit to deathaxe/sublime-packages that referenced this pull request Aug 24, 2019
Fixes sublimehq#608

The issue was partly fixed by PR sublimehq#370. This commit adds support for
highlighting XML/HTML inside \begin{minted}{...} ... \end{minted}.
wbond pushed a commit that referenced this pull request Oct 18, 2019
Fixes #608

The issue was partly fixed by PR #370. This commit adds support for
highlighting XML/HTML inside \begin{minted}{...} ... \end{minted}.
mitranim pushed a commit to mitranim/Packages that referenced this pull request Mar 25, 2022
Fixes sublimehq#608

The issue was partly fixed by PR sublimehq#370. This commit adds support for
highlighting XML/HTML inside \begin{minted}{...} ... \end{minted}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite the LaTeX syntax
8 participants