1

I can do syntax highlighting in the minted environment, for any SPARQL query using this Pygments lexer thanks to this answer.

My problem is how to get SPARQL syntax highlighting to work with mint in a listing (so that I can get a label and a caption). I am missing the BOM/EOM escape code.

Here's a minimal example:

\documentclass{article}
\usepackage{minted}
\begin{document}

%Minted environment works fine 
\begin{minted}{sparql}
PREFIX java: <http://evolizer.org/ontologies/seon/2009/06/java.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?url ?name
WHERE {
   ?url rdf:type java:Package .
   ?url rdfs:label ?name
}
\end{minted}

%Mint in listing gives runaway argument error
\begin{listing}[H]
\mint{SPARQL}
PREFIX java: <http://evolizer.org/ontologies/seon/2009/06/java.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?url ?name
WHERE {
   ?url rdf:type java:Package .
   ?url rdfs:label ?name
\caption{Example of a listing.}
\label{lst:example}
\end{listing}

Listing \ref{lst:example} contains an example of a listing.

\end{document}

When I try to compile the above example with pdflatex -shell-escape I get:

Runaway argument?
REFIX java: <http://evolizer.org/ontologies/seon/2009/06/java.owl#>
! Forbidden control sequence found while scanning use of \FancyVerbGetVerb.
<inserted text> 
                \par 
l.17 ...zer.org/ontologies/seon/2009/06/java.owl#>

This example from the mint manual works fine:

\begin{listing}[H]
\mint{cl}/(car (cons 1 ’(2)))/
\caption{Example of a listing.}
\label{lst:example}
\end{listing}

Listing \ref{lst:example} contains an example of a listing. 

I seem to be missing the escape code (/ in cl) that signals the beginning and end of a message for SPARQL. Thoughts?

I'd also consider other approaches to syntax highlighting (e.g. other libraries that use Pygments); since I want colors, this b+w highlighting solution isn't what I need.

  • What is it that you want to do that the minted environment can't? – G. Poore Aug 30 '13 at 17:37
  • I need a label and a caption. – Jodi Schneider Aug 30 '13 at 17:41
  • You should be able to put the minted environment inside the listing environment, with the label and caption after the end of the minted environment (on a separate line). – G. Poore Aug 30 '13 at 17:47
  • Ah, I didn't think of trying that! Indeed, that works. Want to add it as an answer so I can accept it? Thanks @g-poore ! – Jodi Schneider Aug 30 '13 at 17:53
1

You can use the minted environment by putting it inside the listing environment, with the label and caption after the end of the minted environment (on a separate line). The nested environments will work fine.

The \mint command is for typesetting a single line of code, so the code must delimited by a pair of matched characters. For example, \mint{<language>}/<code>/ uses the / character as a delimiter.

  • Working solution, for clarity: \documentclass{article} \usepackage{minted} \begin{document} \begin{listing}[H] \begin{minted}{sparql} PREFIX java: <http://evolizer.org/ontologies/seon/2009/06/java.owl#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?url ?name WHERE { ?url rdf:type java:Package . ?url rdfs:label ?name \end{minted} \caption{Example of a listing.} \label{lst:example} \end{listing} Listing \ref{lst:example} contains an example of a listing. \end{document} – Jodi Schneider Aug 31 '13 at 10:02

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.