Cross Reference problem
I don't think \chapter
is defined for the standalone document class. Besides this, for me this sounds more like a job for the subfiles
package then for standalone
:
main.tex:
\documentclass{book}
\usepackage{subfiles}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage{xstring}
\begin{document}
\subfile{chapter1}
\subfile{chapter2}
\end{document}
and chapter1.tex
% !TeX root = chapter1.tex
\documentclass[main]{subfiles}
\begin{document}
\chapter{chapter}
\label{ch:first_chapter}
\section{first section}\label{sc:first_section}
some Text..........
\end{document}
and chapter2.tex
% !TeX root = chapter2.tex
\documentclass[main]{subfiles}
\IfEq{\jobname}{\detokenize{main}}{}{%
\externaldocument{chapter1}
}
\begin{document}
\chapter{Second Chapter}
\label{ch:second_chapter}
\section{section}\label{sc:first_section_ch2}
Some text...text \ref{sc:first_section}
\end{document}
(the above example assumes that all 3 files are in the same folder, for the usage of subfolders, you have to adjust the paths of the main file and the chapter files accordingly)
The /
before Chapter1
in \externaldocument
is wrong. Also standalone
does not have the \chapter
command.
In my point of view, there is nothing to gain to make separate documents from the individual chapter files here.
Both (or all!) files should use hyperref
packages in order to provide the correct label format.
\documentclass{book}
\usepackage{xr-hyper}
\usepackage{hyperref}
\begin{document}
\chapter{chapter}
\label{ch:first_chapter}
\section{first section}\label{sc:first_section}
some Text..........
\end{document}
Chapter2.tex
\documentclass{book}
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[C1-]{Chapter1}
\begin{document}
\chapter{Second Chapter}
\label{ch:second_chapter}
\section{section}\label{sc:first_section_ch2}
Some text...text \ref{C1-sc:first_section}
\end{document}