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 wondering if it's possible to use guillemets («») in a lstlisting block? I have seen some solutions for including it in the document, but none with the listings package.

share|improve this question
    
@lockstep: why the tag "punctuation"? –  Herbert Feb 9 '12 at 19:37
1  
@Herbert Guillemets are a kind of quotation mark, for which we normally use punctuation. Perhaps characters or symbols would have been appropriate as alternative tags. I have no strong opinion here, so feel free to revert my tag selection. –  lockstep Feb 9 '12 at 19:45
add comment

1 Answer

up vote 9 down vote accepted
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{bera,listings,babel}
\lstset{literate={«}{{\flqq}}1 {»}{{\frqq}}1}
\usepackage{listings}
\begin{document}

\begin{lstlisting}[basicstyle=\ttfamily]
my «foo» and my «bar»
\end{lstlisting}

\end{document}

enter image description here

share|improve this answer
    
Works like a charm! Thank you! –  navlelo Feb 10 '12 at 10:25
    
with xelatexyou can do a morecomment=[s]{«}{»} –  Herbert Jul 10 '12 at 15:34
    
Which part of your answer was the crucial part? What's bera for? What does \lstset do? Why are there numbers? I could look the answers to these questions up, of course, but I think it's good style on SE sites not only to provide code, but to explain what's going on and why the answer given works. I'd love to see more explanations in your great answers! –  doncherry Jul 10 '12 at 18:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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