为正文、图表和表格生成单独的 tex 文件

为正文、图表和表格生成单独的 tex 文件

我想将当前的 LaTeX 文档拆分为三个文件:

  • 正文及图片和表格占位符
  • 人物

端浮点包在编译期间将所有图形和表格移至底部。然后我可以使用 pdftk 从创建的 PDF 中剪切一些页面。但是,我更喜欢生成单独的 .tex 文件,因为我可以从它们生成单独的 Word/OpenOffice 文件(tex2rtf)。

可以自动完成吗?


例子

如果以下是输入文件:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\title{MyExample}
\author{matandked }
\date{October 2015}

\begin{document}

\maketitle

\section{Introduction}

A latex is a stable dispersion (emulsion) of polymer microparticles in an aqueous medium. Latex itself is natural, but synthetic latexes have been made. Synthetic latexes can be made by polymerizing a monomer such as styrene that has been emulsified with surfactants.

\begin{figure}[h]
    \centering
    \includegraphics[width=0.5\textwidth]{Latex}
    \label{Fig:Latex}
    \caption{Example of latex}
\end{figure}

As you can see in figure \ref{Fig:Latex}, latex is a milky fluid. Some key facts you can find in table: \ref{Tab:SomeData}

\begin{table}
\centering
\caption{Some random data to present table}
\label{Tab:SomeData}
\begin{tabular}{lll}
\hline
           & Approach 1 & Approach 2 \\ \hline
Data set 1 & 0.35       & 0.34       \\
Data set 2 & 0.6        & 0.6        \\
Data set 3 & 0.7        & 0,0377     \\ \hline
\end{tabular}
\end{table}

\newpage

The word is also used to refer to natural latex rubber, particularly non-vulcanized rubber. Such is the case in products like latex gloves, latex condoms and latex clothing. Many people are allergic to rubber latex.

\end{document}

我想生成以下单独的文档:

主文本:

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{MyExample}
\author{matandked }
\date{October 2015}

\begin{document}

\maketitle

\section{Introduction}

A latex is a stable dispersion (emulsion) of polymer microparticles in an aqueous medium. Latex itself is natural, but synthetic latexes have been made. Synthetic latexes can be made by polymerizing a monomer such as styrene that has been emulsified with surfactants.

\begin{center}
[Figure 1 here]
\end{center}

As you can see in figure 1, latex is a milky fluid. Some key facts you can find in table: 1

\begin{center}
[Table 1 here]
\end{center}

The word is also used to refer to natural latex rubber, particularly non-vulcanized rubber. Such is the case in products like latex gloves, latex condoms and latex clothing. Many people are allergic to rubber latex.

\end{document}

图形.tex:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\begin{document}

List of figues:
\begin{enumerate}
    \item Example of latex
\end{enumerate}

\newpage

\begin{figure}[h]
    \centering
    \includegraphics[width=0.5\textwidth]{Latex}
    \label{Fig:Latex}
\end{figure}

\end{document}

表格.tex:

 \documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

List of tables:
\begin{enumerate}
    \item Some random data to present table
\end{enumerate}

\newpage

\begin{table}
\centering
\label{Tab:SomeData}
\begin{tabular}{lll}
\hline
           & Approach 1 & Approach 2 \\ \hline
Data set 1 & 0.35       & 0.34       \\
Data set 2 & 0.6        & 0.6        \\
Data set 3 & 0.7        & 0,0377     \\ \hline
\end{tabular}
\end{table}


\end{document}

答案1

一种(半自动)方法是形成三个文件:

  1. 将所有图表和表格写为单独的文件(借助独立包,您可以在本地编译它们,然后将它们作为 TeX 文件或 PDF 文件包含在“主”文件中)

  2. 形成三个“主要”文件:

    • 带有文本的主文件,其中包括带有标题和标签的浮动环境中的图形和表格文件
    • 包含图形的文件,其中仅包含非浮动环境中的图形(无标题和标签)
    • 带有表格的文件,其中只包含与图形相同的表格。

在这方面,该软件包standalone可以提供很大的帮助。使用它,您可以单独编译每个图形和表格,并以此方式测试它们是否符合您的要求。此类图形文件的示例如下:

\documentclass[border=1mm,
               class=article
               preview]{standalone}
\usepackage{...}
\usepackage{...}
%% for easy remember file name is put here file name (if you wish)
        \begin{document}
%%
    \begin{tikzpicture}
... image code ...
    \end{tikzpicture}
        \end{document}

主文件中的软件包从图片和表格文件中standalone剥离出序言,这样它们就可以与我的文件一起编译,或者如果你想加快编译速度,你可以将它们的 pdf 文件(在单独编译图片和表格时生成)包含为begin{document}end{document}

\includegraphics[ ... options if needed ...]{file name}

主要文件:

\documentclass{article}
\usepackage{standalone}
%
\usepackage{...}

    \begin{document}
\section{introduction}
your text
\begin{figure}
    \input{file-name}
\caption{Figure 1}
    \label{fig: figure-1}
\end{figure}
... your text  ...
\end{document}

类似地,包含收集到的数据的文件可以是:

\documentclass{article}
\usepackage{standalone}
%
\usepackage{...}

    \begin{document}
\begin{center}%% file of figure 1
    \input{file-name}
\end{center}

\begin{center}%% file of figure 2
    \input{file-name}
\end{center}
\end{document}

用同样的方式,您可以生成表格文件。您可以将表格和图片文件存储在与最小文件相同的文件夹中,也可以将其存储在包含图片和表格的子文件夹中。在这种情况下,您需要定义它们的路径。

相关内容