2

Positioning a float in a document usually involves not only changing modifiers such as [t] etc, but also moving around the code -- especially figure* environments in twocolumn documents, which have to be seen by the compiler before the page that they should actually appear on.

Moving a long float, in particular, table around multiple times can be quite annoying; in addition, when using version control software, this results in significant diffs where no such significant change has actually occured, and breaks the blame function.

One way that I have tried is

\newcommand{\figureImportantResult}{\begin{figure}...\end{figure}}

(for example, in the preamble) and moving around only \figureImportantResult. This works quite nicely, solving the above problems (only one-line changes not involving the figure environment). However, SyncTeX doesn't quite understand this: each float is only associated with the corresponding \figure... line, not with the definition of the environment -- so applying changes to the environment becomes more cumbersome. The same is true with constructions using the catchfilebetweentags package (see this answer).

What is a good way to deal with this? \include/\input would probably work, yet I would like to keep the whole document in one file (some publishers prefer/require that). I know that I can programmatically replace \include/\input by the content of the respective files before submission, yet this is not what I would prefer to do. Can I hint SyncTeX at a better location of that code? Is there an alternative to \newcommand that SyncTeX understands?

bers
  • 5,404
  • 1
    For long floats I would recommend \input even if you don't like additional files. It also has the advantage that the code will be more readable. Apart from that I would say that you should not move floats around in the code. Let TeX place it where it suits best, that is sort of the idea with floats. If you really want to move it around, wait until the last edition. – StefanH Jan 31 '17 at 10:03
  • Even in the last edition (whatever you think IS the last edition, which can be many times), moving floats around can be a pain, causing the issues with version control that I have mentioned. – bers Jan 31 '17 at 11:36
  • 3
    And I can't help it, "the last edition": http://www.phdcomics.com/comics.php?f=1531 – bers Feb 02 '17 at 10:14

1 Answers1

1

This may not be nice, but it works. Maybe it inspires someone to post a better answer:

% FIGURE DEFINITION
\ifdefined\whichfigure\begin{myfigures}
    \definefigure{FigA}{%
        AAA
    }
    \definefigure{FigB}{%
        BBB
    }
    \definefigure{FigD}{%
        DDD
    }
    \definefigure{FigE}{%
        EEE
    }
\end{myfigures}\fi

\documentclass{article}

% PREAMBLE CODE
\newenvironment{myfigures}{%
    \let\shownfigure\relax%
}{%
    \if\shownfigure\relax%
        \PackageWarning{\string\showfigure}{Figure `\whichfigure' not defined}%
    \fi%
    \endinput%
}
\newcommand{\definefigure}[2]{%
    \def\thisfigure{#1}%
    \ifx\whichfigure\thisfigure%
        \let\shownfigure\thisfigure%
        #2%
    \fi%
}
\newcommand{\showfigure}[1]{%
    \def\whichfigure{#1}%
    \input{\jobname}%
}
% END OF PREAMBLE CODE

\begin{document}
    % FIGURE INCLUSION
    \showfigure{FigA}

    \showfigure{FigB}

    \showfigure{FigC}

    \showfigure{FigE}
\end{document}
bers
  • 5,404