2

I would like to split my current LaTeX document to three files:

  • main text with figures and tables placeholders
  • figures
  • tables

endfloat package move all figures and tables during compilation to the bottom. Than I can use pdftk to cut some pages from created PDF. However, I prefer to generate separate .tex files, because I will be able to generate separate Word/OpenOffice files from them (tex2rtf).

Is it possible to do that automatically?


Example.

If following will be an input file:

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

I would like to generate following, separate documents:

Main.tex:

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

Figures.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}

Tables.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}
  • please add a minimal example of your current code and examples of 3 files. – touhami Oct 2 '15 at 14:03
  • @touhami thank you for comment - I added an example. – matandked Oct 3 '15 at 18:59
  • I think extracting tables.tex and figures.tex is easy using answers or fancyfrb packages. For main.tex that need some work. – touhami Oct 3 '15 at 19:08
3

One (semi automatic) way is to form three files:

  1. write all figures and tables as separate files (with help of standalone package you can compile them locally and them include them in "main" files as TeX files or as PDF files)

  2. form three "main" files:

    • main files with text, in which you include figure's and table's files in float environments with captions and labels
    • file with figures in which you include only figures in non-float environment (without captions and labels)
    • file with tables, in which you include only tables on the same was as you do with figures.

In this the package standalone can be of big help. With its use, you can individually compile each figure and table and on this way tested, if they are as you like to to have them. Example of such figure file is:

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

Package standalone in main files strip preamble with begin{document} and end{document} from images and table files, so they can be compiled with mine files or if you lie to speed-up compilation, you can include their pdf files (which are generated at individual compilation of figures and tables) as

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

The main documents:

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

Similarly the file with collected figures can be:

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

On the same way you can form file of tables. Files of tables and figures you can store in the same folder as min files or in subfolders with figures and tables. In this case you need to define path to them.

  • In the main document, Is it possible to input the labels only (as defined in each standalone tex file), for cross-referencing purposes, without actually including the images and captions themselves? – Nicholas Hamilton Oct 29 '16 at 23:20
  • I'm not sure, if I understand your question, so I suggest you to ask it in question, where it will be better visible to others. Use of \incledeonly and include pair in main document enable to consider sub documents' labels in main document. – Zarko Oct 29 '16 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.