Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@m1dnight
Last active January 2, 2024 02:53
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save m1dnight/95f405c9c41f208a16df0a68b6ccbfda to your computer and use it in GitHub Desktop.
Save m1dnight/95f405c9c41f208a16df0a68b6ccbfda to your computer and use it in GitHub Desktop.
Elixir Listings Latex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings,xcolor}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage[scaled=0.9]{DejaVuSansMono}
\definecolor{commentgreen}{RGB}{2,112,10}
\definecolor{eminence}{RGB}{108,48,130}
\definecolor{weborange}{RGB}{255,165,0}
\definecolor{frenchplum}{RGB}{129,20,83}
\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},
basicstyle=\ttfamily,
breaklines,
showstringspaces=false,
frame=tb
}
\lstset{numbers=left,xleftmargin=2em,frame=single,framexleftmargin=0em,numberstyle=\footnotesize\ttfamily}
\begin{document}
This is the an example rendering of a piece of code. It contains most of the syntax in Elixir.
Atoms are purple, and have on issue: if they are followed by more text, that is syntax highlighted as well as an atom.
Therefore I made the comma a keyword as well, and used a space as a delimiter for an atom. So if you use a space afterwards, there problem is gone.
\begin{lstlisting}[language=elixir, caption={Super fancy code},captionpos=b]
# A comment
defmodule Foo do
def bar(x) do
string = "hello"
fc = fn x,y -> x + y end
atom = fc.(!\elsymb{:imanatom}!)
atom = fc.(!\elsymb{:because_the_parser_is_not_good_enough}! )
end
end
\end{lstlisting}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment