tex-conceal.vim icon indicating copy to clipboard operation
tex-conceal.vim copied to clipboard

Possible to conceal \frac{}{}?

Open huijunchen9260 opened this issue 4 years ago • 5 comments

Dear @KeitaNakamura:

It actually shouldn't an issue but just a feature request. I wish it is possible to hide \frac{onething}{something else} into onething / something else. I simply think that would be super cool.

huijunchen9260 avatar May 02 '20 22:05 huijunchen9260

In case onething or something else contained operators like + or -, the meaning could be confused, but if we wrap in parentheses like (onething) / (something else), I think it could be a nice feature.

ddrake avatar May 08 '20 17:05 ddrake

Thanks for your suggestion. I also like the feature, but I have no idea how to implement it.

KeitaNakamura avatar Jun 26 '20 16:06 KeitaNakamura

I've been hacking away at this, and so far I can conceal \frac and leave the concealed line as {onething}/{something else} using

syn match texFrac '\\frac' containedin=texFrac conceal
syn match texFrac "}\zs \ze{" containedin=texFrac conceal cchar=/
syn region texFrac start=/\\frac{/ skip=/} {/ end=/}/  contains=texFrac,texMathSymbol containedin=@texMathZones,texStatement transparent

I could not find a way to conceal }{ as }/{ (that would mean matching zero characters) so I'm having to write \frac{a} {b} instead of \frac{a}{b}. The above code produces Also it would be nice to get it to color the \frac and the brackets.

crivaronicolini avatar Dec 24 '20 20:12 crivaronicolini

syn match texFrac '\\frac' containedin=texFrac conceal
syn match texFrac "}\zs \ze{" containedin=texFrac conceal cchar=/
syn region texFrac start=/\\frac{/ skip=/} {/ end=/}/  contains=texFrac,texMathSymbol containedin=@texMathZones,texStatement transparent

This is really nice. Could you tell me how to implement this in the file? I put those quoted code into the /after/syntax/tex.vim and somehow it is not working.

huijunchen9260 avatar Dec 27 '20 20:12 huijunchen9260

Thanks! I put it at the end of that file in this plugin's directory. If you have vimtex or other latex plugins try disabling them one by one to see if the texZones collide or something. Also you can see if the texFrac region is recognized by appending

hi lin texFrac Error

to the previous lines. It should highlight at least the \frac{ part.

Keep in mind that for now it only works when writing \frac{a} {b}, with a space in between the }{.

crivaronicolini avatar Dec 27 '20 20:12 crivaronicolini