vim-pandoc-syntax
vim-pandoc-syntax copied to clipboard
'$' breaks highlighting and folding
A dollar sign in single quotes '$'
breaks the highlighting and folding. It has to be escaped '\$'
for the highlighting and folding work again. For example, in
Here the $
in single quotes is concealed.
As a quick fix, one can use backticks: `$`.
Same issue here. Importantly it does also concern fenced code blocks and I can't imagine a workaround that preserves the output of those.
Confirmed still an issue. Notably at least Neovim's build in markdown syntax highlighter does not have this problem.
So this issue is due to a Vim bug? Is there a reasonable workaround by modifying the syntax file?
@Konfekt No no it's bug in this plugin's syntax file. I'm sure there is a way to fix it, somebody just has to do so. I've been triaging a few issue reports and was just confirming that I determined this was/is a bug (as opposed to a question, feature request, etc.).
Do we need to avoid other characters than '
. A general rule that fixes it (as far as i can tell) is
syn region pandocLaTeXInlineMath start=/\v([[:graph:]])@<!\$\S@=/ end=/\v\\@<!\$\d@!/ keepend contains=@LATEX
Maybe [:punct:]
is a better choice.
Why is ([[:graph:]])
or ([[:punct:]])
necessary? Regarding
https://groups.google.com/forum/#!msg/pandoc-discuss/KiyMZn1wFHg/lPUzI8U-KukJ
we have
The opening $ must have a character immediately to its right, while the closing $ must have a character immediately to its left.
Could something like \<@<!\$\S@=
for detecting the opening $
and \S\\@<!\$
for detecting the closing $
be sufficient?
Sure, we can try that out. The rule using [:punct:]
was just an idea.
An option:
syn region pandocLaTeXInlineMath start=/\$\ze\<\S\@=/ end=/\S\zs\\@<!\$/ keepend contains=@LATEX
But it is faulty for the final $
in
'$' a $1$ '$aa$' $a+a$ aa$a aaa
aaaaa aaaa aaa
Shouldn't it be
start=/\<\$\ze\S\@=/ end=/\S\zs\\@<!\$\>/
The first \<
won't match unless keyword is set to include $
, I think. It doesn't work for me, in any case.
Then perhaps something like
start=/[^[:keyword:]]\$\ze\S\@=/ end=/\S\zs\\@<!\$[^[:keyword:]]/
I still have the issue with that. The best I've come up with so far is
start=/\$\ze\<.\{-}\>\$/ end=/\v\\@<!\S\zs\$\d@!/
This version looks for a matching $
in the current line before matching the start pattern. For multiline matches it will not work:
aa$a
a$
It is possible to capture these changing .
with \_.
in the start pattern, but then there are other issues with stuff like
$ '$' a $1$ '$aa$' $a+a$ $ aa$a aaa
aaaaa aaaa a$aa
I don't know how serious a problem this is; I think that having inline math across several lines is probably a mistake in any case.
That is, you want to match
aa$a
a$
? Then start=/[^[:keyword:]]\$\ze\S\@=/
would exclude that. While I find an inline math command spanning more than a single line common, starting an inline math pattern with a character such as a$ ... $
does not look like best practice to me.
Again citing
The opening $ must have a character immediately to its right, while the closing $ must have a character immediately to its left.
this is also not what pandoc
expects for a starting delimiter, but for a closing one.
@Konfekt The example is just to illustrate the kind of problem. It could have just as easily been
a. $...
...$
I also think that multiline math is worth having.
Again, [^[:keyword:]]\$\ze\S\@=
does not work, because it doesn't even match for
$ '$' a $1$ '$aa$'
What I'm trying to do is to prevent the syntax to start the region for cases like this
aaaa. $...
regular text here.
...
EOF
Regarding your example, why is it that Vim does not deem a closing delimiter necessary before starting highlighting ?
I guess you dismissed already for good reason, such as slowness, the rules given in the built-in syntax/tex.vim
such as
syn region texMathZoneX matchgroup=Delimiter start="\$" skip="\\\\\|\\\$" matchgroup=Delimiter end="\$" end="%stopzone\>" concealends contains=@texMathZoneGroup
Also, by
The opening $ must have a character immediately to its right, while the closing $ must have a character immediately to its left.
the matching rules in pandoc
are more restrictive.
Regarding your example, why is it that Vim does not deem a closing delimiter necessary before starting highlighting ?
I think the way it works is it starts highlighting once it finds the match and then it stops when it finds the end region. So it's not really clever. This is one of the reasons we cannot use naive rules for the highlighting.
I don't think the proposed rules are more restrictive besides the corner cases that the spec doesn't talk about (for example, what happens when a paragraph ends after a $
). This is what the manual says:
Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for some reason you need to enclose text in literal $ characters, backslash-escape them and they won’t be treated as math delimiters.
What I have now is
syn region pandocLaTeXInlineMath start=/\\\@<!\$\ze\<\_.\{-}\>\$/ skip=/\\\$/ end=/\v\\@<!\S\zs\$\d@!/ end=/\n\s*\n/ keepend contains=@LATEX
This still has problems with dangling $...
at the end of a line, but covers all the other cases.
EDIT: And the TeX rule simply gives the wrong rendering, it is too liberal.