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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
Does anyone have an opinion here on OSX's TexPad for LuaTeX? I am particularly interested in its limitations, since the staff team is working on its problems but some are unfortunately in OSX itself. – Masi Dec 15 '14 at 21:06
Note: the Lua syntax used in a Lua script and the Lua syntax used by Lua code embedded in (La)TeX code are different. It is best to keep Lua code and LaTeX code in separate files. So, any decent editor is enough. – Paul Gaborit Dec 15 '14 at 22:51
up vote 20 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:

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

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

Then everything inside \startluacode ... \stopluacode will have Lua syntax highlighting. Here is a screenshot showing code from one of my modules (not that the lua comments and the function os.remove inside the \startluacode environment are syntax highlighted)

enter image description here

For completeness, here is a screenshot showing highlighted Metapost code inside a tex file

enter image description here

The same idea will also work in LaTeX, as follows:

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

syn region luatexSnip matchgroup=Snip
    \ start='\\begin{\z(luacode\|luacode*\)}'
    \ end='\\end{\z1}'
    \ contains=@LUA

syn region luatexSnip matchgroup=Snip
    \ start='\\\(directlua\|luadirect\){'
    \ end='}'
    \ contains=@LUA

highlight link Snip SpecialComment

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

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.


share|improve this answer
I wonder if this will be addressed in future versions of AUCTeX? – emacsomancer 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
Thread address: mail-archive.com/auctex@gnu.org/msg04305.html – Keks Dose May 29 '11 at 19:35
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
github.com/vspinu/polymode – student Dec 17 '14 at 11:21

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

I have added this to my fork of VimTex at: https://github.com/frankier/vimtex

You can install it in vim with eg vim-plug like so:

Plug 'frankier/vimtex'
share|improve this answer

I like very much Sublime Text. His multi cursor editing is simply fantastic (I know that now other editors has it too, but it was the first one). It has the possibility to have different highlights inside the same document depending on the context. But I don't know if somebody has created a setting for Lua(La)TeX.

share|improve this answer
This would be an even better answer if you could find or create such a plugin :) – Sean Allred Dec 17 '14 at 21:58
In this document, dated 2001, is described multiple selection in Lapis. The initial release of Sublime TeXt has been done seven years later. – giordano Dec 17 '14 at 21:59
WOOT! I like some features of this editor. It is easy and similar keyboard-shortcuts as in Vim. I would like to have a section -drawer to the left-hand-side like in TexPad. Do you know if it is possible? – Masi Dec 18 '14 at 8:20
In my honest opinion, this is an inevitability with any and every closed-source project. There will come a time when TeXpad will die – some say Sublime is in its death throws as far as development is concerned – but emacs/vi will never die. They may look different in the coming decades, but they will survive up to the end of the keyboard as a primary HCI device. (At least in the case of emacs though, this may be less of a problem than you'd think :) – Just another input mode…) You won't get a more established userbase than either of the professional editors. (I recommend emacs.) – Sean Allred Dec 18 '14 at 13:02
@Masi it is not a team, it is one person (Jon Skinner). And I agree with you that the communication is missing. This is really a weak point of ST. This is probably the most used editor for web development. It is obvious that one person can't communicate alone with entire community ;) And this is a recurrent problem when one person produce a great software. Have you seen how many bug reports are pending for TikZ ? The problem is the same ;) Anyway i'm not selling ST. I'm just saying that I like it. – Kpym Dec 18 '14 at 13:03

Your Answer


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.