Skip to content

Commit aec384b

Browse files
namasikanamMM45
authored andcommitted
Add a LaTeX formatting style file
Co-authored-by: Matthias Meijers <m.c.f.h.p.meijers@tue.nl>
1 parent c5ddeca commit aec384b

2 files changed

Lines changed: 164 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ EasyCrypt is part of the [Formosa Crypto project](https://formosa-crypto.org/).
2626
- [Visual Studio Code](#visual-studio-code)
2727
- [Useful Resources](#useful-resources)
2828
- [Examples](#examples)
29+
- [LaTeX Formatting](#latex-formatting)
2930

3031
# Installation
3132

@@ -185,3 +186,10 @@ Examples of how to use EasyCrypt are in the `examples` directory. You
185186
will find basic examples at the root of this directory, as well as a
186187
more advanced example in the `MEE-CBC` sub-directory and a tutorial on
187188
how to use the complexity system in `cost` sub-directory.
189+
190+
## LaTeX Formatting
191+
192+
LaTeX style file is in `assets/latex` directory. The basic usages are
193+
`\begin{eclst} ... \end{eclst}` (display mode) and
194+
`\ecinl{proc main() = { ... }}` (inline mode).
195+

assets/latex/eclistings.sty

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
\NeedsTeXFormat{LaTeX2e}
2+
\ProvidesPackage{eclistings}[2026/04/07 EasyCrypt listings]
3+
4+
\RequirePackage{listings}
5+
\RequirePackage{xcolor}
6+
\RequirePackage{xparse}
7+
8+
% EasyCrypt %
9+
% Language
10+
\lstdefinelanguage{easycrypt}{%
11+
sensitive=true, % Case sensitive keywords
12+
% Keywords: Meta/Specification language
13+
morekeywords=[1]%
14+
{
15+
abbrev, abstract, as, assert, async, axiom, axiomatized, class, clone,
16+
const, debug, declare, eager, ehoare, elif, else, end, equiv, exists, exit,
17+
export, fail, for, forall, from, fun, glob, global, goal, hint, hoare, if,
18+
import, in, include, inductive, instance, islossless, lemma, let, local, locate,
19+
match, module, nosmt, notation, of, op, phoare, pragma, Pr, pred, print, proc,
20+
proof, prover, qed, quantum, realize, remove, rename, require, res, return,
21+
search, section, Self, subtype, then, theory, time, timeout, Top, type,
22+
undo, var, while, why3, with
23+
},
24+
% Keywords: Regular (i.e., non-closing) tactics
25+
morekeywords=[2]%
26+
{
27+
algebra, alias, apply, async, auto, beta,
28+
byequiv, byphoare, bypr, call, case, cbv, cfold,
29+
change, clear, congr, conseq, cut, delta, dump,
30+
ecall, elim, eta, exfalso, exlim, fel, field, fieldeq, fission,
31+
fusion, gen, have, hoare, idtac, inline, interleave, iota, kill, left, logic,
32+
modpath, move, outline, pose, pr_bounded, progress, rcondf,
33+
rcondt, replace, rewrite, right, ring, ringeq, rnd, rndsem, rwnormal,
34+
seq, sim, simplify, skip, sp, split, splitwhile, subst,
35+
suff, swap, symmetry, transitivity, trivial, unroll, weakmem, wlog,
36+
wp, zeta
37+
},
38+
% Keywords: Closing tactics/tacticals
39+
morekeywords=[3]%
40+
{
41+
abort, admit, admitted, assumption, by, check, done,
42+
edit, exact, fix, reflexivity, smt, solve
43+
},
44+
% Keywords: Tacticals
45+
morekeywords=[4]%
46+
{
47+
do, expect, first, last, strict, try
48+
},
49+
comment=[n]{(*}{*)}, % Multi-line, nested comments delimited by (* and *)
50+
string=[d]{"}, % Strings delimited by " and ", non-escapable
51+
}
52+
53+
% Style (base/default)
54+
\lstdefinestyle{easycrypt-base}{%
55+
% Frame
56+
captionpos=t, % Position caption at top (mirroring what's typical for algorithms)
57+
frame=tb, % Top and bottom rules
58+
framesep=\smallskipamount, % Small skip between frame and listing content
59+
% Float placement
60+
floatplacement=tbhp,
61+
% Character printing and placement
62+
upquote=true, % Print backtick and single quote as is
63+
columns=[c]fixed, % Monospace characters, centered in their box
64+
keepspaces=true, % Don't drop spaces for column alignment
65+
tabsize=2, % Tabstops every 2 spaces
66+
mathescape=false, % Don't allow escaping to LaTeX with $
67+
showstringspaces=false, % Don't print characters for spaces
68+
% Line numbers
69+
numbers=none, % No line numbers
70+
% Basic style
71+
basicstyle={\normalsize\ttfamily},
72+
% Style for (non-keyword) identifiers
73+
identifierstyle={},
74+
}
75+
76+
% Define default colors based on availability of colorblind colors
77+
\makeatletter
78+
\@ifpackageloaded{colorblind}{
79+
\lstdefinestyle{easycrypt-default}{%
80+
style=easycrypt-base,
81+
% Styles for different keyword classes
82+
keywordstyle=[1]{\color{T-Q-B6}},%
83+
keywordstyle=[2]{\color{T-Q-B1}},%
84+
keywordstyle=[3]{\color{T-Q-B5}},%
85+
keywordstyle=[4]{\color{T-Q-B4}},%
86+
% Styles for comments and strings
87+
commentstyle={\itshape\color{T-Q-B0}},%
88+
stringstyle={\color{T-Q-B3}},
89+
% Style of line numbers (in case numbers is overwritten to true)
90+
numberstyle={\small\color{T-Q-B0}},
91+
}
92+
}{%
93+
\lstdefinestyle{easycrypt-default}{%
94+
style=easycrypt-base,
95+
% Styles for different keyword classes
96+
keywordstyle=[1]{\color{violet}},%
97+
keywordstyle=[2]{\color{blue}},%
98+
keywordstyle=[3]{\color{red}},%
99+
keywordstyle=[4]{\color{olive}},%
100+
% Styles for comments and strings
101+
commentstyle={\itshape\color{gray}},%
102+
stringstyle={\color{green}},
103+
% Style of line numbers (in case numbers is overwritten to true)
104+
numberstyle={\small\color{gray}},
105+
}
106+
}
107+
\makeatother
108+
109+
% Style for drafting/debugging (explicit spaces/tabs)
110+
\lstdefinestyle{easycrypt-draft}{%
111+
style=easycrypt-default,
112+
showspaces=true,
113+
showtabs=true,
114+
showstringspaces=true,
115+
}
116+
117+
% Style without top/bottom frame rules
118+
\lstdefinestyle{easycrypt-plain}{%
119+
style=easycrypt-default,
120+
frame=none,
121+
framesep=0pt,
122+
}
123+
124+
% Environments
125+
%% Default, non-floating environment
126+
%% Meant to be used inside other (potentially floating) environment
127+
%% that takes care of the caption and surrounding spacing
128+
\lstnewenvironment{eclst}[1][]{%
129+
\lstset{%
130+
language=easycrypt,%
131+
style=easycrypt-default,%
132+
aboveskip=\smallskipamount,% Equal to framesep of style if top rule, else 0pt
133+
belowskip=\smallskipamount,% Equal to framesep of style if bottom rule, else 0pt
134+
abovecaptionskip=0pt,%
135+
belowcaptionskip=0pt,%
136+
#1%
137+
}%
138+
}{}
139+
140+
% Inline
141+
\NewDocumentCommand{\ecinl}{O{easycrypt-default} m O{}}{%
142+
\lstinline[%
143+
language=easycrypt,%
144+
style=#1,%
145+
breaklines,%
146+
breakindent=0pt,%
147+
columns=fullflexible,%
148+
#3%
149+
]{#2}%
150+
}
151+
152+
\NewDocumentCommand{\ecinlfoot}{O{easycrypt-default} m O{}}{%
153+
\ecinl[#1]{#2}[basicstyle={\footnotesize\ttfamily},#3]%
154+
}
155+
156+
\endinput

0 commit comments

Comments
 (0)