我正在使用清單來顯示 bash 腳本,例如
$ export MY_ENV=`pwd`
如何使清單顯示正確的字元`.現在它顯示'
微量元素:
\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
軟體包提供了upquote
切換選項來確定如何列印左右引號。將其設定為true
您想要的(與在egreg的答案中設定識字類似)。這需要textcomp
在設定選項之前載入套件。
\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)
哪個印起來也比較簡單?;-)