我正在研究新的财产制度(见texdoc ltproperties-doc
或在线的),但在引用未知标签时会出现问题。
\NeedsTeXFormat{LaTeX2e}[2023/11/01]
\documentclass{article}
\begin{document}
\section{abc}
\RecordProperties{seq:xyz}{label,page} % save label & page
This one is defined: \RefProperty{seq:xyz}{label} on page \RefProperty{seq:xyz}{page}
This one is not defined: \RefProperty{unknown}{label} on page \RefProperty{unknown}{page} (with default value: \RefProperty[??]{unknown}{page})
\label{seq:abc}
Old style: defined \ref{seq:abc} on \pageref{seq:abc} and undefined \ref{unknown2} on \pageref{unknown2}
\end{document}
日志相关部分:
No file property_test.aux.
LaTeX Warning: Reference `seq:abc' on page 1 undefined on input line 16.
LaTeX Warning: Reference `seq:abc' on page 1 undefined on input line 16.
LaTeX Warning: Reference `unknown2' on page 1 undefined on input line 16.
LaTeX Warning: Reference `unknown2' on page 1 undefined on input line 16.
[1{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./property_test.aux)
LaTeX Warning: There were undefined references.
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
日志:
(./property_test.aux)
LaTeX Warning: Reference `unknown2' on page 1 undefined on input line 16.
LaTeX Warning: Reference `unknown2' on page 1 undefined on input line 16.
[1{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./property_test.aux)
LaTeX Warning: There were undefined references.
引用未知标签不会在日志中产生任何警告,并且除非您设置本地默认值,否则会排版为第 0 页。这是一个错误,还是(可能更可能是)我使用它们不正确?
此外,文档中有一个星号\RefProperty
,但使用\RefProperty*
会产生错误(Use of \??? doesn't match its definition
),所以我不确定该星号代表什么。
答案1
感谢@Ulrike Fischer 的评论,创建一个检查属性并发出警告的命令似乎有效(根据@David Carlisle 更新):
\NeedsTeXFormat{LaTeX2e}[2023/11/01]
\documentclass{article}
\newcommand\MyRef[2]{%
\RefProperty[%
\textbf{??}% default output
\RefUndefinedWarn{#1}{#2}%
]{#1}{#2}%
}
\begin{document}
\section{abc}
\RecordProperties{seq:xyz}{label,page}
Using MyRef: defined \MyRef{seq:xyz}{label} on page \MyRef{seq:xyz}{page} and undefined \MyRef{unknown}{label} on page \MyRef{unknown}{page}
\end{document}
向日志中添加常规警告LaTeX Warning: Reference ``unknown' on page 1 undefined on input line 17
,并且已知参考在后续运行中正常显示。
欢迎提供更好的方法:)