Is it possible to reference a label in another LaTeX document?
A very similar question has already been asked and answered in this forum. However, I'd like to use cleverefs and theorem lists which makes the problem more complex. Furthermore, the other question was asked 10 years ago; perhaps there are better ways to solve it now.
Consider the following LaTeX code which is copied from this answer and which I saved in a file named 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}
I ran lualatex test twice, and both executions ended successfully. The typeset output was:
Now consider the following LaTeX code that I saved in a file named test2.tex and which is loosely modeled on this answer:
\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}
When I run lualatex test2, the execution ends successfully, and the typeset output is:
Questions
Is there a way to get the last reference in the output from test2.tex to typeset as Thm. 1.1.(b) rather than 1.1(b), in a similar manner to the way test.tex works?



\subcrefthat you have not defined. – David Carlisle Jul 08 '21 at 09:04\subcrefto\refand it seems to work. Thanks. – Evan Aad Jul 08 '21 at 09:12test2.texto typeset as Thm. 1.1.(b) rather than as 1.1(b), just like the output fromtest.tex? – Evan Aad Jul 08 '21 at 09:14\subcrefits'\cref, and it's supposed to be available in packagecleveref. – Evan Aad Jul 08 '21 at 09:21