Acento traseiro ou acento grave nas listagens

Acento traseiro ou acento grave nas listagens

Estou usando listagens para exibir um script bash como, por exemplo

$ export MY_ENV=`pwd`

Como posso fazer com que a listagem exiba o caractere correto para `. No momento está exibindo '

MWE:

\documentclass[11pt, article, oneside, a4paper]{memoir}

% Files encoding
\usepackage[utf8]{inputenc}
\usepackage[spanish, es-noquoting, es-tabla]{babel}
%es-noquoting era por el tikz

\usepackage[spanish]{translator}
\usepackage[OT1]{fontenc}
%\usepackage[T1]{fontenc}

%Listings
\usepackage[final]{listings} % to be shown independently draft of final
\lstdefinestyle{CommandLineStyle}{
  basicstyle=\small\ttfamily,
  numbers=none,
%  frame=tblr,
  columns=fullflexible,
%  backgroundcolor=\color{blue!10},
  linewidth=0.95\linewidth,
  xleftmargin=0.05\linewidth,
  breaklines=true,
  breakindent=1em,
%  inputencoding=utf8/latin1,
%  postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}},
%  breakautoindent=true
}

\begin{document}

\begin{lstlisting}[style=CommandLineStyle]
$ export MY_ENV=`pwd`
\end{lstlisting}


\end{document}

Responder1

O listingspacote fornece a upquoteopção de alternância para determinar como as cotações esquerda e direita serão impressas. Configurá-lo para truefazer o que você deseja (funciona de forma semelhante a definir o alfabetizado como na resposta do egreg). Isso requer o carregamento do textcomppacote antes que a opção seja definida.

\documentclass[article]{memoir}

\usepackage{textcomp} % <--- for other glyphs, so can use upquote option of listings

\usepackage[final]{listings} % to be shown independently draft of final
\lstdefinestyle{CommandLineStyle}{
  basicstyle=\small\ttfamily,
  numbers=none,
  upquote=true% ensure that backtick displays correctly
}

\begin{document}

\begin{lstlisting}[style=CommandLineStyle]
$ export MY_ENV=`pwd`
\end{lstlisting}

\end{document}

Os crases são exibidos corretamente

Responder2

Você pode usar o literaterecurso listingse a \textasciigravemacro do textcomp. Reduzi o exemplo ao essencial.

\documentclass[article]{memoir}

\usepackage{textcomp} % <--- for other glyphs

\usepackage[final]{listings} % to be shown independently draft of final
\lstdefinestyle{CommandLineStyle}{
  basicstyle=\small\ttfamily,
  numbers=none,
%  frame=tblr,
  columns=fullflexible,
%  backgroundcolor=\color{blue!10},
  linewidth=0.95\linewidth,
  xleftmargin=0.05\linewidth,
  breaklines=true,
  breakindent=1em,
%  inputencoding=utf8/latin1,
%  postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}},
%  breakautoindent=true,
  literate={`}{\textasciigrave}{1}, <--- real back quote
}

\begin{document}

\begin{lstlisting}[style=CommandLineStyle]
$ export MY_ENV=`pwd`
\end{lstlisting}

insira a descrição da imagem aqui

Mas se você estiver usando Bash, por que não

export MY_ENV=$(pwd)

o que também é mais simples de imprimir?;-)

informação relacionada