LaTeX 异常排查之“Missing character: There is no + (“2B) in font nullfont!”

文章讲述了作者在使用XeLaTeX编译时遇到的关于nullfont字符缺失的异常,通过在StackExchange找到的解答,发现是由于图形绘制中字符操作的语法问题,如加号使用不当和多余分号导致。作者通过修正这些细节解决了异常。

在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;
}

LaTeX中遇到字体问题时,通常需要从多个角度进行排查。以下是对LaTeX中字体 `cmbx10` 缺少字符 B7 的解决方案: ### 1. 字体安装完整性检查 确保系统中的LaTeX发行版(如TeX Live或MiKTeX)已正确安装所有必要的字体集合。如果缺少某些字体文件,可能会导致类似“Missing character”的错误。可以通过安装额外的字体集合来解决此问题[^1]。例如: ```bash tlmgr install collection-fontsrecommended collection-fontsextra ``` ### 2. 更新与重新生成字体映射 有时字体映射文件可能未正确更新,从而引发字符缺失的问题。可以尝试通过以下命令重新生成字体映射文件: ```bash updmap-sys ``` 这一步会强制更新字体映射表,确保LaTeX能够正确识别和使用所需的字体。 ### 3. 替换字符或调整编码 如果字符B7确实不存在于当前使用的字体中,可以考虑替换为其他等效字符,或者更改文档的字体设置以支持该字符。例如,将字符编码从默认的OT1切换到T1,通常能解决许多字符显示问题: ```latex \usepackage[T1]{fontenc} ``` ### 4. 检查文档代码中的隐藏字符 有时文档中可能存在不可见的特殊字符(如假空格或非法Unicode字符),这些字符可能导致编译器报告“Missing character”错误。可以使用文本编辑器的高级搜索功能,查找并删除这些异常字符。例如,十六进制内容为 `f4 80 80 80` 的字符可能是引起问题的根源[^1]。 ### 5. 使用替代字体 如果上述方法仍无法解决问题,可以尝试更换字体以避免字符缺失。例如,使用Latin Modern字体族作为Computer Modern的替代方案: ```latex \usepackage{lmodern} ``` ### 6. 示例代码调整 以下是调整后的示例代码,包含字体编码设置和替代字体的使用: ```latex \documentclass{article} \usepackage[T1]{fontenc} % 更改字体编码 \usepackage{lmodern} % 使用Latin Modern字体 \begin{document} The missing character B7 can be represented as \textbullet{} or $\cdot$. \end{document} ``` ### 7. 验证ghostscript版本 如果问题与Ghostscript相关,可以尝试回退到较旧版本的Ghostscript,或者确保XeTeX使用的DLL文件(如xetex.dll)是最新的且兼容当前环境[^1]。 --- ####
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值