É possível inserir figura, legenda, gráfico de outro arquivo tex

É possível inserir figura, legenda, gráfico de outro arquivo tex

Eu tenho dois .texarquivos. O primeiro .texarquivo inclui duas figuras: Fig.1 e Fig.2. Posso cruzar todos os detalhes de cada figura em outro arquivo tex, incluindo gráfico, legenda, número da figura...? Agradecer a todos

O código defile1.tex

\documentclass[preprint,12pt, sort&compress]{elsarticle}
\usepackage{graphicx}
\usepackage{caption,subfig} 
\begin{document}
 This is figure 1
\begin{figure} 
  \centering \includegraphics[width=0.5\linewidth]{example-image-a}
  \caption{This is caption 1}
  \label{fig:1}
\end{figure}   

\begin{figure} 
  \centering \includegraphics[width=0.5\linewidth]{example-image-b}
  \caption{This is caption 2}
  \label{fig:2}
\end{figure}

\end{document}

Nofile2.tex

\documentclass[preprint,12pt, sort&compress]{elsarticle}
\usepackage{graphicx}
\usepackage{caption,subfig}
\usepackage{xcite}
\usepackage{xr-hyper}
\externaldocument{file1}
\begin{document}
Figure \ref{fig:2} is figure in the file1 file. And I want to show it in below
% Figure2
Figure \ref{fig:1} is figure in the file1 file. And I want to show it in below
% Figure1
\end{document}

Responder1

Atualizar!!!

Aviso – código enorme avançando

Redefini figureum pouco o ambiente, captando o conteúdo da figura e da legenda, bem como o rótulo armazenado. Isso salvará um arquivo por ambiente de figura (não por legenda!) nomeado \jobname.figurenumber.fige armazenará um rótulo nomeado figlabel:fooonde fooestá o rótulo dado à legenda.

No segundo arquivo, use \figextref{foo}então para carregar o conteúdo armazenado de volta.

A versão anterior usava o número da figura errado – isso foi corrigido agora. O problema com rótulos definidos de forma múltipla era devido ao 'namespace' errado - o storefigpacote permite especificar um prefixo de driver para as referências. Isso deve ser tratado \externaldocumentcomo uma opção, o exemplo reffilepara isso. Se esta opção storefig driverprefixfor omitida, o prefixo padrão driverserá usado.

Um gargalo é a dependência da hyperrefversão de \labele \newlabel.

... e é claro que não funcionará para figurelessnúmeros, ou seja, para \captionof{...}coisas.

motorista.tex

\documentclass[preprint,12pt, sort&compress]{elsarticle}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subfig} 
\usepackage[driverprefix=mydriver]{storefig}

\begin{document}
This is figure 1
\begin{figure} 
  \centering \includegraphics[width=0.5\linewidth]{example-image-a}
  \caption{This is caption 1}
  \label{fig:1}
\end{figure}   

\begin{figure} 
  \centering \includegraphics[width=0.5\linewidth]{example-image-b}
  \caption{This is caption 2}
  \label{fig:2}
\end{figure}


\end{document}

reffile.tex-- o arquivo que usa a figura armazenada

\documentclass[preprint,12pt, sort&compress]{elsarticle}
\usepackage{graphicx}
\usepackage{caption,subfig}
\usepackage{xcite}
\usepackage{xr-hyper}
\usepackage[driverprefix=mydriver]{storefig}

\externaldocument[\storefigdriverprefix]{driver}
\begin{document}
Figure \ref{fig:2} is figure in the file1 file. And I what to show it in below

% Now fetch the stuff
\figextref[h]{fig:2}% is figure in the file1 file. And I what to show it in below

\end{document}

Aqui está o storefigarquivo do pacote alterado - ele permite o uso correto de referências externas e busca o número da figura no arquivo externo:

\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{storefig}
\RequirePackage{xkeyval}
\RequirePackage{xparse}
\RequirePackage{refcount}
\RequirePackage{letltxmacro}
\RequirePackage{tcolorbox}
\RequirePackage{hyperref}

\DeclareOptionX{driverprefix}[driver]{%
  \gdef\storefig@@driverprefix{#1}%
}

\ExecuteOptionsX{driverprefix=driver}
\ProcessOptionsX

\newcommand{\storefigdriverprefix}{%
  \storefig@@driverprefix%
}


\AtBeginDocument{% 
  \typeout{Package storefig info: Prefix is \storefig@@driverprefix}%
  \def\label#1{%
    \@bsphack
    \begingroup
    \def\label@name{#1}%
    \xdef\@lastlabel{#1}% My hack!
    \label@hook
    \protected@write\@auxout{}{%
      \string\newlabel{#1}{%
        {\@currentlabel}%
        {\thepage}%
        {\@currentlabelname}%
        {\@currentHref}{}%
      }%
    }%
    \endgroup
    \@esphack
  }%
}

\LetLtxMacro\latex@@figure\figure
\let\latex@@endfigure\endfigure


\AtBeginDocument{%
  \RenewDocumentEnvironment{figure}{O{ht}}{%
    \latex@@figure[#1]
    \begingroup
    \tcbverbatimwrite{\jobname.\the\numexpr\value{figure}+1.fig}%
  }{\endtcbverbatimwrite\endgroup%
    % Now load it again
    \input{\jobname.\the\numexpr\value{figure}+1.fig}
    \latex@@endfigure%
    % Store a general label to the .aux file
    \immediate\write\@auxout{%
      \string\newlabel{figlabel:\storefig@@driverprefix:\@lastlabel}{{\jobname.\number\value{figure}.fig}{}{}{}{}}%
    }%
  }
}

\NewDocumentCommand{\figextref}{O{tpb}mo}{%
  \begingroup
  \IfValueTF{#3}{%
    \def\local@driverprefix{#3}%
  }{%
    \def\local@driverprefix{\storefig@@driverprefix}%
  }%
  \latex@@figure[#1]
  \renewcommand{\thefigure}{\getrefnumber{\local@driverprefix#2}}% Redefine the figure counter output according to the value delivered by \
  \InputIfFileExists{\getrefnumber{\local@driverprefix figlabel:\storefig@@driverprefix:#2}}{%
    \typeout{Loading file \local@driverprefix figlabel:\storefig@@driverprefix:#2}%
  }{%
    \typeout{Sorry, not found}%
  }
  \latex@@endfigure
  \endgroup
}


\endinput

insira a descrição da imagem aqui

informação relacionada