如何强调列表的某些部分?
如何将列表的某些部分设置为粗体?
\begin{lstlisting}[escapechar=@]
fun(foo, bar, @\textbf{baz}@ );
\end{lstlisting}
这可以编译,但 baz 没有设置为粗体:( 我错过了什么?
How can I set certain parts of an lstlisting in boldface?
\begin{lstlisting}[escapechar=@]
fun(foo, bar, @\textbf{baz}@ );
\end{lstlisting}
This compiles, but baz isn't set in boldface :( What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的基本方法应该是告诉列表要强调哪些单词。一个简单的方法是这样的:
当然,无论何时出现,都会强调
baz
。但这是比尝试将标记放入列表本身更好的方法,您不(应该)想要这样做,因为您(应该)想要使用列表来格式化未修改的代码段。尤其是当您包含源文件而不是键入代码片段时。一旦您掌握了基础知识,请查看文档,了解如何设置关键字和标识符的样式,以及如何修改您选择的语言的内置关键字列表。
Your basic approach should be to tell listing what words to emphasise. A straightforward way to do this is like this:
Of course, that will emphasise
baz
whenever it occurs. But this is a better approach than trying to put the markup into your listing itself, you don't (ought to) want to do that since you (ought to) want to use listings to format an unmodified piece of code. Especially so if you are including source files rather than typing code snippets.Once you've got the basics under your belt look at the documentation, to learn how to set styles for keywords and for identifiers, and how to modify the inbuilt list(s) of keywords for your languages of choice.
你的解决方案是正确的。但是,标准 LaTeX 等宽字体没有粗体版本,因此
\textbf
在lstlisting
环境中不会执行任何操作。根据macfreek.nl,您可以执行以下操作来重新声明粗体版本:我已经测试过下面的示例,它按照您的意愿工作:
我使用与
\color{red}
而不是\textbf
相同的技术来提示投影仪演示的观众注意差异两个几乎相同的代码清单之间。Your solution is correct. However, the standard LaTeX monospaced font does not have a boldface version, so
\textbf
doesn’t do anything within thelstlisting
environment. According to macfreek.nl, you can do the following to redeclare the boldface version:I’ve tested the following example and it works as you desire:
I use the same technique with
\color{red}
instead of\textbf
to hint the audience of a beamer presentation at the difference between two almost identical code listings.我在 http://www.mrunix.de/ 下找到了答案论坛/archive/index.php/t-42976.html
I found an answer under http://www.mrunix.de/forums/archive/index.php/t-42976.html