Last active
January 2, 2024 02:53
-
-
Save m1dnight/95f405c9c41f208a16df0a68b6ccbfda to your computer and use it in GitHub Desktop.
Elixir Listings Latex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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