9

I'm using listings to display my codes. I'm getting some issues. First, the codes when it is too long, it is going out of page as shown here. Secondly, the codes are in SPARQL. It is recognising some of the variables I use as SQL keywords and highlighted them as shown here where Class is inspite being a variable is being highlighted as a keyword. My codes are as follows:

\begin{lstlisting}[captionpos=b, caption=Retrieval of Individuals, label=listing:sparql_getallindividuals,
   basicstyle=\ttfamily]
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  wo:   <http://purl.org/ontology/wo/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT  ?individual ?type ?name
  WHERE
    { ?individual rdf:type ?type .
      ?individual wo:commonName ?name
      FILTER ( ?type IN (wo:Kingdom, wo:Phylum, wo:Class, wo:Order, wo:Species, wo:Family, wo:Genus) )
    }
\end{lstlisting}

Any help would be greatly appreciated

This is preamble of my report:

\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}

 \lstset{frame=tb,
  language=Java,
  showstringspaces=false,
  columns=flexible,
  numbers=none,
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  tabsize=3
}
\lstdefinelanguage{XML}
{
  morestring=[b]",
  morestring=[s]{>}{<},
  morecomment=[s]{<?}{?>},
  stringstyle=\color{black},
  identifierstyle=\color{darkblue},
  keywordstyle=\color{cyan},
  morekeywords={xmlns,version,type,ma-id}% list your attributes here
}
Noor
  • 1,801
  • minted doesn't wrap long lines unlike listings, see http://tex.stackexchange.com/questions/23663/minted-truncates-the-code-if-it-doesnt-fit-into-one-page, for sparql highlighting, see http://tex.stackexchange.com/questions/14927/listing-syntax-highlighting-for-sparql-query – ArTourter Aug 06 '13 at 23:10
  • Oh sorry, in fact i'm using listing itself, I just edited my question – Noor Aug 06 '13 at 23:16

1 Answers1

11

For the line breaking problem, you can use the breaklines=true option:

\documentclass{book}
\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}

 \lstset{frame=tb,
  language=Java,
  breaklines=true,
  showstringspaces=false,
  columns=flexible,
  numbers=none,
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  tabsize=3
}
\lstdefinelanguage{XML}
{
  morestring=[b]",
  morestring=[s]{>}{<},
  morecomment=[s]{<?}{?>},
  stringstyle=\color{black},
  identifierstyle=\color{darkblue},
  keywordstyle=\color{cyan},
  morekeywords={xmlns,version,type,ma-id}% list your attributes here
}

\begin{document}

\begin{lstlisting}[captionpos=b, caption=Retrieval of Individuals, label=listing:sparql_getallindividuals,
   basicstyle=\ttfamily]
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  wo:   <http://purl.org/ontology/wo/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT  ?individual ?type ?name
  WHERE
    { ?individual rdf:type ?type .
      ?individual wo:commonName ?name
      FILTER ( ?type IN (wo:Kingdom, wo:Phylum, wo:Class, wo:Order, wo:Species, wo:Family, wo:Genus) )
    }
\end{lstlisting}

\end{document}

enter image description here

For the other issue, you haven't provided enough information to detect the problem.

Gonzalo Medina
  • 505,128
  • Thanks, here is the other issue I am getting, https://dl.dropboxusercontent.com/u/108022472/syn.png, are you see class is being highlighted. – Noor Aug 06 '13 at 23:25
  • @user1774937 Yes, I see, but I need the settings you are using for the highlighting. – Gonzalo Medina Aug 06 '13 at 23:31
  • the preamble of my report, https://dl.dropboxusercontent.com/u/108022472/preamble.txt – Noor Aug 06 '13 at 23:35
  • @user1774937 Please add the relevant information to your question. Compose a little complete document (like the one in my answer) with the relevant settings and showing the problem mentioned and add this document as an edit to your question. – Gonzalo Medina Aug 06 '13 at 23:37
  • u right, its done – Noor Aug 06 '13 at 23:39
  • @user1774937 Sorry, but that's not a little, complete document. Remove all unnecessary information and keep just all that is really relevant to your problem and complete the code until it's complete. – Gonzalo Medina Aug 06 '13 at 23:41
  • I'm a latex beginner, I removed what I think is not relevant – Noor Aug 06 '13 at 23:58
  • @user1774937 I updated my answer using the settings in your question. As you can see I don't get the string "Class" highlighted, so something else must be going on in your document, and without the actual offending code is almost impossible to provide effective help. Please compose a little, complete document (again, like the one in my answer) containing the settings allowing us to reproduce the problem mentioned. – Gonzalo Medina Aug 07 '13 at 00:14
  • I suppose this issue must be in the preamble?? – Noor Aug 07 '13 at 00:19