[Tex/LaTex] Which is the best editor for LuaTeX

editorsluatex

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.

Best Answer

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.