在列表环境中使用货币符号时,我遇到了 unicode 错误。我尝试添加\usepackage{textcomp}
,但随后遇到了其他 (bibtex) 错误。所以也许有一个更干净的选项?
\documentclass[a4paper,12pt,parskip=half]{report}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=Python, caption=Example, label=lst:example]
currencies = ["£","€","$","¥","¢","₩","§"]
\end{lstlisting}
\end{document}
答案1
您可以使用 LateX 命令在列表模式下排版它们,因此您必须对它们进行转义。为此,请使用 \lstset。输入它们的命令位于文本压缩包裹。
像这样:
\documentclass[a4paper,12pt,parskip=half]{report}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{listings}
\lstset{
escapeinside={(*@}{@*)}
}
\begin{document}
This is it in TeX mode: currencies =[\texteuro \textlira \textcent \textdollar \textyen \textwon \textsection]
\begin{lstlisting}[language=Python, caption=Example, label=lst:example]
This is it in listings mode:
currencies = [(*@{\pounds \texteuro \textdollar \textyen \textcent \textwon \textsection}@*)]
\end{lstlisting}
\end{document}