Title: Labels not referencing correct number figure
Tags: labels
Question: I have a report where it's required to have sections from another report both in the main body as well as in an appendix, and I'm including them by using the \input{some_section} command.
I'm referring to figures in text by using:
Figure~\ref{fig:something}
Which works fine, but I'm getting warnings because the labels are multiply defined, since they occur in two parts of the report.
Is it possible for me to still reference the same image (essentially) without hard-labeling (i.e. typing Figure 1 in stead of Figure~\ref{fig:something}) ?
Comment: I'm inputting the files twice.

Comment: do you mean you are inputting the files twice, or that labels in the input file clash with labels in the main one?


Here is another answer: You can add a macro to all the labels in the inputted file and either reset it manually or use \thechapter (for example).
\documentclass{report}
\usepackage{mathtools}
\begin{document}
Equation \eqref{first.1} and equation \eqref{first.2} are copies.
\chapter{Main}
\begin{equation}\label{first.\thechapter} a=b \end{equation}
This references the local equation \eqref{first.\thechapter}.
\chapter{Appendix}
\begin{equation}\label{first.\thechapter} a=b \end{equation}
This references the local equation \eqref{first.\thechapter}.
\end{document}
Come to think of it, instead of making many changes to the inputted file, you could use
\let\oldlabel=\label
\renewcommand{\label}[1]{\oldlabel{#1.\thechapter}}
at the beginning and
\let\label=\oldlabel
at the end.

Here is another answer: You probably mean that the \label commands should be processed only the first time the file is input.
Start the file to input with
\ifcsname thisfilehasbeeninput\endcsname
\global\expandafter\let\csname thisfilehasbeeninput\endcsname\relax
\makeatletter
\let\latexlabel\label
\def\label#1{\@bsphack\@esphack}
\makeatother
and end it with
\ifcsname thisfilehasbeeninput\endcsname
\let\label\latexlabel
Instead of thisfilehasbeeninput you might use the file name; the string should be unique for every file you need to input twice.
In case the file hasn't yet been input, a command will be defined and nothing else will be done. If the file has already been input, that command will be defined and the \label command will be turned into a no-op. At the end, the original meaning of \label is restored.

{'source': 'StackExchangeDataset', 'subset': 'tex.stackexchange.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:10/17/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<labels>', 'Title': 'Labels not referencing correct number figure', 'ViewCount': 203, 'id': 207714, 'user_AboutMe': None, 'user_AccountId': 3253122.0, 'user_DisplayName': 'user2742907', 'user_Reputation': 51.0, 'user_Views': 1.0, 'user_id': 64403.0}}