[Tex/LaTex] Curly braces in the Java lstlisting are not shown

bracketslistings

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}
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}

Best Answer

The problem can be seen with this very small MWE:

\documentclass[a4paper]{article}

\uccode`@=`I \lccode`@="10

\usepackage{listings}
\lstset{
    language = Java,
    basicstyle=\scriptsize\ttfamily,
}

\begin{document}
\begin{lstlisting}
... InterruptedException {

}
\end{lstlisting}
\end{document}

The \uccode`@=`I \lccode`@="10 line is found at the very end of metu.cls, and it apparently messes up listings. Remove the line, and the {} reappear.

Related Question