リスト内のバックアクセントまたはグレーブアクセント

リスト内のバックアクセントまたはグレーブアクセント

私はリストを使って、例えば次のようなbashスクリプトを表示しています。

$ export MY_ENV=`pwd`

リストに`の正しい文字を表示させるにはどうしたらいいでしょうか。現在は'が表示されています。

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}

答え1

パッケージには、左引用符と右引用符の印刷方法を決定する切り替えオプションlistingsが用意されています。 に設定すると、必要な処理が実行されます (egreg の回答にある literate の設定と同様に機能します)。このオプションを設定する前に、パッケージを読み込む必要があります。upquotetruetextcomp

\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}

バックティックが正しく表示される

答え2

literateの機能listings\textasciigraveのマクロを使用できますtextcomp。この例は必要不可欠なものだけに絞りました。

\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}

ここに画像の説明を入力してください

しかし、Bashを使用している場合は、

export MY_ENV=$(pwd)

どちらの方が印刷が簡単でしょうか?;-)

関連情報