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:
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










