4

I'm using listings to display a bash script like for instance

$ export MY_ENV=`pwd`

How can I make listing display the correct character for `. Right now it is displaying '

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

The listings package provides the upquote toggle option to determine how the left and right quote are printed. Setting it to true does what you want (works similarly to setting the literate as in egreg's answer). This requires loading the textcomp package before the option is set.

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

Backticks are displayed correctly

3

You can use the literate feature of listings and the \textasciigrave macro of textcomp. I have reduced the example to the essential.

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

enter image description here

But if you're using Bash, why not

export MY_ENV=$(pwd)

which is also simpler to print? ;-)

  • the bash was just an example, it is a more complicated line ;) Both answers are equally valid. – jlanza Mar 24 '14 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.