vim-pandoc / vim-pandoc-syntax

pandoc markdown syntax, to be installed alongside vim-pandoc
MIT License
425 stars 61 forks source link

Latex within \begin{...} environments not concealed #306

Open dzackgarza opened 4 years ago

dzackgarza commented 4 years ago

Here's a quick example of what I'm looking at:

image

Here, the inline \begin{align*} ... \end{align*} is valid Pandoc syntax for embedded Latex, and it looks like syntax highlighting is applied but not the concealing.

(I've copied the same line down to 158 and surrounded it with $ ... $, which shows how it's concealed elsewhere.)

Incidentally, the underscores seem to be highlighted as spelling mistakes -- if there's a known way to disable spell-checking within those environments, please let me know!

alerque commented 4 years ago

I haven't looked into specifics but off the top of my head this is probably something we won't actually "fix" because fixing it would break more situations than it repairs. I can understand in your example why you would want conceal to work, but I can also imagine far more situations where messing with conceals inside a block of LaTeX that we can't fully parse is probably a really bad idea.

dzackgarza commented 4 years ago

Seems reasonable, although I'd be perfectly happy in my case to blindly apply syntax highlighting/concealing to the special case of anything between (e.g.) \begin{align} and \end{align}.

If this is something that would be considered for the project, do you have any ideas for how this might be done? (I'd be fine with just branching for my particular use case.)

alerque commented 4 years ago

I'd be happy to allow this as part of the main plugin behind a (default off) option flag. It's probably just a matter of finding the syntax groups in question and noting what other groups or features are allowed inside that. We're clearly already finding the LaTeX block, so you just need to allow other things inside that.

avivrosenberg commented 4 years ago

@dzackgarza did you prehaps find a fix/workaround for the \begin{align} and \end{align} case?

dzackgarza commented 4 years ago

@avivrosenberg Unfortunately not, and I don't quite know enough to figure out how to patch it in either! I imagine this must be taken care of in some other latex-specific plugins, but I couldn't find any good references to go off of.

rnhmjoj commented 3 years ago

Surprising, conceal works inside an eqnarray. This suggets it's only a matter of allowing the right environment.

Update: This seems to work because eqnarray is a standard LaTeX environment and has an ad-hoc highlight match group in tex.vim. So here's a trick, do

:call TexNewMathZone("D", "align", 1)
:call TexNewMathZone("E", "align*", 1)

Now conceal should work in align and align* as well.

0az commented 3 years ago

One cool trick that I lack the knowledge to implement would be figuring out how to use vimtex's more comprehensive syntax instead of the default.

Vimtex supports align/align* under texMathZoneAmsA/texMathZoneAmsAS respectively.

For now, I just switch back and forth between the filetypes.

fmoralesc commented 3 years ago

@0az I think the easiest way to do it would be to change

syn include @LATEX syntax/tex.vim

in the syntax file so it points to vimtex's syntax file. Haven't tested it though. If it works, we could try checking if the file exists and using that conditionally.

a-torgovitsky commented 3 years ago

Being able to use vimtex's syntax highlighting would be really helpful. Is there an easy way to do this manually?

tomtomjhj commented 3 years ago

My attempt to use vimtex(>=2.0)'s syntax: https://github.com/tomtomjhj/vim-pandoc-syntax/commit/ddb948fddf3ef602abe97e8e8d4931c03199aed7