-
Notifications
You must be signed in to change notification settings - Fork 47
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
Change $base
to $self
#185
base: master
Are you sure you want to change the base?
Conversation
The use of `'include': '$base'` causes LaTeX syntax highlighting to not work correctly when embedded in another grammar.
- Allows for use of text.tex.latex and text.tex rules within arbitrary brackets without resorting to using `$base`
I'm pretty sure I accounted for all possible drawbacks of switching from |
With these changes, syntax highlighting when embedded in Markdown works correctly: text:
|
@Aerijo any chance this can get a review? I believe with my edits there are only upsides and no drawbacks. |
@kylebarron Changing {
\begin{fboxverbatim}
foo
\end{fboxverbatim}
} When using How many people use memoir, I don't know. This sort of thing applies to everthing else in memoir and beamer as well. Personally, I believe the better solution is to make a dedicated grammar for embedded latex. It would be bare bones; highlighting commands, math delims (but only the delim itself, not the contents), and avoid any begin/end rules. This way, we still get reasonable highlighting, but no risk of breaking anything. |
I'll check that out when I get back to my computer. |
- Allows for use of `$self` instead of `$base` within text.tex.latex.
@Aerijo These are the rules from memoir and beamer.
As long as these rules don't appear as patterns inside environments changed to Below I've grouped the rules for which the package currently uses
The above rules wouldn't appear within math or literal text, so that leaves programming and environments. I can't imagine any of the above appearing within a named environment or within If you think either of these two rules could allow recursive memoir or beamer text, I propose adding these two rules, with informative comments, to the memoir and beamer files. It's only ~20 lines of repetition, and then we could satisfy all constituents of the package. Programming:
Environments:
Literal text:
Math:
Arbitrary braces clause, currently in
|
Hi @Aerijo , I pushed a commit that catches all Could you please take a look? |
@kylebarron I can't think of anything this breaks. But then again, it's late right now and I'm tired. I'll check back in tomorrow and (probably) merge. My biggest concern was changing |
I've been on vacation the last week and haven't been able to look at this until now. You're right that the most recent commit was misguided, but I still strongly believe that it is both possible and desirable to use the standard LaTeX grammar for embedded purposes. Catching arbitrary I reverted that commit and I contend that the current state is stable without breaking environments.
Your embedded syntax appears to not highlight math at all, which would be a huge step backwards for most users of Markdown, who use LaTeX syntax mostly for math. |
The use of
'include': '$base'
causes LaTeX syntax highlighting to not work correctly when embedded in another grammar. The short summary of the difference between them, from here, is:This means that when
language-latex
is embedded withinlanguage-markdown
, every time an'include': '$base'
occurs, Markdown highlighting is included instead of LaTeX highlighting. Ugliness ensues.Description of the Change
All occurrences of
were replaced with
Alternate Designs
There is no other way to prevent any incorrect highlighting from the
$base
file. A compromise that could theoretically work, but does not in practice is usingThis does not work for this situation because Markdown highlighting is still injected where there should only be LaTeX highlighting. In this example, the HTML injections (part of Markdown syntax) causes the entire rest of the document to be miscolored:
Benefits
Accurate syntax highlighting for grammars that embed LaTeX. I think this is primarily Markdown, however due to the popularity of Pandoc and programs that use it, such as Knitr/R Markdown, this is an important change that would improve a lot of syntax highlighting for math and tables.
Possible Drawbacks
The use of
$self
instead of$base
means that recursive includes happen only within the scope of the inner file, and do not include the rules within the top-level grammar that is embedding the inner file. However with a few included changes, there should be no drawbacks.Currently,
text.tex.latex.beamer
andtext.tex.latex.memoir
includetext.tex.latex
, andtext.tex.latex
includestext.tex
.Including of
text.tex
text.tex
only uses$base
once. That is for anything within arbitrary{ ... }
blocks.language-latex/grammars/tex.cson
Lines 73 to 88 in 2447b74
In order to fix this, I add that rule to the end of
text.tex.latex
and change both toinclude: '$self'
. This should give near-identical highlighting as now. (I could also include this rule fortext.tex.latex.beamer
andtext.tex.latex.memoir
, but this seems unnecessary as those provide few extra rules and are unlikely to be nested within arbitrary{
}
blocks.)Including of
text.tex.latex
The only other side-effects to watch out for are
text.tex.latex.beamer
andtext.tex.latex.memoir
includingtext.tex.latex
. However these side-effects seem rare if not impossible. The extra rules provided withintext.tex.latex.beamer
andtext.tex.latex.memoir
seem top-level only, and they would not be used within any of the environments intext.tex.latex
that currently employ$base
.For example, you would not have
This means that it's fine to have
include: $self
and notinclude: $base
in each of thesetext.tex.latex
environments, because they would not need any special rules from thetext.tex.latex.memoir
ortext.tex.latex.beamer
grammars.Applicable Issues
burodepeper/language-markdown#226