forked from markroyer/latex-syllabus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlstcustom.sty
More file actions
223 lines (190 loc) · 5.97 KB
/
lstcustom.sty
File metadata and controls
223 lines (190 loc) · 5.97 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
% This is a nice eclipse-like style for displaying Java with the
% listings package. I originally found it here
%
% http://trac.rtsys.informatik.uni-kiel.de/trac/rtsys/attachment/wiki/Latex/Listings/lstcustom.sty
%
% and modified it so that it was just for Java. I also added some
% more markup for Javadoc and anything else I could think of.
%
% Requires texlive-fonts-extra package for beramono.sty
%
% Modified by Mark Royer
%
\usepackage{color}
\usepackage{etoolbox}
\usepackage{listings}
\usepackage[T1]{fontenc}
% beramono or luximono give very nice ttfamily fonts
\usepackage[scaled=0.8]{beramono}
%\usepackage[scaled=0.8]{luximono}
% Use the ttfamily font here will be used below
\newcommand{\lstfontfamily}{\ttfamily}
% Some useful colors...
\definecolor{darkviolet}{rgb}{0.5,0,0.4}
\definecolor{darkgreen}{rgb}{0,0.4,0.2}
\definecolor{darkblue}{rgb}{0.1,0.1,0.9}
\definecolor{darkgrey}{rgb}{0.5,0.5,0.5}
\definecolor{lightblue}{rgb}{0.4,0.4,1}
\definecolor{stringColor}{rgb}{0.16,0.00,1.00}
\definecolor{fieldColor}{rgb}{0.16,0.00,1.00}
\definecolor{annotationColor}{rgb}{0.39,0.39,0.39}
\definecolor{keywordColor}{rgb}{0.50,0.00,0.33}
\definecolor{commentColor}{rgb}{0.25,0.50,0.37}
\definecolor{javadocColor}{rgb}{0.25,0.37,0.75}
\definecolor{jTagColor}{rgb}{0.50,0.62,0.75}
\definecolor{eTagColor}{rgb}{0.50,0.62,0.75}
\definecolor{lineNumberColor}{rgb}{0.47,0.47,0.47}
% Additional keywords that may be missing
%\makeatletter
%\lst@InstallKeywords k{attributes}{attributestyle}\slshape{attributestyle}{}ld
%\makeatother
% Here are the Javadoc tags and the version they were introduced based on the Java 7 docs here:
%
% http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javadoc.html#javadoctags
%
% Currently does not handle the tags that are surrounded by brackets for example {@code}.
%
% @author 1.0
% {@code} 1.5
% {@docRoot} 1.3
% @deprecated 1.0
% @exception 1.0
% {@inheritDoc} 1.4
% {@link} 1.2
% {@linkplain} 1.4
% {@literal} 1.5
% @param 1.0
% @return 1.0
% @see 1.0
% @serial 1.2
% @serialData 1.2
% @serialField 1.2
% @since 1.1
% @throws 1.2
% {@value} 1.4
% @version 1.0
% Inline tags not added to the list
\def\jTags{@author, @deprecated, @exception, @param, @return, @see, @serial, @serialData, @serialField, @since, @throws, @version}
% Here is standard annotations as listed here:
%
% http://en.wikipedia.org/wiki/Java_annotation
%
% @Override - Checks that the function is an override. Causes a compile warning if the function is not found in one of the parent classes.
% @Deprecated - Marks the function as obsolete. Causes a compile warning if the function is used.
% @SuppressWarnings - Instructs the compiler to suppress the compile time warnings specified in the annotation parameters
%
% Annotations applied to other annotations:
%
% @Retention - Specifies how the marked annotation is stored -- Whether in code only, compiled into the class, or available at runtime through reflection.
% @Documented - Marks another annotation for inclusion in the documentation.
% @Target - Marks another annotation to restrict what kind of java elements the annotation may be applied to
% @Inherited - Marks another annotation to inherit features from a parent annotation
\def\jAnnotations{
classoffset=1,
morekeywords={@Override, @Deperecated, @SuppressWarnings, @Retention, @Documented, @Target, @Inherited},
keywordstyle=\color{annotationColor},
classoffset=0
}
% Eclipse Task Tags
\def\eTags{FIXME, TODO, XXX}
%
% Markup Javadoc code. If it's a Tag, bold it.
%
\newrobustcmd{\markupJavadocs}[1]{%
\edef\mytok{\the\lst@token}%
\renewcommand*{\do}[1]{%
\ifdefstring{\mytok}{##1}%
{\color{jTagColor}\bfseries\listbreak}%
{}%
}%
{\color{javadocColor}%
\expandafter\docsvlist\expandafter{\jTags}%
\renewcommand*{\do}[1]{%
\ifdefstring{\mytok}{##1}%
{\color{eTagColor}\bfseries\listbreak}%
{}%
}%
\expandafter\docsvlist\expandafter{\eTags}%
#1}%
}%
%
% Markup regular comment. If it's a Tag, bold it.
%
\newrobustcmd{\markupComments}[1]{%
\edef\mytok{\the\lst@token}%
\renewcommand*{\do}[1]{%
\ifdefstring{\mytok}{##1}%
{\color{eTagColor}\bfseries\listbreak}%
{}%
}%
{\color{commentColor}%
\expandafter\docsvlist\expandafter{\eTags}#1}%
}%
% For manual eclipse field styling
\newrobustcmd{\ef}[1]{%
{\color{fieldColor}\lstfontfamily#1}%
}
\newrobustcmd{\efi}[1]{%
{\color{fieldColor}\it\lstfontfamily#1}%
}
% For manual eclipse comment styling
\newrobustcmd{\ecom}[1]{%
{\color{commentColor}\lstfontfamily#1}%
}
\newrobustcmd{\ecomi}[1]{%
{\color{commentColor}\it\lstfontfamily#1}%
}
\lstdefinestyle{eclipse}{
basicstyle={\lstfontfamily},
emphstyle=\bfseries,
keywordstyle=\color{keywordColor}\bfseries,
commentstyle=\markupComments,
stringstyle=\color{stringColor},
numberstyle=\color{lineNumberColor}\lstfontfamily,
morecomment=[s][\markupJavadocs]{/**}{*/}, % For Javadoc comments
showstringspaces=false,
numbers=left
% ,frame=lines%shadowbox%trBL
}
\lstdefinestyle{black}{
basicstyle=\small\lstfontfamily,
numbers=left,
columns=fullflexible,
breaklines=true,
mathescape=true,
escapechar=\#,
tabsize=4,
frame=lines,
showstringspaces=false
}
% use proper tt font that supports bold printing, e.g. by
% \usepackage{courier}
\lstdefinestyle{seminar}{
basicstyle=\small\ttfamily,
numbers=left,
breaklines=true,
mathescape=true,
escapechar=\#,
tabsize=4,
showstringspaces=false
}
% Originally from
% http://tex.stackexchange.com/questions/116534/lstlisting-line-wrapping
% Bug fix for fragile beamer from
% https://tex.stackexchange.com/questions/586477/missing-number-treated-as-zero-within-beamer-and-lstcustom
\newsavebox\lstcustomredarrow
\sbox\lstcustomredarrow{\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}}}
\lstset{
language=Java,%c++,
style=eclipse,
showspaces=false,
numbers=left,
frame=lrtb,
captionpos=b,
breaklines=true,
postbreak=\usebox\lstcustomredarrow,%
% Add additional keywords here
morekeywords={ enum, strictfp },
escapeinside={(*@}{@*)}
}
\expandafter\lstset\expandafter{\jAnnotations}