我知道这个答案是重复的,但对其他问题提出的解决方案对我来说不起作用。
因此,我声明了我的语言和风格,然后添加了“literate={è}{{\`{e}}}{1}”(或“literate={è}{{\`e}}1”,我尝试了很多组合)以使用“\`e”作为“e”重音。但这对我来说不起作用。例如:
\lstset{
language=Arduino,
style=myArduino,
literate={è}{{\`{e}}}{1},
}
进而:
\begin{lstlisting}[style=myArduino, caption="funzione "loop", captionpos=b]
// quando il bluetooth \`e connesso posso procedere ad inizializzare...
\end{lstlisting}
这应该产生一个输出,其中“\`e”被è替换,但这并没有发生,我得到的输出是“\`e”。
现在,我怎样才能写出像“\`e”这样的重音字母并得到è作为输出?
(我有一个没有重音字母的英文键盘)
多谢。
答案1
您可以尝试该escapeinside
功能
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstset{breaklines = true, frame = trBL, tabsize = 4, basicstyle = \small \ttfamily, keywordstyle = \color{blue}, stringstyle = \color{red}, rulecolor = \color{black}}
\usepackage[usenames, dvipsnames]{color}
\begin{document}
\begin{lstlisting}[language = Python, caption = funzione ``loop", captionpos = b, escapeinside = {(*@}{@*)}]
mellin_parameter = {'number_of_gl_points': 8, 'x_axis_intersection': 1.9, 'phi': (3.0 * numpy.pi) / 4.0, 'extension': False}
with open(input_path.replace('pretable/', 'mellin_parameter.pickle'), 'wb') as pf:
pickle.dump(mellin_parameter, pf) ## accented (*@ \`{e} @*)
\end{lstlisting}
\end{document}
这将产生
答案2
正如指出的那样列表和 UTF-8 存在问题。可以修复吗?使用 escapeinside 无法很好地适应该格式。
您可以简单地使用(记得转义反斜杠)
\documentclass{article}
\usepackage{listings}
\lstset{breaklines = true, frame = trBL, tabsize = 4, basicstyle = \small \ttfamily, keywordstyle = \color{blue}, stringstyle = \color{red}, rulecolor = \color{black}}
\usepackage[usenames, dvipsnames]{color}
\begin{document}
\begin{lstlisting}[language = Python, caption = funzione ``loop", captionpos = b,
literate=
{\\`e}{{\`e}}1
]
mellin_parameter = {'number_of_gl_points': 8, 'x_axis_intersection': 1.9, 'phi': (3.0 * numpy.pi) / 4.0, 'extension': False}
with open(input_path.replace('pretable/', 'mellin_parameter.pickle'), 'wb') as pf:
pickle.dump(mellin_parameter, pf) ## accented \`e
\end{lstlisting}
\end{document}
另外,由于这不是真正的 LaTeX 代码,您也可以指定不需要反斜杠
\documentclass{article}
\usepackage{listings}
\lstset{breaklines = true, frame = trBL, tabsize = 4, basicstyle = \small \ttfamily, keywordstyle = \color{blue}, stringstyle = \color{red}, rulecolor = \color{black}}
\usepackage[usenames, dvipsnames]{color}
\begin{document}
\begin{lstlisting}[language = Python, caption = funzione ``loop", captionpos = b,
literate=
{`e}{{\`e}}1
]
mellin_parameter = {'number_of_gl_points': 8, 'x_axis_intersection': 1.9, 'phi': (3.0 * numpy.pi) / 4.0, 'extension': False}
with open(input_path.replace('pretable/', 'mellin_parameter.pickle'), 'wb') as pf:
pickle.dump(mellin_parameter, pf) ## accented `e
\end{lstlisting}
\end{document}
输出符合您的预期(请注意,è
是斜体)