]> gitweb.michael.orlitzky.com - mjotex.git/blob - mjo-listing.tex
Wrap all mjotex files in conditionals to prevent double-loading.
[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 \ifx\havemjolisting\undefined
14 \def\havemjolisting{1}
15
16
17 \usepackage{listings}
18 \usepackage{tcolorbox}
19
20 % Tell tcolorbox to use ``listings'' within the boxes.
21 \tcbuselibrary{listings}
22
23 % Define the colors that we'll use in our listings.
24 \definecolor{codefg}{rgb}{0.9, 0.9, 0.9}
25 \definecolor{codebg}{rgb}{0.16, 0.16, 0.16}
26 \definecolor{brilliantlavender}{rgb}{0.96, 0.73, 1.0}
27 \definecolor{brilliantgreen}{rgb}{0.7, 0.9, 0.7}
28 \definecolor{brown}{rgb}{0.75, 0.4, 0.4}
29
30 % General listing settings.
31 \lstset{%
32 basicstyle=\ttfamily\small,
33 columns=fullflexible,
34 keepspaces=true,
35 showstringspaces=false
36 }
37
38 % Define a style for interactive sage prompt listings.
39 \lstdefinelanguage{sage}{ keywords={sage} }
40 \lstdefinestyle{sage}{
41 commentstyle=\color{brown},
42 keywordstyle=\color{brilliantlavender},
43 stringstyle=\color{brilliantgreen}
44 }
45
46
47 % Input a SageMath example code listing from a file. You generally
48 % want these to be in separate files so that the build system can test
49 % them automatically.
50 %
51 % The sole argument is the "name" of the listing, which ultimately
52 % just identifies a file named "sage_listings/<name>.listing".
53 \newcommand*{\sagelisting}[1]{\tcbinputlisting{listing only,%
54 colback=codebg,%
55 coltext=codefg,%
56 left=2em,%
57 listing options={language=sage,style=sage},%
58 listing file=sage_listings/#1.listing}}
59
60
61 \fi