使用 LaTeX 的“列表”时,如何显示直引号而不是弯引号? 包裹?
我正在使用 LaTeX 的“listings" 包用于格式化源代码。 不幸的是我得到的是弯引号而不是直引号。 由于大引号并不总是指向正确的方向,所以看起来很糟糕。 我怎样才能得到直接引号?
我不想更改或过滤源代码本身。 过滤代码以正确地将 " 更改为 `` 或 '' 是可行的,但这比在一行上使用多个引号或跨越多行的引号更容易。或者您可以使用符号或许多其他东西。但是我真的很想保持源代码不变。
示例 LaTeX:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}
示例输出(在 Windows 上使用 Miktex):
I'm using LaTeX's "listings" package to format source code. Unfortunately I get curly quotes instead of straight quotes. Since the curly quotes don't always point in the right direction, it looks bad. How can I get straight quotes instead?
I'd prefer not to change or filter the source code itself. Filtering the code to properly change " to `` or '' would work, but this is easier done than said with multiple quotes on a line, or quotes spanning multiple lines. Or you could use symbol or a host of other things. But I'd really like to keep the source unchanged.
Example LaTeX:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}
Example output (using Miktex on windows):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我在文档中看到(应该与 packge 一起分发,但可以在 http://www.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf)对于
listings
有一个可设置的名为upquote
的属性来处理这个问题。从文档中:
执行类似的操作
在开始列表环境之前
,或者使用也可能已经以适当的语言为您设置了 tis 属性
定义(再次参见文档,第 12 页上的预定义语言的大列表)。
使用:
在标题中。 然后使用上述任一约定来选择选项来设置语言。
I see in the documentation (which should have been distributed with the packge, but is available at http://www.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf) for
listings
that there is a settable property calledupquote
to take care of this.From the documentation:
Do something like
before
begin
ing the list environment, or useIt is also possible that tis property is already set for you in the appropriate language
definition (see the docs again, big list of predefined languages on page 12).
Use:
in the header. And then set the language using either of the above conventions for choosing options.
您是否考虑过在列表中使用等宽(打字机)字体? 以下示例有效:
Have you considered using a monospaced (typewriter) font for the listing? The following example works:
dmckee的回答上面的可能有效。 如果您放弃最后一个条件,即您允许更改代码,那么有一个更通用的解决方案,每当 (La)TeX 呈现的字符与我期望的不同时,我倾向于使用该解决方案,即使用
\symbol
命令。 我在这里列出它是因为它在其他情况下也很有用:然后是你的示例:
注意花括号,它应该将列表带回 LaTeX 模式(请参阅包的
escapechars
选项。)dmckee's answer above probably works. If you drop your last condition, i.e. you permit changes to the code, then there is a more generic solution, which I tend to use whenever (La)TeX renders a character somehow differently than I expect it to do is to use the
\symbol
command. I list it here because it can be useful in other situations as well:And then your example:
Note the curly braces which supposedly take listings back to LaTeX mode (see
escapechars
option of the package.)这是一个解决方案
Here is a solution
我使用 fontspec 时遇到了同样的问题,解决方案是不设置
\defaultfontfeatures{Mapping=tex-text}
,而是设置Mapping=tex- text
特别是仅在主字体和无字体上,并将 tt 字体留给它自己的设备。 :)I had the same problem, using fontspec, and the solution was to not set
\defaultfontfeatures{Mapping=tex-text}
, but instead settingMapping=tex-text
specifically on only the main and sans font, and leaving the tt font to it's own devices. :)也许是因为我作为 LaTeX 用户很早就安装了列表,但我很惊讶地发现,如果没有列表包,行为会有所不同。
我的解决方案与 David Hanak 的类似,但我使用了 LaTeX Cheat Sheet 中描述的双引号符号 (http://stdout.org/~winston/latex)
Maybe it's because I installed listings early as a LaTeX user, but I'm surprised to learn that without the listings package the behaviour is any different.
My solution was similar to David Hanak's, but I used the symbols for double-quote as described in the LaTeX Cheat Sheet (http://stdout.org/~winston/latex)