在 LaTeX 中有效地转义许多 _
如何在不使用 \_
的情况下转义 _?
这是问题的示例
word_a_a_a_a_a_b_c_dd
有一个函数可以用于此目的。 然而,我记不起它的名字了。
How can you escape _ without the use of \_
?
This is the example of the question
word_a_a_a_a_a_b_c_dd
There is one function which you can use for this.
However, I cannot remember its name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您是否正在考虑
underscore
包,它重新定义了下划线符号,以便您不必在文本模式下转义它?请参阅此处。Are you thinking of the
underscore
package, which redefines the underscore symbol so that you don't have to escape it in text mode? See here.除了逐字逐句我不知道。
逐字环境:
内联:
Other than verbatim I wouldn't know.
Verbatim environment:
Inline:
我无法使用
underscore
包,因此我使用了url
包:I couldn't get the
underscore
package to work, so I used theurl
package:有趣的是,这是一个针对编程问题的问答网站,但还没有人建议编程。
您可以定义自己的命令来替换下划线标记:
It's funny how this is a question and answer site for programming questions but nobody has suggested programming yet.
You could define your own command which replaces the underscore tokens:
通常在这种情况下您需要等宽字体,因此您可以使用:
Typically you want a monospaced font in such situations, so you can use this:
您可能还会想到
lstlisting
或verbatim
环境,它们通常用于显示代码 - 可以包含下划线。然而,这些环境的作用不仅仅是“转义”下划线。You may also be thinking of the
lstlisting
orverbatim
environments, which are commonly used to display code - which can contain underscores. However, these environments do a lot more than just "escape" underscores.当文本来自另一个宏时,上述大多数方法都会失败,因为人们不想列出宏名称。 \url{} 命令有效,但如果不想生成链接,则还可以使用 hyperref 包中的 \nolinkurl{}。
例如,您可以使用宏 \jobname 来打印主 LaTeX 文件的基本名称。如果文件名包含下划线,这将打印一些有趣的字符来代替下划线。要正确打印文件名,您可以将宏 \jobname 包装在 \nolinkurl 中。
例如,如果文件名是“my_project.tex”,您可以:
诚然,这对于关于如何转义许多下划线的原始问题来说并不是一个好的答案,因为您无法在 \nolinkurl 中放置长文本。
Most methods above fail when the text comes from another macro, because one does not want to list the macro name. The \url{} command works, but if one does not want a link generated, then one can use also \nolinkurl{} from the hyperref package.
For example you could use the macro \jobname to print the base name of your main LaTeX file. This will print some funny characters in place of the underscores, if the filename contains underscores. To print the filename properly, you could wrap the macro \jobname in \nolinkurl.
For example, if the filename is "my_project.tex" you could:
Admittedly, this is not a good answer to the original question on how to escape many underscores, since you won't be able to put a long text in \nolinkurl.