[TxMt] Re: Pimping the LaTeX grammar - trying to, at least

Daniel Käsmayr 321r7db02 at sneakemail.com
Sat Mar 25 19:40:51 UTC 2006


Dear folks,

I have succeeded, a bit at least. I have been looking for a way to do  
two things:

1. create markup for the different heading types
2. create some kind of mechanism that lets me extend the latex  
grammar without the need to fiddle with the main latex grammar file  
(as I would like to keep my edits separate from those within the svn/ 
official version).

The following is just quick description, I will clarify later if  
there are questions… for now. And I will post some samples somewhere  
if anyone cares.

solution for #2:
start the LaTeX language grammar with:

	patterns = (
		{	include = 'text.latex.user'; },

and define overriding patterns as well as new, custom patterns such  
as stuff you would like for packages you use or macros you defined  
yourself (useful since right now everything starting with \ is  
colored, but in order to catch typos or whatever I like to have my  
custom commands colored in a certain way - thus recognizing them  
easier.)


solution for #1:
add those lines (adapted to each heading that should be styled  
separately) before the main section recognition pattern:

		{	name = 'meta.section.latex';
			begin = '((\\(?:chapter))(\*?)(?:(\[)[^\[]*?(\]))??(\{))';
			end = '(\})';
			captures = { 1 = { name =  
'support.function.section.chapter.latex'; }; };
			patterns = ( { include = 'source.tex'; } );
			contentName = 'entity.name.section';
		},

further notes:
the includes may need to be adapted in the examples in order to  
correctly parse things in bracket within your custom definitions.



Lessons learned:

* You should not create a circular include structure. This will crash  
TextMate
* and thus: save early and save often. Just when does TextMate save  
edited bundles? (I just quit TM, this does the job, but else? i.e.  
after that crash I lost the work of about 2h ;))


Dan



More information about the textmate mailing list