1

I'm working on a document structure template composed of several stand alone documents that can also be included in another document generating a "top level" document. The problem is that all the stand alone documents have the same pre-defined labels for tables in figures (since it is a template, make sense to have all that already pre-defined) so when I compile them in the "top level" document the labels are maked as "duplicated" and the in text cross-references go crazy. Curiously, the List od Tables and List of Figures are woking fine.

Here some example:

Document-A.lyx:

\documentclass{article}
\begin{document}
This document describes subject "A".
\begin{figure}
\caption{First Figure}\label{fig:1}
\end{figure}
See Figure~\ref{fig:1}.
\end{document}

Document-B.lyx: (identical to Doc A, since it is using the same template)

\documentclass{article}
\begin{document}
This document describes subject "B".
\begin{figure}
\caption{First Figure}\label{fig:1}
\end{figure}
See Figure~\ref{fig:1}.
\end{document}

Document-C.lyx: (identical to Doc A, since it is using the same template)

\documentclass{article}
\begin{document}
This document describes subject "C".
\begin{figure}
\caption{First Figure}\label{fig:1}
\end{figure}
See Figure~\ref{fig:1}.
\end{document}

Document-D.lyx: (this oneinclude all others)

\documentclass{article}
\begin{document}
This document has a description of all subjects.
\section{Chapter 1}
\include{Document-A.tex}
\section{Chapter 2}
\include{Document-B.tex}
\section{Chapter 3}
\include{Document-C.tex}
\end{document}

When opening Document-CD.pdf, the lines See Figure~\ref{fig:1}. on Chapters 2 and 3 will be all "See Figure 3", since the label fig:1 on these files will be renamed to "DUPLICATED-fig:1". I don't understant why LyX renames all duplicated labels to the same name, but that's what happening.

Is there a way to correct this issue, preventing LyX to automatically rename the labels or setting a renaming rule, or the only way to solve this issue will be renaming all labels manually?

Thank you very much.

closed as unclear what you're asking by user31729, Stefan Pinnow, Troy, Mico, Andrew Dec 7 '17 at 10:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Hi, welcome. I would probably go to lyx.org and add an issue in their bug tracker. It could be that it's expected behaviour, that they've only implemented a check, and adding of the DUPLICATED string to make it more obvious which labels are duplicated, in which case your issue can be a feature request. If LyX is supposed to make unique labels but doesn't, then it's a bug. – Torbjørn T. Oct 23 '17 at 11:32
  • Hi! I'll take a look in lyx.org to see if anything like this has been reported. If not, I'll report myself. Thanks – JPHanke Oct 23 '17 at 12:27
  • Let's say LyX gets the labels right, i.e. the way you want them. What should it do with all those '\ref{fig:1}'? Does fig:1 in file C reference the figure in file A, B or C? How's LyX supposed to know that? Make your labels unique! – PhilipPirrip Oct 24 '17 at 7:05
  • Yes, after struggle a while with this issue I came to this conclusion, I have to make them unique. Inside Documents A, B and C I have a macro, lets call it "\name", that is defined as the subject. So I use \let and \renewcommand inside Document D to rename the labels and avoid all this mess: \let\newlabel\label \renewcommand{\label}[1]{\newlabel{\name #1}} \let\newref\ref \renewcommand{\ref}[1]{\newref{\name #1}} Thanks for your help, guys! – JPHanke Oct 24 '17 at 10:47
  • 1
    @JPHanke: The redefinition of \label etc. is 'dangerous'. Use the xr or xr-hyper packages in order to grab labels and cross-referencing information from other documents, then apply `\externaldocument[doc-A]{Document-A} etc. – user31729 Oct 31 '17 at 7:02