Question: What steps are required to use the xr
package in LyX in order to reference items in other, independent LyX documents?
Steps already taken:
- The
tools
package (that contains thexr
package) has been installed in MikTeX. - The
xr
package has been used in the referencing document (by adding\usepackage{xr}
to the referencing document's preamble). - A pointer to the referenced document has been set in the referencing document (by adding
\externaldocument{referenced.lyx}
to the referencing document's preamble). - A label in the referenced document has been cross-referenced in the the referencing document using the
\ref
tag.
Observed (undesired) behavior: The reference appears as "BROKEN" in the LyX editor. The PDF output shows "??" where the reference number is expected.
Relevant links:
Software used: LyX + MiKTeX + BibTeX on Windows 7
My level of Lyx/LaTeX proficiency: Beginner+
Best Answer
I have been trying to get
xr
andxcite
working for past couple days in LyX and this post and the links it cites were about all I could find as references. Since the current answer doesn't fully explain what is going on in LyX, I'll give what works for me for usingxr
(orxcite
) with LyX:Put
into the LaTeX preamble in Document->Settings of the referencing document (I will call it
referencing.lyx
).Build the referenced document to obtain
referenced.aux
.You can either do File->Export to export
referenced.tex
and runlatex
on it to generatereferenced.aux
or you build the document normally in LyX with the View command. If you use the View command, you will need to find LyX's temporary directory where it ran latex. This directory should be a subdirectory of theTemporary directory
listed under the Paths section of LyX's Preferences. The LyX subdirectories (there might be more than one depending on how many document you have opened and rendered during the session) will have names starting withlyx_tmpdir
and will contain subdirectories with names beginning withlyx_tmpbuf
. One of theselyx_tmpbuf
directories should containreferenced.aux
(if you start a new LyX session and Viewreferenced.lyx
, it should be easy to find since there shouldn't be a lot of extra LyX directories). (Itai, LyX's temporary directory is usually located in a system temporary directory that does not show up in typical file searches, so that might be why you could not find any.aux
files).Once you have
referenced.aux
, just save it in the same directory asreferencing.lyx
and LyX should find it when it rendersreferencing.pdf
.Other usage notes:
LyX does not have native support for
xr
orxcite
. Initially, the labels inreferenced.lyx
will not appear as options in the cross-reference dialog in LyX. To reference items fromreferenced.lyx
such asreferenced_label1
, you can either do "Insert->TeX Code" and put\ref{referenced_label1}
in by hand, or you can keepreferenced.lyx
open, right-click on the label you want to reference and choose "Copy as reference", and then paste intoreferencing.lyx
at the point where you want to make the reference.Because LyX does not have support for
xr
, pasted labels will show up in LyX with aBROKEN:
prefixed in front of the label. However, they should still be rendered properly in the pdf that is produced. TheBROKEN:
prefix just means that LyX can't find that label defined withinreferencing.lyx
. One way to get around this is to putreferencing.lyx
as a child document (Insert -> File -> Child Document) within a LyX note. Then its labels will show in the cross-reference dialog in LyX, but because the inclusion is within a LyX note, it won't get rendered in the .pdf.Pasted labels will appear in LyX's cross-reference dialog (as
BROKEN:
references). Don't try to reference them from there though because you end up with a reference to a reference.With
xcite
, if you have a separate.bib
file forreferenced.lyx
(call itreferenced.bib
), you can addreferenced.bib
toreferencing.lyx
's bibliography and cite the items normally (rather than copying and pasting references out ofreferenced.lyx
). Then, when you want to render thereferencing.pdf
, removereferenced.bib
from the bibliography. This should break all of the citations withinreferencing.lyx
but they should still be found byxcite
.While searching for how to use
xr
with LyX, I saw references to a combo document option in LyX that would allow it to use the same temporary directory for two LyX files (in which casereferenced.aux
file could be made available toreferencing.lyx
without having to put it in the working directory as described above). As far as I can tell, this feature was removed before LyX 2.0 and is not an option any more.