PhilTeX Forums » Text Editors

Cross references in multiple documents

(2 posts)
  1. bnickel
    Member

    Hi all,

    I'm trying to solve a problem that's come up in producing a large document that I'm breaking up into smaller ones. The basic structure is this.

    A main document (main.tex) that includes formatting info for the whole project, and individual files for chapters (part1.tex, part2.tex, etc).

    I need to produce a lot of cross-references, mostly to enumerate items within a part, but ideally also to some elements across parts.

    My basic workflow is editing LaTeX documents in emacs using the RefTeX capabilities to produce cross-references. My problem is that when RefTex automatically supplies me with labels (and I'm not willing to give up that convenience), it'll start numbering the labels from scratch for each part.

    Thus, part1.tex might look like this.

    \begin{enumerate}
    \item first thing in part 1.\label{item:1}
    \item second thing in part 1.\label{item:2}
    \end{enumerate}
    Reference to \ref{item:1}

    Correspondingly, part2.tex might look like this.

    \begin{enumerate}
    \setcounter{enumi}{2}
    \item first thing in part 2.\label{item:1}
    \item second thing in part 2.\label{item:2}
    \end{enumerate}
    Reference to \ref{item:1}

    (NB: I've got the \setcounter command just to ensure that the numbers differ between the two parts so I can see whether the cross-referencing works properly.)

    The main document that calls these is the basic main.tex.

    \documentclass{book}

    \begin{document}
    \input{part1}
    \input{part2}
    \end{document}

    The problem is that, because RefTeX starts over in the labels it provides, the cross-references are screwed up. Both of the references in part1.tex and part2.tex shown above will be "3", the number of the enumerate item the last \label{item:1} is attached to.

    In the past, I've simply brute-forced the issue. When it came time for a final compile, I search-and-replaced all of the labels in my code to include unique prefixes for each input-file. For example, all of the item:xx labels in part1.tex would be turned into item-part1:xx labels, mutatis mutandis for part2.tex. But that is ugly, and surely there must be a better way.

    I don't know if there are packages that solve this problem for me (I looked at xr, but couldn't get it to work out for me), or if there is a way to customize RefTeX so that, when it automatically produces labels within one of the parts, it's automatically aware of the labels that are in use in all of the other parts and hence ensures that no duplicates will be created.

    For what it's worth, I'm running TeX on OSX, in case that matters.

    Also, for what it's worth, it doesn't matter whether I use \input or \include to enter the component files. I've read elsewhere that \include produces separate .aux files for each component, but that info seems to be out of date, or at any rate, irrelevant to this issue.

    Posted 4 months ago #
  2. bnickel
    Member

    Hi,

    I figured it out since I posted, so I wanted to share the solution.

    RefTeX in conjunction with AucTeX can keep track of labels across multiple input files so long as all of the files are aware of each other. That's accomplished by putting the following code at the end of each file (master and input files).

    %%% Local Variables:
    %%% TeX-master: "master"
    %%% End:

    Posted 4 months ago #

RSS feed for this topic

Reply

You must log in to post.