다른 tex 파일의 그림, 캡션, 그래픽을 삽입할 수 있나요?

다른 tex 파일의 그림, 캡션, 그래픽을 삽입할 수 있나요?

두 개의 파일이 있습니다 .tex. 첫 번째 .tex파일에는 Fig.1과 Fig.2라는 두 그림이 포함되어 있습니다. 그래픽, 캡션, 그림 번호 등을 포함하여 다른 tex 파일에 있는 각 그림의 전체 세부 사항을 상호 참조할 수 있습니까? 모두 감사합니다

코드file1.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}

에서file2.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}

답변1

업데이트!!!

경고 - 대규모 코드가 앞으로 다가올 것입니다.

figure환경을 조금 재정의하여 그림의 내용과 캡션은 물론 저장된 레이블도 포착했습니다. 이렇게 하면 그림 환경별로(캡션별로!) 이름이 지정된 파일이 저장되고 캡션에 지정된 레이블이 어디에 있는지 \jobname.figurenumber.fig라는 이름의 레이블이 저장됩니다 .figlabel:foofoo

두 번째 파일에서는 \figextref{foo}저장된 콘텐츠를 다시 로드하는 데 사용됩니다.

이전 버전에서는 잘못된 숫자 번호를 사용했습니다. 이제 이 문제가 수정되었습니다. 다중 정의된 레이블의 문제는 잘못된 '네임스페이스'로 인해 발생했습니다. storefig패키지는 참조에 대한 드라이버 접두사를 지정할 수 있도록 허용합니다. 이는 옵션으로 처리되어야 하며 이에 대한 \externaldocument예는 reffile다음과 같습니다. 이 storefig 옵션을 driverprefix생략하면 기본 접두사가 driver사용됩니다.

병목 현상은 의 및 hyperref버전에 따라 다릅니다 . \label\newlabel

...물론, figureless피규어와 같은 \captionof{...}물건에는 작동하지 않습니다.

드라이버.텍스

\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-- 저장된 Figure를 사용하는 파일

\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}

변경된 storefig패키지 파일은 다음과 같습니다. 외부 참조의 올바른 사용을 허용하고 외부 파일에서 그림 번호를 가져옵니다.

\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

여기에 이미지 설명을 입력하세요

관련 정보