-
Notifications
You must be signed in to change notification settings - Fork 391
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
Unique nested syntax region names for context-commentstring or tcomment #724
Comments
I assume I could also add support for asymptote. I don't know it or use it myself. It seems to use environments |
Yes, that should be fine. " {{{1 Nested syntax highlighting for asymptote
unlet b:current_syntax
syntax include @ASYMPTOTE syntax/asy.vim
syntax cluster texDocGroup add=texZoneAsymptote
syntax region texZoneAsymptote
\ start='\\begin{asy}'rs=s
\ end='\\end{asy}'re=e
\ keepend
\ transparent
\ contains=texBeginEnd,texBeginEndModifier,@ASYMPTOTE
syntax region texZoneAsymptote
\ start='\\begin{asydef}'rs=s
\ end='\\end{asydef}'re=e
\ keepend
\ transparent
\ contains=texBeginEnd,texBeginEndModifier,@ASYMPTOTE
let b:current_syntax = 'tex'
" }}}1 To see the syntax highlighting and sensitive commenting behaviour in action, you can download the syntax file with
and set if !exists('g:context#commentstring#table')
let g:context#commentstring#table = {}
endif
let g:context#commentstring#table.tex = {
\ 'texZoneLua': '--%s',
\ 'texZoneAsymptote': '//%s',
\ } Shortened example file from http://asymptote.sourceforge.net/doc/LaTeX-usage.html: \documentclass[12pt]{article}
\usepackage[inline]{asymptote}
\begin{document}
\begin{asydef}
// Global Asymptote definitions can be put here.
import three;
usepackage("bm");
texpreamble("\def\V#1{\bm{#1}}");
// One can globally override the default toolbar settings here:
// settings.toolbar=true;
\end{asydef}
Here is a venn diagram produced with Asymptote, drawn to width 4cm:
\def\A{A}
\def\B{\V{B}}
%\begin{figure}
\begin{center}
\begin{asy}
size(4cm,0);
pen colour1=red;
pen colour2=green;
pair z0=(0,0);
pair z1=(-1,0);
pair z2=(1,0);
real r=1.5;
path c1=circle(z1,r);
path c2=circle(z2,r);
fill(c1,colour1);
fill(c2,colour2);
picture intersection=new picture;
fill(intersection,c1,colour1+colour2);
clip(intersection,c2);
add(intersection);
draw(c1);
draw(c2);
// draw("$\A$",box,z1); // Requires [inline] package option.
// draw(Label("$\B$","$B$"),box,z2); // Requires [inline] package option.
draw("$A$",box,z1);
draw("$\V{B}$",box,z2);
pair z=(0,-2);
real m=3;
margin BigMargin=Margin(0,m*dot(unit(z1-z),unit(z0-z)));
draw(Label("$A\cap B$",0),conj(z)--z0,Arrow,BigMargin);
draw(Label("$A\cup B$",0),z--z0,Arrow,BigMargin);
draw(z--z1,Arrow,Margin(0,m));
draw(z--z2,Arrow,Margin(0,m));
shipout(bbox(0.25cm));
\end{asy}
%\caption{Venn diagram}\label{venn}
\end{center}
%\end{figure}
\end{document} I think the syntax file is quite basic, however, it is better than nothing. |
Done, nested syntax for asymptote should work now. |
Has this feature been removed? Following @kiryph instructions, I got it working but with a few bugs: |
There was a minor bug that I've fixed now. Notice, though: The |
Commentary.vim and nested code blocks
I use
commentary.vim
for commenting blocks of code. However, if I am working on a block of lua code inside a tex documentcommentary.vim
uses the wrongcommentstring
.I recently found out that the plugin https://github.com/suy/vim-context-commentstring can adjust the commentstring based on the current syntax region.
Installing this plugin next to commentary+vimtex and adding to
~/.vim/after/ftplugin/tex.vim
the mapping
gcc
to toggle a commented line works as epxected:This works because vimtex defines a nested syntax region in
after/syntax/tex.vim
with the nametexZoneLua
.Unfortunately, it does not work for a other nested constructs such as gnuplottex and luacode environment
because the syntax region name are the same
texZone
.Is it possible to change the shared name
texZone
inafter/syntax/tex.vim
to something which includes the associated filetype as following for exampletcomment
The plugin tcomment.vim supports out of the box embedded/nested code with a different comment character. It is also based on syntax region names and therefore could also take advantage of vimtex syntax rules. The defaults of tcomment.vim are
One would add
g:tcommentSyntaxMap.texZoneLua = 'lua'
.asymptote
Do you like adding support for nested asymptote code (http://asymptote.sourceforge.net/doc/LaTeX-usage.html). There is no default syntax file contained in $VIMRUNTIME, however, upstream of asymptote provides a file https://github.com/vectorgraphics/asymptote/blob/master/base/asy.vim.
Commenting in asymptote is the same as in c/c++ either with
//
or/* */
, see http://asymptote.sourceforge.net/asyRefCard.pdf.The text was updated successfully, but these errors were encountered: