6

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

3
  • 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
    Commented Jul 23, 2014 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. Commented Jul 23, 2014 at 16:04
  • @UlrikeFischer reading too fast I guess. You're absolutely right.
    – Alan Munn
    Commented Jul 23, 2014 at 16:17

2 Answers 2

5

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}
2
  • 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
    Commented Jul 23, 2014 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. Commented Jul 24, 2014 at 8:02
3

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

1
  • 1
    +1: showexpl automatically loads listings. Commented Jul 23, 2014 at 16:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .