当出现字符串文字时,软件包列表会出现奇怪的结果

当出现字符串文字时,软件包列表会出现奇怪的结果

我正在使用包列表在文档中添加代码。

几乎一切都运行良好,直到我写了这样的字符串文字:

\documentclass{article}
\usepackage{listings}
\begin{document}
{
\begin{lstlisting}[language=python]
"? {a}"
\end{lstlisting}
}
\end{document}

这会生成一个非常奇怪的字符串,其中“?”和“{”之间的空格变成以下符号: 在此处输入图片描述

这是软件包列表的一个错误吗?我正在寻找解决方案。

评论:奇怪的符号根据当前字体而不同。我正在使用Consolas。在其他情况下,它可能会变成一个没有问号的小方块,如上例所示。

我正在使用 xelatex。

日志档案:

This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/W32TeX) (preloaded format=xelatex 2020.11.18)  20 FEB 2021 21:58
entering extended mode
 restricted \write18 enabled.
 file:line:error style messages enabled.
 %&-line parsing enabled.
**test
(./test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06> (c:/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(c:/texlive/2020/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2019/12/20 v1.4l Standard LaTeX file (size option)
)
\c@part=\count163
\c@section=\count164
\c@subsection=\count165
\c@subsubsection=\count166
\c@paragraph=\count167
\c@subparagraph=\count168
\c@figure=\count169
\c@table=\count170
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen134
) (c:/texlive/2020/texmf-dist/tex/latex/listings/listings.sty (c:/texlive/2020/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks15
)
\lst@mode=\count171
\lst@gtempboxa=\box45
\lst@token=\toks16
\lst@length=\count172
\lst@currlwidth=\dimen135
\lst@column=\count173
\lst@pos=\count174
\lst@lostspace=\dimen136
\lst@width=\dimen137
\lst@newlines=\count175
\lst@lineno=\count176
\lst@maxwidth=\dimen138
 (c:/texlive/2020/texmf-dist/tex/latex/listings/lstmisc.sty
File: lstmisc.sty 2020/03/24 1.8d (Carsten Heinz)
\c@lstnumber=\count177
\lst@skipnumbers=\count178
\lst@framebox=\box46
) (c:/texlive/2020/texmf-dist/tex/latex/listings/listings.cfg
File: listings.cfg 2020/03/24 1.8d listings configuration
))
Package: listings 2020/03/24 1.8d (Carsten Heinz)
 (c:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def
File: l3backend-xdvipdfmx.def 2020-03-12 L3 backend support: xdvipdfmx
\g__graphics_track_int=\count179
\l__pdf_internal_box=\box47
\g__pdf_backend_object_int=\count180
\g__pdf_backend_annotation_int=\count181
) (./test.aux)
\openout1 = `test.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 4.
LaTeX Font Info:    Trying to load font information for TS1+cmr on input line 4.
 (c:/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd
File: ts1cmr.fd 2019/12/16 v2.5j Standard LaTeX font definitions
)
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for TU/lmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 4.
LaTeX Font Info:    ... okay on input line 4.
\c@lstlisting=\count182
 (c:/texlive/2020/texmf-dist/tex/latex/listings/lstlang1.sty
File: lstlang1.sty 2020/03/24 1.8d listings language file
) [1

] (./test.aux) ) 
Here is how much of TeX's memory you used:
 1778 strings out of 479418
 27341 string characters out of 5888104
 454354 words of memory out of 5000000
 19355 multiletter control sequences out of 15000+600000
 532346 words of font info for 25 fonts, out of 8000000 for 9000
 1348 hyphenation exceptions out of 8191
 28i,4n,42p,147b,1087s stack positions out of 5000i,500n,10000p,200000b,80000s

Output written on test.pdf (1 page).

在我添加\XeTeXtracingfonts=1\textvisiblespace

\XeTeXtracingfonts=1
\documentclass{article}
\usepackage{listings}

\begin{document}
\textvisiblespace
\begin{lstlisting}[language=python]
    "? {"
\end{lstlisting}
\end{document}

结果: 在此处输入图片描述

日志档案:

This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/W32TeX) (preloaded format=xelatex 2020.11.18)  21 FEB 2021 23:30
entering extended mode
 restricted \write18 enabled.
 file:line:error style messages enabled.
 %&-line parsing enabled.
**test
(./test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06> (c:/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(c:/texlive/2020/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2019/12/20 v1.4l Standard LaTeX file (size option)
Requested font "[lmroman10-regular]:mapping=tex-text;" at 10.0pt
 -> c:/texlive/2020/texmf-dist/fonts/opentype/public/lm/lmroman10-regular.otf
)
\c@part=\count163
\c@section=\count164
\c@subsection=\count165
\c@subsubsection=\count166
\c@paragraph=\count167
\c@subparagraph=\count168
\c@figure=\count169
\c@table=\count170
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen134
) (c:/texlive/2020/texmf-dist/tex/latex/listings/listings.sty (c:/texlive/2020/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks15
)
\lst@mode=\count171
\lst@gtempboxa=\box45
\lst@token=\toks16
\lst@length=\count172
\lst@currlwidth=\dimen135
\lst@column=\count173
\lst@pos=\count174
\lst@lostspace=\dimen136
\lst@width=\dimen137
\lst@newlines=\count175
\lst@lineno=\count176
\lst@maxwidth=\dimen138
 (c:/texlive/2020/texmf-dist/tex/latex/listings/lstmisc.sty
File: lstmisc.sty 2020/03/24 1.8d (Carsten Heinz)
\c@lstnumber=\count177
\lst@skipnumbers=\count178
\lst@framebox=\box46
) (c:/texlive/2020/texmf-dist/tex/latex/listings/listings.cfg
File: listings.cfg 2020/03/24 1.8d listings configuration
))
Package: listings 2020/03/24 1.8d (Carsten Heinz)
 (c:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def
File: l3backend-xdvipdfmx.def 2020-03-12 L3 backend support: xdvipdfmx
\g__graphics_track_int=\count179
\l__pdf_internal_box=\box47
\g__pdf_backend_object_int=\count180
\g__pdf_backend_annotation_int=\count181
) (./test.aux)
\openout1 = `test.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 5.
LaTeX Font Info:    Trying to load font information for TS1+cmr on input line 5.
 (c:/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd
File: ts1cmr.fd 2019/12/16 v2.5j Standard LaTeX font definitions
)
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for TU/lmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
\c@lstlisting=\count182
 (c:/texlive/2020/texmf-dist/tex/latex/listings/lstlang1.sty
File: lstlang1.sty 2020/03/24 1.8d listings language file
) [1

] (./test.aux) ) 
Here is how much of TeX's memory you used:
 1778 strings out of 479418
 27341 string characters out of 5888104
 454355 words of memory out of 5000000
 19355 multiletter control sequences out of 15000+600000
 532346 words of font info for 25 fonts, out of 8000000 for 9000
 1348 hyphenation exceptions out of 8191
 28i,4n,42p,147b,1087s stack positions out of 5000i,500n,10000p,200000b,80000s

Output written on test.pdf (1 page).

答案1

python 语言默认使空格可见,这就是您所看到的符号。

您可以使用 停用此功能 showstringspaces=false

相关内容