![\label 与 refcheck 一起使用时导致空白页](https://linux22.com/image/332723/%5Clabel%20%E4%B8%8E%20refcheck%20%E4%B8%80%E8%B5%B7%E4%BD%BF%E7%94%A8%E6%97%B6%E5%AF%BC%E8%87%B4%E7%A9%BA%E7%99%BD%E9%A1%B5.png)
考虑以下
\documentclass[12pt]{report}
\usepackage[norefs]{refcheck}
\begin{document}
\label{beware}
\chapter{Troubleshooting \LaTeX: what to do when trouble shoots back}
See page~\pageref{beware}; if that doesn't help; run for cover! $\ddot\smile$
\end{document}
章节从第 2 页开始,而不是第 1 页;如果没有 refcheck,这种情况不会发生。这不太烦人,我可以轻松解决它,因为整个文档中目前只有两个标签会触发此问题,而我不需要其中任何一个。或者,几页空白页也不是世界末日。但仍然如此。
答案1
我们可以修改refcheck
的重新定义,\label
以便它仅在激活显示参考选项时为参考标签创建一个框。 可防止它创建一个没有内容的空框,而空框会导致空白页。
\makeatletter
\renewcommand{\label}[1]{\@bsphack\global\@labelledtrue
\gdef\last@lbl{\@verbatim@{#1}}%
\@ifundefined{lab@#1}{\global\@unsdlbltrue
\@warning@rc@{Unused label `#1'}}%
{\global\@unsdlblfalse}%
\if@show@ref
\ifmmode\relax\else
{\setbox0=\vbox{\vss\@setnmmarginlbl}%
\wd0=0pt\ht0=0pt\dp0=0pt%
\ifvmode
\@tempdima=\prevdepth
\nointerlineskip\box0\nobreak
\prevdepth=\@tempdima
\else
\vadjust{\box0\nobreak}%
\fi}%
\else\relax
\fi
\fi
\@@label@@{#1}\@esphack}%
\makeatother
但是,这不能在前言中完成,否则编译会失败并出现致命错误。因此,我们将重新定义包装在 中以延迟执行,同时保持整洁并避免在环境中\AtBeginDocument{}
使用。\makeatletter
document
\documentclass[12pt]{report}
\usepackage[norefs]{refcheck}
\makeatletter
\AtBeginDocument{%
\renewcommand{\label}[1]{\@bsphack\global\@labelledtrue
\gdef\last@lbl{\@verbatim@{#1}}%
\@ifundefined{lab@#1}{\global\@unsdlbltrue
\@warning@rc@{Unused label `#1'}}%
{\global\@unsdlblfalse}%
\if@show@ref
\ifmmode\relax\else
{\setbox0=\vbox{\vss\@setnmmarginlbl}%
\wd0=0pt\ht0=0pt\dp0=0pt%
\ifvmode
\@tempdima=\prevdepth
\nointerlineskip\box0\nobreak
\prevdepth=\@tempdima
\else
\vadjust{\box0\nobreak}%
\fi}%
\else\relax
\fi
\fi
\@@label@@{#1}\@esphack}%
}
\makeatother
\begin{document}
\label{beware}
\chapter{Troubleshooting \LaTeX: what to do when trouble shoots back}
See page~\pageref{beware}; if that doesn't help; run for cover! $\ddot\smile$
\end{document}