]> gitweb.michael.orlitzky.com - mjotex.git/blob - mjo-listing.tex
Add the \sagelisting macro and associated machinery.
[mjotex.git] / mjo-listing.tex
1 %
2 % Code listing support, in particular, for the SageMath interactive
3 % prompt. You can create a box thingy for displaying code like,
4 %
5 % \begin{tcblisting}{listing only,
6 % colback=codebg,
7 % coltext=codefg,
8 % listing options={language=sage,style=sage}}
9 % sage: x
10 % x
11 % \end{tcblisting}
12 %
13 \usepackage{listings}
14 \usepackage{tcolorbox}
15
16 % Tell tcolorbox to use ``listings'' within the boxes.
17 \tcbuselibrary{listings}
18
19 % Define the colors that we'll use in our listings.
20 \definecolor{codefg}{rgb}{0.9, 0.9, 0.9}
21 \definecolor{codebg}{rgb}{0.16, 0.16, 0.16}
22 \definecolor{brilliantlavender}{rgb}{0.96, 0.73, 1.0}
23 \definecolor{brilliantgreen}{rgb}{0.7, 0.9, 0.7}
24 \definecolor{brown}{rgb}{0.75, 0.4, 0.4}
25
26 % General listing settings.
27 \lstset{%
28 basicstyle=\ttfamily\small,
29 columns=fullflexible,
30 keepspaces=true,
31 showstringspaces=false
32 }
33
34 % Define a style for interactive sage prompt listings.
35 \lstdefinelanguage{sage}{ keywords={sage} }
36 \lstdefinestyle{sage}{
37 commentstyle=\color{brown},
38 keywordstyle=\color{brilliantlavender},
39 stringstyle=\color{brilliantgreen}
40 }
41
42
43 % Input a SageMath example code listing from a file. You generally
44 % want these to be in separate files so that the build system can test
45 % them automatically.
46 %
47 % The sole argument is the "name" of the listing, which ultimately
48 % just identifies a file named "sage_listings/<name>.listing".
49 \newcommand*{\sagelisting}[1]{\tcbinputlisting{listing only,%
50 colback=codebg,%
51 coltext=codefg,%
52 left=2em,%
53 listing options={language=sage,style=sage},%
54 listing file=sage_listings/#1.listing}}