how to use accents inside a lstlisting

i know that this answer is a duplicate but the solution proposed to other question doesn't work for me.

So, i declared my language and my style and then add a "literate={è}{{\{e}}}{1}" (or "literate={è}{{\e}}1", i tried a lot of combinations) to use "\e" as "e" accented. But this doesn't work for me. for example:

\lstset{
language=Arduino,
style=myArduino,
literate={è}{{\{e}}}{1},
}

and then:

\begin{lstlisting}[style=myArduino, caption="funzione "loop", captionpos=b]
// quando il bluetooth \e connesso posso procedere ad inizializzare...
\end{lstlisting}

that should produce an output with the "\e" substituted by the è, but that doesn't happen and i get "\e" as output.

now, how i can write the accented letters like "\e" and get the è as output?

(i have an english keyboard that don't have accented letters)

thanks a lot.

• Use quando il bluetooth è connesso. The purpose of literate is to transform è into \e, not conversely. Feb 14 '19 at 0:34
• Any keyboard is capable of producing è Feb 14 '19 at 10:11
• sorry, in common latex i use \e as è, but in lstlisting it doesn't work, i can't produce the è with my keyboard and i can't copy past it every time. there is a solution for this? Feb 14 '19 at 15:19
• What strange keyboard is it? Feb 14 '19 at 16:31
• It's necessary to know what operating system you are on. Feb 14 '19 at 16:39

You could try the escapeinside feature

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstset{breaklines = true, frame = trBL, tabsize = 4, basicstyle = \small \ttfamily, keywordstyle = \color{blue}, stringstyle = \color{red}, rulecolor = \color{black}}
\usepackage[usenames, dvipsnames]{color}

\begin{document}

\begin{lstlisting}[language = Python, caption = funzione loop", captionpos = b, escapeinside = {(*@}{@*)}]
mellin_parameter = {'number_of_gl_points': 8, 'x_axis_intersection': 1.9, 'phi': (3.0 * numpy.pi) / 4.0, 'extension': False}
with open(input_path.replace('pretable/', 'mellin_parameter.pickle'), 'wb') as pf:
pickle.dump(mellin_parameter, pf) ## accented (*@ \{e} @*)
\end{lstlisting}

\end{document}

which would produce

• i resolved the issue using a text editor and replacing the \e with the è, but this is a good method to do it within latex. thanks Feb 25 '19 at 14:16