Permalink
Browse files

Merge pull request #1783 from jfdm/contrib/updates

Updates to idrislang.sty
  • Loading branch information...
2 parents 674eb4c + 64f9d19 commit 853c9c56ed58605797a7c287cf54abff4b8851cb @david-christiansen david-christiansen committed Dec 11, 2014
Showing with 39 additions and 18 deletions.
  1. +39 −18 contribs/idrislang.sty
View
@@ -5,46 +5,59 @@
%% + Provides a listings bindings:
%% + idris :: default ascii
%% + literateidris :: convert ascii maths to math symbols.
-%% + Defines a `numbers' and `default' listings style.
+%% + Defines a `numbers', `default', and `stdout' listings style.
+%% + default :: Uses TT font for code and SF font for comments,
+%% and indented by parident.
+%% + numbers :: default but with numbers.
+%% + beamer :: default minus parindent
+%% + stdout :: for formatting stdout.
%% + Defines a `code' environment for typesetting idris.
%% + \begin{code}[...] ... \end{code}
%% + Defines an input command for externally defined idris files.
%% + \inputIdrisListing[...]{file.idr}
+%% + Provides definitions (from Idris Compiler) for pretty-printing Idris
+%% code using Fancy Verbatim and colour commands.
+%% + Sets commandchars for latex commands.
%% + Defines commands typesetting the name Idris.
%% + \Idris{}
%% + \idris{}
%%
%% Options:
%% - literate :: turn on literate idris for code environments.
-%% - numbers :: turn on numbers for code environments.
%%
%% ----------------------------------------------------------- [ Begin Package ]
\ProvidesPackage{idrislang}
\RequirePackage{ifthen}
+\RequirePackage{xcolor}
+\RequirePackage{fancyvrb}
\RequirePackage{listings}
\RequirePackage{xspace}
\RequirePackage{textcomp}
\RequirePackage{setspace}
%% ----------------------------------------------------------------- [ Options ]
\newboolean{literate}
\setboolean{literate}{false}
-\newboolean{numbers}
-\setboolean{numbers}{false}
\DeclareOption{literate}{%
\setboolean{literate}{true}
}
-\DeclareOption{numbers}{%
- \setboolean{numbers}{true}
-}
-
\ProcessOptions\relax
%% ---------------------------------------------------------------- [ Commands ]
\newcommand{\Idris}{\textsc{Idris}\xspace}
\newcommand{\idris}{\textsc{Idris}\xspace}
+\newcommand{\IdrisLineSpacing}{\singlespacing}
+%% ---------------------------------------------------------- [ Color Commands ]
+\newcommand{\IdrisData}[1]{\textcolor{red}{#1}}
+\newcommand{\IdrisType}[1]{\textcolor{blue}{#1}}
+\newcommand{\IdrisBound}[1]{\textcolor{magenta}{#1}}
+\newcommand{\IdrisFunction}[1]{\textcolor{green}{#1}}
+\newcommand{\IdrisKeyword}[1]{{\underline{#1}}}
+\newcommand{\IdrisImplicit}[1]{{\itshape \IdrisBound{#1}}}
+
+\fvset{commandchars=\\\{\}}
%% --------------------------------------------------- [ Define Idris Listings ]
\lstdefinelanguage{idris}{%
@@ -67,7 +80,7 @@
},
%% ------------------------------------------------------- [ Prelude Functions ]
morekeywords={%
- class, data, instance, record, dsl, postulate, default,
+ class, data, instance, record, dsl, postulate, default,
lambda, variable, index_first, index_next
},
%% ---------------------------------------------------------------- [ Comments ]
@@ -89,7 +102,7 @@
{>=}{{$\geq$}}2
{<-}{{$\leftarrow$}}2
{<=}{{$\leq$}}2
- {=>}{{$\Rightarrow$}}2
+ {=>}{{$\Rightarrow$}}2
{==}{{$\equiv$}}2
{\ .}{{$\circ$}}2
{\ .\ }{{$\circ$}}2
@@ -100,26 +113,37 @@
%% -------------------------------------------------- [ Default Listings Style ]
\lstdefinestyle{default}{%
- basicstyle=\ttfamily
+ basicstyle=\ttfamily\normalsize,
}
+
\lstdefinestyle{numbers}{%
numbers=left,
numbersep=10pt,
numberstyle=\footnotesize\sffamily,
frame=leftline
}
+\lstdefinestyle{stdout}{%
+ xleftmargin=\parindent,
+ tabsize=2,
+ basicstyle=\ttfamily\normalsize,
+ showstringspaces=false,
+ escapechar=^
+}
+
+\lstdefinestyle{beamer}{%
+ basicstyle=\ttfamily\normalsize,
+ escapechar=^
+}
+
%% ------------------------------------------------------ [ A Code Environment ]
%% Replicate the existence of literate haskell code environments,
%% option to make pretty with numbers.
\lstnewenvironment{code}[1][]
{\ifthenelse{\boolean{literate}}{%
\lstset{language=literateidris}}{%
\lstset{language=idris}}
- \ifthenelse{\boolean{numbers}}{%
- \lstset{style=numbers, #1}}{%
- \lstset{style=default, #1}}
- \singlespacing
+ \IdrisLineSpacing{}
}{}
%% ---------------------------------------------------------- [ Input Listings ]
%% Command to add externally defined Idris code to the document.
@@ -128,9 +152,6 @@
\ifthenelse{\boolean{literate}}{%
\lstset{language=literateidris}}{%
\lstset{language=idris}}
- \ifthenelse{\boolean{numbers}}{%
- \lstset{style=numbers}}{%
- \lstset{style=default}}
\lstinputlisting[#1]{#2}
\endgroup
}

0 comments on commit 853c9c5

Please sign in to comment.