1

I have a main file (say, main.tex) and two chapters in separate files (labour.tex, health.tex) which the main file reads via \externaldocument (I've also used \input but with the same disappointing results).

I want to write in labour something like:

In Chapter health we find...

How can I reference the name of a file within another file, none of which is the main one?

I've tried the xr package, but as far I can tell (not much, admittedly) it helps cross-reference objects such as equations existing in a separate file, but I couldn't figure out how to reference the name of another file.

  • 2
  • Why do you want to reference the file name? I understand, they have the same names as the chapters, but wouldn't it be better to reference the chapter titles, with \label{chapter:health} and In Chapter \nameref{chapter:health}, making them independent of the the filename? – user31729 Aug 18 '14 at 20:22
  • 2
    use \label as Christian says, with \input then you don't need xr or external document – David Carlisle Aug 18 '14 at 20:24
2

A possible setup... the reference style has to be changed, from some colours and perhaps to "" or something like that.

main.tex

\documentclass{book}
\usepackage{xcolor}
\usepackage{nameref}%
\usepackage{blindtext}
\begin{document}

In Chapter \ref{chapter:health} we see, whereas in Chapter \ref{chapter:labour} it's shown that...

\input{health.tex}


\input{labour.tex}

\end{document}

health.tex

\chapter{This is the Health chapter}\label{chapter:health}%
\blindtext

labour.tex

\chapter{Labour chapter}\label{chapter:labour}
\blindtext
  • And if instead of the title, I want to reference their number (as defined by their respective order of inclusion)? For example, "In Chapter 1 we see, whereas in Chapter 2 it's shown that...", where Chapter 1 was the health file included with \input before the labour file, which would therefore be chapter 2 – user60648 Aug 18 '14 at 21:21
  • Chapter~\ref{chapter:health}, etc. Of course! – user60648 Aug 18 '14 at 22:18
  • @user60648: You did not write, that you want chapter numbers as reference, see your post ;-) See In Chapter health ... this is misleading – user31729 Aug 19 '14 at 3:24
  • Christian, it was an added comment, which did include the word 'instead' at the beginning. I thought it did not merit asking a new question, and was more a follow-up from my original post. Sorry if I've misled anyone! – user60648 Aug 21 '14 at 14:37
  • @user60648: To which comment do you refer? – user31729 Aug 21 '14 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.