같은 번호를 가진 다른 문서의 그림 복제

같은 번호를 가진 다른 문서의 그림 복제

여러 이미지가 포함된 큰 문서가 있는데 표시 방법, 그림 번호 매기기, 인용, 표 등의 참조 번호 매기기를 유지하면서 이러한 이미지 중 일부를 개별 pdf 문서에 복제하고 싶습니다. 예를 들어, 주 문서에서 그림 번호가 1.3이라면 그림 1.1과 1.2가 다른 문서에 존재하지 않음에도 불구하고 다른 문서에서는 여전히 1.3입니다. 캡션의 모든 참조에 대해서도 마찬가지입니다. 즉:

\caption{Something referencing Table \ref{tab:example} and citing \cite{examplecite}.}

"그림 1.3: 표 1.2를 참조하고 [15]를 인용하는 내용"으로 표시됩니다. 표 1.1이 없거나 후자 문서에 1-14번 인용이 없음에도 불구하고 두 문서 모두에 있습니다.

이를 달성하는 매우 수동적인 방법은 새 tex 문서에 내 서문을 복제하고, 관련 그림만 복사한 다음, \cite{Example}등의 인스턴스를 실제 번호로 대체하여 번호 매기기를 보존한 다음 이를 사용하여 내가 찾고 있는 pdf입니다. 이것은 효과가 있지만 끔찍한 해결책입니다.

이 문제를 가장 잘 해결하는 방법을 알고 싶습니다. 나는 MWE를 만드는 방법을 모르기 때문에 완전히 코딩된 작업 예제가 아닌 시도해 볼 아이디어를 찾고 있습니다.

답변1

당신은 시도하고 싶습니다 xr. 이것은 도식적인 "긴" 파일입니다 ulysseslong.tex.

\documentclass{article}

\begin{document}

\section{Test}\label{sec:test}

\begin{figure}[htp]
\centering
\fbox{\rule{0pt}{3cm}\rule{3cm}{0pt}}
\caption{A caption\label{fig:A}}
\end{figure}

\begin{figure}[htp]
\centering
\fbox{\rule{0pt}{3cm}\rule{3cm}{0pt}}
\caption{B caption\label{fig:B}}
\end{figure}

\begin{figure}[htp]
\centering
\fbox{\rule{0pt}{3cm}\rule{3cm}{0pt}}
\caption{C caption with a reference to Section~\ref{sec:test}\label{fig:C}}
\end{figure}

\begin{figure}[htp]
\centering
\fbox{\rule{0pt}{3cm}\rule{3cm}{0pt}}
\caption{D caption\label{fig:D}}
\end{figure}

\begin{table}[htp]
\centering
\caption{A table caption\label{tab:A}}
\medskip
\begin{tabular}{cc}
a & b \\
c & d
\end{tabular}
\end{table}

\begin{table}[htp]
\centering
\caption{B table caption\label{tab:B}}
\medskip
\begin{tabular}{cc}
a & b \\
c & d
\end{tabular}
\end{table}

\end{document}

다음은 "짧은" 버전입니다 ulyssesshort.tex.

\documentclass{article}

\usepackage{xr}
\externaldocument{ulysseslong}

\makeatletter
\newcommand{\extref}[1]{%
  \@namedef{the\@captype}{\ref{#1}}%
}
\makeatother

\begin{document}

\begin{figure}[htp]
\centering\extref{fig:C}
\fbox{\rule{0pt}{3cm}\rule{3cm}{0pt}}
\caption{C caption with a reference to Section~\ref{sec:test}}
\end{figure}

\begin{figure}[htp]
\centering\extref{fig:D}
\fbox{\rule{0pt}{3cm}\rule{3cm}{0pt}}
\caption{D caption}
\end{figure}

\begin{table}[htp]
\centering\extref{tab:B}
\caption{B table caption}
\medskip
\begin{tabular}{cc}
a & b \\
c & d
\end{tabular}
\end{table}

\end{document}

의 모든 상호 참조가 ulysseslong.tex해결된 경우 처리 결과는 다음과 같습니다 ulyssesshort.tex.

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

답변2

내가 올바르게 이해했다면 다음과 같이 할 수 있습니다.

주요 문서

\documentclass{article}
\usepackage{mwe} % just for the example


\let\mtincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{%
\mtincludegraphics[#1]{#2}%
\immediate\write\mt{\string\mtfigureinserted{#2}{\thefigure}}}

\newwrite\mt
\AtBeginDocument{\immediate\openout\mt=\jobname.img}
\AtEndDocument{\immediate\closeout\mt}

\begin{document}
\lipsum[1-2]
\begin{figure}
\includegraphics{example-image-a}
\caption{example-image-caption}
\label{imga}
\end{figure}
\lipsum[1-2]
\begin{figure}
\includegraphics{example-image-b}
\caption{example-image-caption}
\label{imgb}
\end{figure}
\lipsum[1-2]
\begin{figure}
\includegraphics{example-image-c}
\caption{example-image-caption}
\label{imgc}
\end{figure}
\end{document}

외부 파일에 정보가 기록됩니다. mainfilename.img 새 파일

\documentclass{article}
\usepackage{mwe}

\newcommand*{\myimage}{}
\newcommand*{\myfile}{example-image-c}
\newcommand*{\mtfigureinserted}[2]{%
\renewcommand*\myimage{#1}%
\ifx\myimage\myfile
\setcounter{figure}{#2}%
\fi}
\input{newtest.img}

\begin{document}
\lipsum[1-2]
\begin{figure}
\includegraphics{\myfile}
\caption{example-image-caption}
\label{imga}
\end{figure}
\end{document}

하나만 설정하면 됩니다 \newcommand*{\myfile}{example-image-c}.

\mtfigureinserted카운터를 figure올바른 값으로 설정합니다.

관련 정보