是否可以引用另一个 LaTeX 文档中的标签?
一个非常相似的问题已经在这个论坛中被提问和回答过。但是,我想使用 cleverefs 和定理列表,这会使问题更加复杂。此外,另一个问题是 10 年前提出的;也许现在有更好的方法来解决它。
考虑以下 LaTeX 代码,它是从这个答案并将其保存在名为 的文件中test.tex
。
\documentclass[english]{amsart}
\usepackage{babel}
\usepackage{enumitem} % for '\newlist' and '\setlist' macros
\usepackage[colorlinks=true]{hyperref}
%%\usepackage{amsthm} % is loaded automatically by amsart document class
\usepackage[nameinlink]{cleveref}
\newtheorem{thm}{Theorem}[section]
\crefname{thm}{Thm.}{Thms.} % singular and plural forms of label
\newtheorem{cor}[thm]{Corollary}
\crefname{cor}{Cor.}{Cors.} % singular and plural forms of label
\newlist{enumthm}{enumerate}{1} % set up a dedicated enumeration env.
\setlist[enumthm]{label=\upshape(\alph*),ref=\upshape\thethm(\alph*)}
\crefalias{enumthmi}{thm} % alias 'enumthmi' counter to 'thm'
\newlist{enumcor}{enumerate}{1} % set up a second dedicated enumeration env.
\setlist[enumcor]{label=\upshape(\alph*),ref=\upshape\thecor(\alph*)}
\crefalias{enumcori}{cor} % alias 'enumcori' counter to 'cor'
\makeatletter
\newcounter{subcreftmpcnt} %
\newcommand\alphsubformat[1]{(\alph{#1})} %adapt ....
\newcommand\subcref[2][\alphsubformat]{%
\ifcsname r@#2@cref\endcsname
\cref@getcounter {#2}{\mylabel}%
\setcounter{subcreftmpcnt}{\mylabel}%
\alphsubformat{subcreftmpcnt}%
\else ?? \fi}
\makeatother
\begin{document}
\setcounter{section}{1} % just for this example
\begin{thm}\label{Thm:One}
The following properties hold:
\begin{enumthm}
\item\label{Thm:One:1} \(1>0\)
\item\label{Thm:One:2} \(0<1\)
\end{enumthm}
\end{thm}
\begin{cor}\label{Thm:Two}
The following properties hold as well:
\begin{enumcor}
\item\label{Thm:Two:1} \(2>1\)
\item\label{Thm:Two:2} \(1<2\)
\end{enumcor}
\begin{proof}
\subcref{Thm:Two:1} follows from \ref{Thm:One:1} by adding 1 on both sides. Similarly, \subcref{Thm:Two:2} follows from \cref{Thm:One:2}.
\end{proof}
\end{cor}
\end{document}
我运行了lualatex test
两次,两次执行都成功结束。排版的输出为:
现在考虑以下我保存在名为的文件中test2.tex
且大致模仿的LaTeX 代码这回答:
\documentclass{scrartcl}
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[A-]{test}[test.pdf]
\usepackage[nameinlink]{cleveref}
\begin{document}
\ref{A-Thm:Two:1} follows from \ref{A-Thm:One:1} by adding 1 on both sides. Similarly, \ref{A-Thm:Two:2} follows from \ref{A-Thm:One:2}.
\end{document}
当我运行 时lualatex test2
,执行成功结束,排版输出为:
问题
有没有办法让输出中的最后一个引用test2.tex
排版为1.1.(b)而不是1.1(b),其工作方式与方式类似吗test.tex
?
答案1
我test2.tex
用下面的代码替换了代码:
\documentclass{scrartcl}
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[A-]{test}[test.pdf]
\usepackage[nameinlink]{cleveref}
\crefname{thm}{Thm.}{Thms.} % singular and plural forms of label
\begin{document}
\ref{A-Thm:Two:1} follows from \ref{A-Thm:One:1} by adding 1 on both sides. Similarly, \ref{A-Thm:Two:2} follows from \cref{A-Thm:One:2}.
\end{document}
并运行了lualatex test2
两次。执行成功结束,排版输出符合要求: