1

I'm writing a long paper, I have to add many figures, and the code lines for adding all those figures in my paper makes the code hard to read.

Is there a way to for example create a figure1.tex ... figure20.tex, and then just insert them into my main paper to look cleaner?

Bernard
  • 271,350

1 Answers1

4

You asked,

Is there a way to for example create a figure1.tex ... figure20.tex, and then just insert them into my main paper?

Short answer: Yes.

Slightly longer answer: Yes. First, create the files figure1.tex thru figure<n>.tex -- where <n> could be 20 -- with the following overall format:

\begin{figure}[htbp]
% insert relevant code here
\end{figure}

Second, use \input directives in the main tex file to load them in the desired locations, say,

...
\input figure1
...

Note that it's not necessary to specify the .tex extension or to encase the file name in curly braces (a la \input{figure1}).


That said, what you should probably be doing as well is to find an editor that enables code folding, i.e., an editor that has the ability to selectively hide and display -- "fold" -- portions of the file you're currently editing. Among these code portions could be the preamble of a LaTeX document, entire sections (i.e., starting at a \section directive and running to just before the next \section directive), entire environments such as table, figure, theorem, lstlisting, comment etc, and so on. Modern editors can easily provide hierarchical or nested code folding. E.g., you may choose to "fold away" the code that pertains to a lengthy tabular environment inside a table environment.

A serious benefit of using an editor that can provides code folding is that there's no longer a need to maintain lots of secondary files just for the sake of keeping things tidy and manageable; all code portions can be folded away or "unfolded" while being kept in a single file.

Mico
  • 506,678