I am struggling with the creation of cross-references between different files. What I want to do is the following. I want to create two separate documents (books). One of the documents (doc1) will include exercises, and the other document (doc2) will provide the solutions to these exercises. What I want is to create a link after each exercise in doc1 that would say something like: "the solution is here", and when you click on "here", it opens doc2 and takes you to the solution of the exercise.
Similarly, in doc2 there would be a header for each exercise solution stating "this is the solution to exercise x", and when you click on x, it would take you back to doc1 right at the beginning of the exercise.
I looked at many related topics on this forum, and with what I found I thought at first I could do the job with a combination of the hyperref and xr-hyper packages. I tried with something like this:
doc1:
\documentclass[11pt,a4paper,fleqn]{book}
\usepackage{xr-hyper}
\externaldocument[doc2-]{doc2}
\usepackage{hyperref}
\usepackage[nopar]{lipsum}
\begin{document}
\lipsum[1-6]
\\ \\
This is exercise 1 \label{ex1} \\
\lipsum[1-6] \\
Solution is \href{doc2.pdf#correx1}{\textbf{here}}.
\\ \\
This is exercise 2 \label{ex2} \\
\lipsum[1-6] \\
Solution is \href{doc2.pdf#correx2}{\textbf{here}}.
\\ \\
\lipsum[1-6]
\end{document}
and doc2:
\documentclass[11pt,a4paper,fleqn]{book}
\usepackage{xr-hyper}
\externaldocument[doc1-]{doc1}
\usepackage{hyperref}
\usepackage[nopar]{lipsum}
\begin{document}
\lipsum[1-6]
\\ \\
This is the solution to exercise \href{doc1.pdf#ex1}{1} \label{correx1} \\
\lipsum[1-6]
\\ \\
This is the solution to exercise \href{doc1.pdf#ex2}{2} \label{correx2} \\
\lipsum[1-6]
\\ \\
\lipsum[1-6]
\end{document}
In a sense, it works: the hyperlinks are created, and they do open the other document. However, when clicking on the link, it does not lead to the \ref-erenced label, but rather to some random spot of the document. This ruins the whole thing.
Would you have any suggestion?
\\
to end lines outside special contexts such astabular
andarray
. You haven't used anything which is cross-reference-able in either document. No sections or numbered lists of anything like that. So there is nothing to label except the document generally.