I'm writing my thesis with ShareLatex online tool (pdfLaTeX compiler) based on template; METU Thesis Template on ShareLatex. When I try to add a lstlisting or lstinputlisting to my document, curly braces ({, }) in my Java code are not showing at all. I'm fairly new at LaTeX but I tried a lot of solutions found online like escaping brackets in my Java code, or trying to adjust lstset parameters accordingly. I also tried to simplify and comment out every lstset directive but nothing solved my problem.
In my tests, it seems that when I use metu.cls as my document class, it messes up with my listing formatting. How can I overcome this issue or include a different document class just for my listings?Thanks for any help.
A sample of my document (For compiling, I just included some parts of the template) (For the document class directive, metu.cls file can be found in the following link - metu.cls):
%%%% Works fine with this default article document class %%%%
%\documentclass[a4paper,12pt]{article}
%%%% When I use the "metu" class, it seems like it messes up with my source codes %%%%
\documentclass[chaparabic,ceng,ms,12pt,oneandhalf]{metu}
\usepackage{appendix}
\usepackage[pdftex]{hyperref}
\usepackage[all]{hypcap}
\usepackage{todonotes}
\usepackage{rotating}
\usepackage{xy}
\usepackage{booktabs}
\usepackage{pifont}
\usepackage{color}
\usepackage{pdfpages}
\usepackage{adjustbox}
\usepackage{caption}
\usepackage{array}
\usepackage{graphicx}
\graphicspath{ {./images/} }
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
% Listings formatting directives
\usepackage{listings}
\usepackage{float}
\lstset{float}
\makeatletter
\let\lst@floatdefault\lst@float
\makeatother
\DeclareCaptionFormat{listing}{#1#2#3}
\captionsetup[lstlisting]{format=listing,singlelinecheck=false, margin=0pt, font={sf}}
\restylefloat{figure}
\newcommand{\tab}{\hspace*{2em}}
\definecolor{keyword}{rgb}{0.13,0.13,1}
\definecolor{comment}{rgb}{0,0.5,0}
\definecolor{string}{rgb}{0.9,0,0}
\definecolor{splashedwhite}{rgb}{1.0, 0.99, 1.0}
\definecolor{reserved}{rgb}{0.46,0.45,0.48}
\lstset{
language = Java,
basicstyle=\scriptsize\ttfamily,
numbers=left,
numbersep=10pt,
numberstyle=\tiny\color{black},
stepnumber=1,
tabsize=2,
showspaces=false,
frame=single,
breaklines=true,
escapeinside={\%*}{*)},
backgroundcolor=\color{splashedwhite},
commentstyle=\itshape\color{comment},
keywordstyle=\bfseries\color{keyword},
stringstyle=\color{string},
extendedchars=true,
captionpos=t
}
\begin{document}
% Sample lstlisting from my document
\begin{lstlisting}[caption=Browsed Log Hadoop Mapper Code]
public void map(Text key, Text value, Mapper.Context context) throws IOException, InterruptedException {
List<String> logValues = Lists.newArrayList();
StringTokenizer itr = new StringTokenizer(value.toString(), LOG_SEPERATOR);
while (itr.hasMoreTokens()) {
logValues.add(itr.nextToken());
}
context.write(new Text(logValues.get(UID_INDEX)), new Text(logValues.get(URL_INDEX)));
}
\end{lstlisting}
% Sample lstinputlisting from my document
%\lstinputlisting[language=Java, float=false, frame=none]{source-codes/EUrlCategory.java}
\end{document}
\documentclass{...}
, the required\usepackage
's,\begin{document}
, and\end{document}
. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.metu.cls
:\uccode`@=`I \lccode`@="10
, that messes uplistings
and the{}
disappear. It is found at the very end. No idea what it is for.