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.

It seems that showexpl removes the accents when it is processing them.

How can I make it to use accented letters?

Is there a replacement or a similar package that is more robust?

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{listings}
\usepackage{showexpl}
\lstset {
  literate=%
    {á}{{\'{a}}}1
    {é}{{\'{e}}}1
    {í}{{\'{i}}}1
    {ó}{{\'{o}}}1
    {ú}{{\'{u}}}1
    {ñ}{{\~{n}}}1
    {Ñ}{{\~{N}}}1
}

\begin{document}

\begin{lstlisting}
  á é í ó ú a e i o u
\end{lstlisting}

\begin{LTXexample}
  á é í ó ú a e i o u
\end{LTXexample}

\end{document}

enter image description here

share|improve this question
1  
Since showexpl uses the listings package, this is a duplicate of Having problems with listings and UTF-8. Can it be fixed?. –  Alan Munn Jul 23 at 14:54
2  
@AlanMunn: not really. The accents disappear also in an ansinew encoded files. Also the example shows that in lstlisting itself the accents works. –  Ulrike Fischer Jul 23 at 16:04
    
@UlrikeFischer reading too fast I guess. You're absolutely right. –  Alan Munn Jul 23 at 16:17

2 Answers 2

showexpl has to write the code to a temporary file. It uses an internal command of listings for this. But accent doesn't survive if you use the literate option too. Put the code in some external file and then use

\LTXinputExample{test-code}
share|improve this answer
    
The problem with that solution is that breaks the idea of using showexpl. As I wanted to keep the code I'm showing within the same file, and without duplicity. In that case, I may just copy paste the code, but that solution is not maintainable. –  adn Jul 23 at 18:54
    
Well you can use an enviroment like filcontents* from the filecontents package or VerbatimOut from fancyvrb to output the code on-the-fly. In many (but not all) cases this should work fine. If your file is utf8 encoded: check carefully the encoding of the output file. Writing utf8 is a bit tricky. See e.g. tex.stackexchange.com/questions/47462/…. You could also make a feature request for showexpl. –  Ulrike Fischer Jul 24 at 8:02

Run xelatex and everything will be fine without using the literate option:

\documentclass{article}
\usepackage{fontspec}
\setmonofont[Scale=0.88]{DejaVu Sans Mono}
\usepackage{listings}
\usepackage{showexpl}
\begin{document}

\begin{lstlisting}
áéíóúaeiou
\end{lstlisting}

\begin{LTXexample}
áéíóúaeiou
\end{LTXexample}

\end{document}

enter image description here

share|improve this answer
1  
+1: showexpl automatically loads listings. –  stalking is prohibited Jul 23 at 16:41

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.