# in subfile: name{theorem.0.1} has been referenced but does not exist, replaced by a fixed one

since I was not able to find a solution online, which fixed this problem, so I hope someone here can help me :)

Here is my main.tex file:

\documentclass[a4paper,12pt,headsepline]{article}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage{mathtools}
\usepackage[a4paper,left=3.125cm, right=3.125cm, top=2.5cm, bottom=3.0cm]{geometry}
\usepackage{filecontents}
\renewcommand{\baselinestretch}{1.3}
\usepackage{graphicx}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{caption}
\usepackage{cite}
\usepackage{float}
\usepackage{subfiles}
\usepackage{xr}

\usepackage{amsmath}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem{lemma}[theorem]{Lemma}

\externaldocument[X-]{file1}
\externaldocument[G-]{file2}

\begin{document}
\section{abc}

\subfile{file1.tex}

\subfile{file2.tex}

\end{document}


file1 looks like this:

%!TeX root = file1.tex
\documentclass[main.tex]{subfiles}
\begin{document}
\subsection{bla}
\begin{theorem}\label{theorem:fix}
blabla
\end{theorem}
\end{document}


In file2 I'm trying to cross referencing to the theorem like this:

%!TeX root = file2.tex
\documentclass[main.tex]{subfiles}

\begin{document}
... Theorem~\ref{X-theorem:fix} ...
\end{document}


During compilation, I'm getting this warning

name{theorem.0.1} has been referenced but does not exist, replaced by a fixed one


which I imagine produces this problem...

And the output in the pdf looks like this

Theorem 0.1


with the hyperlink pointing just to the top of the document. It doesn't change if I'm compiling main.tex, which produces a large file with all the subfiles or just file2.tex. The interesting thing is, in my opinion, that it somehow knows that I'm trying to reference to something already labeled. Otherwise instead of 0.1, ?? would be standing there. So if I write \label{theorem:fi} instead of \label{theorem:fix}, ?? would be written here rather then 0.1.

• Don't show incomplete snippets. Make a real example that we can use for tests. Aug 12, 2019 at 16:39
• Sorry! I've added now an main.tex file. I hope it's ok so! Aug 12, 2019 at 17:43