Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
}
share|improve this question

closed as unclear what you're asking by Jubobs, Andrew Swann, Charles Stewart, Jesse, Peter Jansson Jan 16 at 15:25

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
minted doesn't wrap long lines unlike listings, see tex.stackexchange.com/questions/23663/…, for sparql highlighting, see tex.stackexchange.com/questions/14927/… –  ArTourter Aug 6 '13 at 23:10
    
Oh sorry, in fact i'm using listing itself, I just edited my question –  user1774937 Aug 6 '13 at 23:16

1 Answer 1

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.

share|improve this answer
    
Thanks, here is the other issue I am getting, dl.dropboxusercontent.com/u/108022472/syn.png, are you see class is being highlighted. –  user1774937 Aug 6 '13 at 23:25
    
@user1774937 Yes, I see, but I need the settings you are using for the highlighting. –  Gonzalo Medina Aug 6 '13 at 23:31
    
the preamble of my report, dl.dropboxusercontent.com/u/108022472/preamble.txt –  user1774937 Aug 6 '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 6 '13 at 23:37
    
u right, its done –  user1774937 Aug 6 '13 at 23:39

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