2

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}
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \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. – jubobs Jan 14 '15 at 20:36
  • @Jubobs thanks for the heads up, I edited the question as you suggested and I hope it helps. – Erinç İnci Jan 14 '15 at 21:40
  • 1
    Good, but it's best to have the entire MWE in one code block (less editing required). – jubobs Jan 14 '15 at 21:50
  • @Jubobs I found out that metu.cls document class file is my problem, however I need it because it is the main template document for my thesis. Can you help me to pinpoint the code that causes the problem? The class file can be found in the following link: filedropper.com/metu – Erinç İnci Jan 15 '15 at 8:16
  • 1
    Found it. It is this line inside metu.cls: \uccode`@=`I \lccode`@="10, that messes up listings and the {} disappear. It is found at the very end. No idea what it is for. – daleif Jan 15 '15 at 9:07
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.