# Incorrect placement of quotation marks

I just want to include some sourcecode by using the listings package wit XeTeX.

Here is my minimal example:

% !TEX TS-program = XeLaTeX
% !TEX encoding = UTF-8 Unicode
\documentclass[xetex]{scrreprt}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\setmonofont[Scale=.8]{Inconsolata}
\usepackage{bold-extra}
\usepackage{upquote}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily\scriptsize,
keywordstyle=\bfseries,
numbers=left,
inputencoding=utf8x,
extendedchars=true,
showlines=true,
upquote=true,
showstringspaces=false
}
\lstdefinelanguage{turtle} {
morekeywords={@prefix,@base,@forSome,@forAll,@keywords},
%   literate=%
%       *{}{}{1}
%       {''}{''}{1}
%       {„}{}{1}
%       {“}{''}{1},
}

\begin{document}
\begin{lstlisting}[language=turtle]
@prefix crm:  <http://www.cidoc-crm.org/cidoc-crm/> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<http://my.domain/object/1>
rdf:type
rdfs:label
"„David“ Skulptür …", "This is another ‚test‘ …" ;
crm:P102_has_title
<http://my.domain/title/1> ;
crm:P108i_was_produced_by
<http://my.domain/production/1> ;
crm:P31i_was_modified_by
<http://my.domain/modification/1> .
\end{lstlisting}
\end{document}


This produces te following output:

As you can see in line 8 (the last sign at the end) and line 9 (after the first quotation mark; in front of the word test) the quotation marks are wrong/incorrect. – David should be surrounded by (German) double quotation marks („David“) and test with (German) single quotation marks (‚test‘).

→ Does someone know how to fix that/produce that?

Another problem in line 9 is the display of typographical quotation marks (opening and closing) for the whole string ("„David“ Skulptür …"). I can only fix this by commenting out \defaultfontfeatures{Mapping=tex-text} in the preamble.

→ Again: Does someone know how to fix that (without disabling \defaultfontfeatures)?

Thanks a lot and best regards!

PS: The disabled literate option in the MWE doesn't change anything if is enabled …

-
I'm afraid listings has problems with Unicode input as interpreted by XeTeX. For the \defaultfontfeatures problem, just define the mono font before issuing that declaration. Don't load xltxtra, but fontspec; the recommendation for the former package has long been obsolete. –  egreg Sep 10 '13 at 13:44
Thanks @egreg for your comment! I now load fontencinstead of xltxtra and added \defaultfontfeatures after my font definitions, but that didn't change anything. :-/ (Maybe now I'm a little bit more future-proof?) –  sokai Sep 10 '13 at 14:21
The second part of the comment is independent from the first, about the problems of listings with XeTeX, that remain as you saw. –  egreg Sep 10 '13 at 14:23
Thanks @egreg! – Moving \defaultfontfeatures behind \setmonofont fixed the 2nd question. :) –  sokai Sep 10 '13 at 16:23

The main problem is that listings does not work well with UTF-8 input, which means in particular XeLaTeX and LuaLaTeX. I'm afraid that a very thorough revision of the package would be required for getting it to work with arbitrary UTF-8 input.

However, not all is lost. I downloaded some pygmentize lexers from https://github.com/gniezen/n3pygments and installed them (pygmentize is required). Then I changed your input in the following way:

\documentclass{scrreprt}
\usepackage{fontspec}
\setmonofont[Scale=.8]{Inconsolata}
\defaultfontfeatures{Ligatures=TeX}

\usepackage{verbments}

\begin{document}
\begin{pyglist}[language=turtle]
@prefix crm:  <http://www.cidoc-crm.org/cidoc-crm/> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<http://my.domain/object/1>
rdf:type
rdfs:label
"„David“ Skulptür …", "This is another ‚test‘ …" ;
crm:P102_has_title
<http://my.domain/title/1> ;
crm:P108i_was_produced_by
<http://my.domain/production/1> ;
crm:P31i_was_modified_by
<http://my.domain/modification/1> .
\end{pyglist}
\end{document}


and compiled the file with

xelatex -shell-escape sokai


Here's the result, which seems what you were looking for.

Note that \defaultfontfeatures{Ligatures=TeX} should be issued after defining the monospaced font, if you don't want it to use the standard ligatures.

Also using xltxtra is not recommended any more; it's better to call directly fontspec as shown. The packages bold-extra and upquote are not compatible with this setting for XeLaTeX, so I removed them.

-
Thanks @egreg! – Your example with the verbments package works very well. But I was looking for a solution for the listings package, so I can't accept this as an answer … :-/ Also I'm missing many options with the verbments package that I'm using wit the listings package. But I really like the lexer method used by pygmentize! Thanks for your hints about compatibility and not recommended packages, too. :) –  sokai Sep 15 '13 at 9:19
@sokai As I said, listings has problems with UTF-8 encoded files using "arbitrary" characters, because its look-ahead procedures work under the assumption of character codes between 0 and 255. –  egreg Sep 15 '13 at 9:33
O.K. – So the answer of my first question is „There is no (known) solution with the listings package. But it can be solved with the verbments package.“. – So I will accept your answer. :) (I keep using the listings package and try to avoid typographical question marks.) –  sokai Sep 15 '13 at 9:56