日志文件中有很多“缺少字符”消息

日志文件中有很多“缺少字符”消息

更改箭头的默认尖端会在日志文件中产生大量“缺少字符”消息。这是错误还是 MWE 出了问题?

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}[>=Triangle]
    \draw[->] (0,0) -- (0,1);
\end{tikzpicture}

\end{document}

日志档案 :

[... snip ...]
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
Missing character: There is no p in font nullfont!
Missing character: There is no t in font nullfont!
[... snip ...]

编辑:文件列表:

 *File List*
standalone.cls    2012/09/15 v1.1b Class to compile TeX sub-files standalone
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
   ifpdf.sty    2011/01/30 v2.3 Provides the ifpdf switch (HO)
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
 xkeyval.sty    2012/10/14 v2.6b package option processing (HA)
 xkeyval.tex    2012/10/14 v2.6b key=value parser (HA)
standalone.cfg    2012/09/15 v1.1b Default configuration file for 'standalone' 
class
 article.cls    2007/10/19 v1.4h Standard LaTeX document class
  size10.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
    tikz.sty    2013/12/13 v3.0.0 (rcs-revision 1.142)
     pgf.sty    2013/12/18 v3.0.0 (rcs-revision 1.14)
  pgfrcs.sty    2013/12/20 v3.0.0 (rcs-revision 1.28)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v3.0.0 (rcs-revision 1.7)
graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty    2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2007/01/18 v1.5 graphics configuration of teTeX/TeXLive
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
  pgfsys.sty    2013/11/30 v3.0.0 (rcs-revision 1.47)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2013/09/09  (rcs-revision 1.9)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v3.0.0 (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v3.0.0 (rcs-revision 1.1)
  pgffor.sty    2013/12/13 v3.0.0 (rcs-revision 1.25)
 pgfkeys.sty    
 pgfkeys.code.tex
 pgfmath.sty    
 pgfmath.code.tex
  pgffor.code.tex
    tikz.code.tex
supp-pdf.mkii
 ***********

答案1

TikZ 将字体设置为环境\nullfont内部tikzpicture以删除垃圾,从tikzpicturePGF 手册

接下来,处理环境的内容,并将其中的图形命令放入框中。非图形文本被尽可能地抑制,但环境内的非 pgf 命令{tikzpicture}不应产生任何“输出”,因为这可能会完全扰乱后端驱动程序的定位系统。顺便说一下,抑制普通文本是通过将字体暂时切换为 来完成的\nullfont。但是,您可以“退出”到正常的 TEX 排版。例如,当您指定节点时,就会发生这种情况。

TikZ/PGf 中的命令通常很灵活,它们接受数字(浮点数或整数)或单位作为参数。例如,除法在文件中实现pgfmathfunctions.code.tex

\pgfmathdeclarefunction{divide}{2}{%
  \begingroup
    \pgfmath@x=#1pt\relax
    \pgfmath@y=#2pt\relax
    ...
}

这定义了宏\pgfmathdivide@。参数#1#2存储在维度寄存器\pgfmath@x和中。对于大小写,会附加\pgfmath@y“默认”单位,并且是没有单位的数字。但如果它们包含单位,则附加的字母是垃圾。它们只会被当前字体丢弃,您可以在文件中看到丢失的字符消息。pt#1#2pt\nullfont.log

调试提示

丢失的字符消息也可以在控制台上显示:

\tracinglostchars=2

可以通过 来查看p和的设置位置。文件中可以看到以下几行:t\tracingcommands=1.log

{the letter p}
{the letter t}

(它也用 写入控制台\tracingonline=1。)

现在感兴趣的是宏,它导致了字母的设置:

\tracingmacros=1

然后.log文件包含:

\pgfmathdivide@ #1#2->\begingroup \pgfmath@x =#1pt\relax \pgfmath@y =#2pt\relax
 \let \pgfmath@sign =\pgfmath@empty \ifdim 0pt=\pgfmath@y \pgfmath@error {You'v
e asked me to divide `#1' by `#2', but I cannot divide any number by `#2'}\fi \
afterassignment \pgfmath@xa \c@pgfmath@counta \the \pgfmath@y \relax \ifdim 0pt
=\pgfmath@xa \divide \pgfmath@x by\c@pgfmath@counta \else \ifdim 0pt>\pgfmath@x
 \def \pgfmath@sign {-}\pgfmath@x =-\pgfmath@x \fi \ifdim 0pt>\pgfmath@y \expan
dafter \def \expandafter \pgfmath@sign \expandafter {\pgfmath@sign -}\pgfmath@y
 =-\pgfmath@y \fi \ifdim 1pt>\pgfmath@y \pgfmathreciprocal@ {\pgfmath@tonumber 
{\pgfmath@y }}\pgfmath@x =\pgfmath@sign \pgfmathresult \pgfmath@x \else \def \p
gfmathresult {0}\pgfmath@divide@periodtrue \c@pgfmath@counta =0\relax \pgfmathd
ivide@@ \pgfmath@x =\pgfmath@sign \pgfmathresult pt\relax \fi \fi \pgfmath@retu
rnone \pgfmath@x \endgroup 
#1<-\pgfarrowlength 
#2<-\pgfarrowwidth 
{\begingroup}
{\dimen107}
{the letter p}

Missing character: There is no p in font nullfont!
{the letter t}
Missing character: There is no t in font nullfont!
{\relax}
{\dimen108}
{the letter p}
Missing character: There is no p in font nullfont!
{the letter t}
Missing character: There is no t in font nullfont!
{\relax}

这样就找到了一个“罪魁祸首”:\pgfmathdivide@。继续搜索还会发现 \pgfmathsqrt@\pgfmathcos@\pgfmathtan@。这些是本例中输出垃圾的命令pt,但还有许多其他候选命令,它们也会产生pt

解决方法

可以通过 分配后立即插入清理宏\afterassignment。软件包etoolbox提供了\patchcmd更简单的受影响宏的修补方法:

\tracinglostchars=2
\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\usepackage{etoolbox}
\makeatletter
\def\cleanup@unit#1\@nil{}
\patchcmd{\pgfmathdivide@}{%
  \pgfmath@x=#1pt\relax
  \pgfmath@y=#2pt\relax
}{%
  \afterassignment\cleanup@unit
  \pgfmath@x=#1pt\relax\@nil
  \afterassignment\cleanup@unit
  \pgfmath@y=#2pt\relax\@nil
}{}{%
  \errmessage{Patching \string\pgfmathdivide@\space failed}%
}
\patchcmd{\pgfmathsqrt@}{%
  \expandafter\pgfmath@x#1pt\relax
}{%
  \afterassignment\cleanup@unit
  \expandafter\pgfmath@x#1pt\relax\@nil
}{}{%
  \errmessage{Patching \string\pgfmathsqrt@\space failed}%
}
\patchcmd{\pgfmathcos@}{%
  \expandafter\pgfmath@x#1pt\relax
}{%
  \afterassignment\cleanup@unit
  \expandafter\pgfmath@x#1pt\relax\@nil
}{}{%
  \errmessage{Patching \string\pgfmathcos@\space failed}%
}
\patchcmd{\pgfmathsin@}{%
  \expandafter\pgfmath@x#1pt\relax
}{%
  \afterassignment\cleanup@unit
  \expandafter\pgfmath@x#1pt\relax\@nil
}{}{%
  \errmessage{Patching \string\pgfmathsin@\space failed}%
}
\makeatother

\begin{document}

\begin{tikzpicture}[>=Triangle]
    % \tracingmacros=1
    % \tracingcommands=1
    \draw[->] (0,0) -- (0,1);
\end{tikzpicture}

\end{document}

相关内容