在XeLaTeX编译完成后,虽然得到了期望的输出结果,但是我一直苦于这样一个异常:
Missing character: There is no + ("2B) in font nullfont!
今天我在StackExchange看到这样一条,评论区里提到:
because things will break:-) \nullfont
is a built in font guaranteed to have no characters and so if you break that then characters and spacing will go wrong in any code that relies on that guarantee (tikz being a famous example) which uses nullfont as the default font outside node contents to avoid having to catch all spurious characters.
于是我根据提示将异常报错位置附近的一个tikzpicture块复制到一个test.tex文件中,准备如下:
\documentclass[12pt,a4paper,oneside]{ctexart}
\usepackage{tikz} % 绘图库
\usetikzlibrary{quotes}
\usetikzlibrary{angles}
\usetikzlibrary{intersections}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}%计算长度
\usetikzlibrary{decorations.markings}%用来在几何图形旁边标注长度
\usepackage{subcaption} % necessary for subfigure environment
\begin{document}
\begin{figure}[ht]
\def\subwidth{.5\linewidth}
\centering
\begin{subfigure}[b]{\subwidth}
\centering
\begin{tikzpicture}
\path[save path=\pathA](-1,0)circle(2cm);
\path[save path=\pathB](1,0)circle(2cm);
\begin{scope}
\clip[use path=\pathA];
\fill[black!30][use path=\pathB];
\end{scope}
\draw[use path=\pathA];
\draw[use path=\pathB];
\draw(0,0)node{\(A \cap B\)};
\end{tikzpicture}
\subcaption{集合的交}
\end{subfigure}%
\begin{subfigure}[b]{\subwidth}
\centering
\begin{tikzpicture}
\path[save path=\pathA,name path=A](-1,0)circle(2cm);
\path[save path=\pathB,name path=B](1,0)circle(2cm);
\path[fill=black!30][use path=\pathA+\pathB];
\draw[name intersections={of=A and B}]
(intersection-1)arc[start angle=60,end angle=300,radius=2]
(intersection-2)arc[start angle=-120,end angle=120,radius=2]
(intersection-1);
\draw(0,0)node{\(A \cup B\)};
\pgfresetboundingbox
\path[use as bounding box] (-3,-2)rectangle(3,2);
\end{tikzpicture}
\subcaption{集合的并}
\end{subfigure}%
\begin{subfigure}[b]{\linewidth}
\centering
\begin{tikzpicture}
\fill[black!30](0,{sqrt(3)})arc[start angle=60,end angle=300,radius=2]
arc[start angle=240,end angle=120,radius=2];
\draw(-1,0)circle(2cm);
\draw(1,0)circle(2cm);
\draw(-2,0)node{\(A-B\)};
\pgfresetboundingbox
\path[use as bounding box] (-3,-2)rectangle(3,2);
\end{tikzpicture}
\subcaption{集合的差}
\end{subfigure}%
\caption{韦恩图}
\label{figure:集合论.韦恩图}
\end{figure}
\end{document}
果不其然,引擎给出了nullfont警告。
这里只要一搜索就能定位到一句:
\path[fill=black!30][use path=\pathA+\pathB];
中用到了加号(+)。
于是我将这附近的代码修改为
\begin{tikzpicture}
\filldraw[fill=black!30,draw=black]
(0,{sqrt(3)})arc[start angle=60,end angle=300,radius=2]
arc[start angle=240,end angle=480,radius=2];
\draw(0,0)node{\(A \cup B\)};
\pgfresetboundingbox
\path[use as bounding box] (-3,-2)rectangle(3,2);
\end{tikzpicture}
异常警告就消失了。
类似地,下面这段代码的第7行有两个分号,但只需要一个分号,多了一个分号,导致异常警告:Missing character: There is no ; ("3B) in font nullfont!
\begin{scope}[>=Stealth,->]
\draw(0,0)node[below left]{\(O\)}
--(4,0)node[below]{\(x\)}
node[midway,below=.5cm]{\(\begin{array}[t]{l}
x=yz \\
0<z<1
\end{array}\)};;
\draw(0,0)--(0,4)node[left]{\(y\)};
\end{scope}
下面这段代码第8行的\fi命令后有一个多余的分号,也会导致异常警告:Missing character: There is no ; ("3B) in font nullfont!
\foreach \i in {-1,...,3} {
\draw[ultra thick,orange] (\i,\i+1)--(\i+1,\i+1);
\fill[kx] (\i,\i+1)circle(2pt);
\fill[sx] (\i+1,\i+1)circle(2pt);
\ifnum\i=0\relax\else
\draw(\i,0)node[below right]{\i};
\draw(0,\i)node[above right]{\i};
\fi;
}
因篇幅问题不能全部显示,请点此查看更多更全内容