sashaafm
Elixir Code listings and snippets in LaTeX?
Hi guys! Has anyone found (or has a way) to insert good Elixir code listing and snippets in LaTeX? Something with automatic color highlights. I’m using the listings package and while it’s got support for a ton of languages (including Erlang) it does not have for Elixir 
I guess I could always insert them as images although I don’t find that to be very correct for a formal document.
Most Liked
vidalraphael
I’m actually writing a paper on concurrency and I’m using tons of Elixir code. ![]()
I’m using the listings package and created a definition for the Elixir lang.
Some things like atoms and module attributes don’t work quite like I would prefer, but it is better than creating images and pasting then all the time ![]()
Here’s the definition:
\lstdefinelanguage{elixir}{
morekeywords={case,catch,def,do,else,false,%
use,alias,receive,timeout,defmacro,defp,%
for,if,import,defmodule,defprotocol,%
nil,defmacrop,defoverridable,defimpl,%
super,fn,raise,true,try,end,with,%
unless},
otherkeywords={<-,->},
sensitive=true,
morecomment=[l]{\#},
morecomment=[n]{/*}{*/},
morestring=[b]",
morestring=[b]',
morestring=[b]"""
}
And here’s the rendered result:
NobbZ
m1dnight
I made some minor changes to this, and ended up with highlighted keywords. The only downside is that a keyword needs to be followed by a space to make the parser happy.
\lstdefinelanguage{elixir}{
morekeywords={case,catch,def,do,else,false,%
use,alias,receive,timeout,defmacro,defp,%
for,if,import,defmodule,defprotocol,%
nil,defmacrop,defoverridable,defimpl,%
super,fn,raise,true,try,end,with,%
unless},
otherkeywords={<-,->, |>, \%\{, \}, \{, \, (, )},
sensitive=true,
morecomment=[l]{\#},
morecomment=[n]{/*}{*/},
morecomment=[s][\color{purple}]{:}{\ },
morestring=[s][\color{orange}]"",
commentstyle=\color{commentgreen},
keywordstyle=\color{eminence},
stringstyle=\color{red},
showstringspaces=false,
}
I have put an entire minimal example online here: Elixir Listings Latex · GitHub
The rendered output looks as follows:
s417-lama
There is another option to do it: a vim plugin to generate listings with colorscheme of vim. It does not depend on syntax highlighting of listings and we can utilize syntax highlighting in vim for LaTeX:) The output looks quite beautiful.
Qqwy
I do not believe there exists a library for LaTeX that does Elixir-highlighting right now. However, as Elixir’s syntax is actually quite regular (i.e. there are not a lot of edge-cases), creating such a library should not be extremely difficult (but, you know, still difficult). There do exist syntax highlighting packages for Sublime, Atom, Emacs and the likes, so maybe some of their logic could be ported to a LaTeX library.









