如何在不使用\_
的情况下逃避_
这是问题的例子
word_a_a_a_a_a_b_c_dd
您可以使用一个功能。 但是,我不记得它的名字。
答案 0 :(得分:27)
您是否正在考虑underscore
包,它重新定义了下划线符号,以便您不必在文本模式下转义它?请参阅here。
答案 1 :(得分:23)
除了逐字逐句,我不知道。
逐字环境:
\begin{verbatim}
word_a_a_a_a_a_b_c_dd
\end{verbatim}
内联:
\verb|word_a_a_a_a_a_b_c_dd|
答案 2 :(得分:13)
我无法使underscore
包工作,所以我使用了url
包:
\usepackage{url}
\urlstyle{sf} % or rm, depending on your font
...
Foo \url{word_a_a_a_a_a_b_c_dd} bar.
答案 3 :(得分:2)
在这种情况下,通常需要等宽字体,因此可以使用:
\verb|word_a_a_a_a_a_b_c_dd|
答案 4 :(得分:0)
您可能还在考虑lstlisting
或verbatim
环境,它们通常用于显示代码 - 可以包含下划线。但是,这些环境不仅仅是“逃避”下划线。
答案 5 :(得分:0)
这是一个有趣的编程问题问答网站,但没人提出编程建议。
您可以定义自己的命令来替换下划线标记:
\documentclass{article}
\newcommand{\filename}[1]{\emph{\replunderscores{#1}}}
\makeatletter
% \expandafter for the case that the filename is given in a command
\newcommand{\replunderscores}[1]{\expandafter\@repl@underscores#1_\relax}
\def\@repl@underscores#1_#2\relax{%
\ifx \relax #2\relax
% #2 is empty => finish
#1%
\else
% #2 is not empty => underscore was contained, needs to be replaced
#1%
\textunderscore
% continue replacing
% #2 ends with an extra underscore so I don't need to add another one
\@repl@underscores#2\relax
\fi
}
\makeatother
\begin{document}
\filename{__init__.py}
\end{document}