Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Many (La)TeX editors support the LuaTeX engine. However, which one offers the best support for writing LuaTeX? Which editor or plugin supports features such as syntax highlighting and auto-completion for both Lua and (La)TeX?

Common useful features of LaTeX focused IDEs such as integrated viewer, forward and inverse search, structure browser and spell checking are still important, though supplemented by some Lua syntax support.

share|improve this question
3  
There's a huge list of editors with Lua support here: Lua Editor Support. Crossing this with your favourite LaTeX editor shouldn't be too hard. Perhaps the question is do any of the editors support two language syntaxes at once? –  Alan Munn May 23 '11 at 20:47
    
@Alan: thanks for the link! A capable editor supporting two languages at the same time may do, though I'm mainly focused on LaTeX and I like forward and inverse search, integrated viewers and further features of classical LaTeX IDEs - combined with integrated Lua syntax support - I'll edit the question. –  Stefan Kottwitz May 23 '11 at 21:12
    
Not having an IDE and not being free: I really like textmate (macromates.com) because you can (like vim - see Aditya's answer) define regions where the editor switches from LaTeX to Lua syntax. –  topskip May 24 '11 at 5:09
add comment

3 Answers

up vote 12 down vote accepted

Vim supports embedding syntax highlighting of one language in another. I use that to support both MP and Lua syntax highlighting in ConTeXt. regions. The basic trick is do define a syntax region as follows:

syn include @LUA syntax/lua.vim
unlet b:current_syntax

syn region luatex matchgroup=contextIdentifier
      \ start='\\startluacode'
      \ end='\\stopluacode'
      \ contains=@LUA

Then everything inside \startlucode ... \stopluacode will have Lua syntax highlighting. The same idea will also work in LaTeX.

Vim also supports auto-completion, but I don't use that feature so I don't know if language dependent auto-completion is possible or not.

Other requirements, like forward/backward search, spell checking, structure browser, are straight forward, but even then, vim is not what you will call an IDE.

share|improve this answer
    
This does not work for me anyway. I use LaTeX and it may be the reason. Anyway, inspired by your answer I got it works for LuaLaTeX but putting the following in the 'tex.vim' ft plugin file. ... it i too long in a comment, I put it in an answer –  Yan Zhou Aug 22 '11 at 11:03
    
@Yan Zhou: I include them in the syntax/context.vim rather than the ft plugin. For LaTeX, you can consider adapting the default syntax highlighting plugin. –  Aditya Aug 22 '11 at 16:45
    
I did try to include your code (modified for latex) in /after/syntax/tex.vim and that is where the problem happens. My method does not actually require they to be included in specific file, fttype file or even .vimrc will do. –  Yan Zhou Aug 22 '11 at 17:05
add comment

Emacs as well offers syntax highlighting for Lua and LaTeX. I do not know whether there is something like "embedded syntax highlighting" for lua-chunks inside a *.tex-file. Usually you do that by opening the file into an indirect buffer: in the base buffer you get LaTeX-highlighting, in the indirect buffer you change the major mode to lua-mode.

But: this doesn't work with lua-mode yet, at least for me. Independently from changing the mode to lua-mode, Emacs keeps highlighting LaTeX-keywords in the indirect buffer.

Emacs with AucTEX is great for LaTeX, the lua-mode is by far less convenient.

Alexander

share|improve this answer
4  
I wonder if this will be addressed in future versions of AUCTeX? –  BeSlayed May 29 '11 at 1:36
    
Good question. I opened a thread on the auctex-mailinglist, see here: mail-archive.com/auctex@gnu.org , title: »Lua commands in TeX-buffers: highlighting by using indirect buffers?« We will see if more people are interested. A. –  Keks Dose May 29 '11 at 19:29
1  
Thread address: mail-archive.com/auctex@gnu.org/msg04305.html –  Keks Dose May 29 '11 at 19:35
2  
I don't know the status of the mailing lists, but I've actually been able to solve this one: tex.stackexchange.com/a/128724/17423 –  Sean Allred Aug 18 '13 at 2:01
add comment

Aditya's answer does not work for me anyway. I use LaTeX and it may be the reason. Anyway, inspired by your answer I got it works for LuaLaTeX by putting the following in the 'tex.vim' ft plugin file.

autocmd BufWinEnter * if exists("b:current_syntax") && b:current_syntax == "tex"
autocmd BufWinEnter * unlet b:current_syntax
autocmd BufWinEnter * syntax include @TEX syntax/tex.vim
autocmd BufWinEnter * unlet b:current_syntax
autocmd BufWinEnter * syntax include @LUA syntax/lua.vim
autocmd BufWinEnter * syntax region luatex matchgroup=Snip start="%--beginlua--" end="%--endlua--" containedin=@TEX contains=@LUA
autocmd BufWinEnter * syntax region luatex matchgroup=Snip start="--beginlua--" end="--endlua--" containedin=@TEX contains=@LUA
autocmd BufWinEnter * highlight link Snip SpecialComment
autocmd BufWinEnter * let b:current_syntax="luatex"
autocmd BufWinEnter * endif

It should worked by simply put these codes without autocmd BufWinEnter in to the after/syntax/tex.vim file. But in my case that causes some problems and got vim halted. So I use the au to get them executed at the very end of file loading process.

After doing these, everything marked by --beginlua-- and --endlua-- are highlighted as lua code. One can use the version with % in \directlua or luaexec where TeX line comment is allowed but not lua line comment. And the version without % in the \begin{luacode}, etc.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.