-
Notifications
You must be signed in to change notification settings - Fork 5
/
code.tex
85 lines (75 loc) · 2.9 KB
/
code.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
\chapter{Code}\label{cha:code}
You can put code in your document using the \texttt{listings} package, which is
loaded. Be aware that the \texttt{listings}
package does not put code in your document if you are in draft mode
unless you give it the \texttt{final} option.
There is an example java (Listing~\ref{src:Data_Bus.java}) and XML
file (Listing~\ref{src:AndroidManifest.xml}). Thanks to the
\texttt{url} package, you can typeset OSX and unix paths like this:
\path{/afs/rnd.ru.is/project/thesis-template}. Windows paths:
\path{C:\windows\temp\ }. Note: The \texttt{menukey} package has
similar functionality but may cause problems.
If you are trying to include multiple different languages, you should
go read the documentation and set these up as below. You
will save yourself a lot of effort, especially if you have to fix
anything.
%% This default style make long lines wrap nicely
\lstdefinestyle{default}{
%basicstyle=\footnotesize\ttfamily,%
numbers=left,%
numberstyle=\tiny,%
numberfirstline=true,%
stepnumber=2,%
numbersep=5pt,%
columns=fullflexible,%
tabsize=4,%
frame=lines,%
breaklines=true,% break long lines
prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookleftarrow}}, % red arrow
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow}}, % red arrow
% from http://tex.stackexchange.com/questions/116534/lstlisting-line-wrapping
}
\lstset{%
language=,%default similar to verbatim
style=default,
}
%% The pre-defined languages we want to use.
\lstloadlanguages{Java, XML}
%% We can also define a new language (so we can change some formatting)
%% Be careful you do not make a recursive style nor language!!
%% You can just use the XML language, or in this case create a "dialect"
\lstdefinelanguage[android]{XML}%
{ %
sensitive=false,% case-insensitive
classoffset=0, % first class
morekeywords={manifest},
classoffset=1, % second class
morekeywords={uses, sdk, application, activity},
keywordstyle=\color{blue}, % set a color
classoffset=0, % reset back to 0
}
%% We use listing styles to adjust the appearance
%% Be careful you do not make a recursive style nor language!!
%% This makes use of the listing package to show program output
\lstdefinestyle{progoutput}{
language=sh,
frame=single,
breaklines=true,
prebreak=\textbackslash,
captionpos=b,
basicstyle=\small\ttfamily,
showstringspaces=false
}
%%I have put the source code in the \directory{src/} folder.
\lstinputlisting[language=Java, firstline=1,
lastline=40, caption={Data\_Bus.java: Setting up the class.},
label={src:Data_Bus.java}]{src/Data_Bus.java}
\lstinputlisting[language={[android]XML}, firstline=1, lastline=20,
caption={AndroidManifest.xml: Configuration for the Android UI.},
label={src:AndroidManifest.xml}]{src/AndroidManifest.xml}
%% TODO: fix wrapping from custom.sty
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% TeX-engine: luatex
%%% End: