# How not to load a file repeatedly?

I created a file version.tex with a git log message. This .tex-file is then included in my main.tex file like this:

\renewcommand{\footsnippy}{%
Author Name,
Title of my Book,  %
\input{version}
}


because footsnippy is used by the document class to print the current date, author, title -- and now the git log -- onto each page.

But: LaTeX now is slowed down quite a bit, because it seems that the \input is now executed on every page. Hrm...

Look:

...
) [11] (./version.tex) [12] (./version.tex) [13] (./version.tex) [14]
(./version.tex) [15] (./version.tex) [16] (./version.tex) [17] (./version.tex)
[18] (./version.tex) [19] (./version.tex) [20] (./version.tex) [21]
(./version.tex) [22]) (./wikitex/00Vorwort.tex (./version.tex) [23]
(./version.tex) [24]) (./version.tex) [25] (./wikitex/teil01beginn.tex
(./version.tex) [26]
...


Is there any way I can circumvent that the file is read again and again?

-
You can save the input in a savebox. –  Marco Daniel Aug 20 '14 at 19:35
@MarcoDaniel Thanks, got it working with this tip and googling. If you make it an answer, you have the chance to get the credit for it. –  towi Aug 20 '14 at 19:58

You can load the file just once, the key is the catchfile package:

\usepackage{catchfile}

\newcommand{\gitinput}[1]{%
\begingroup
\ifcsname gitinput#1\endcsname
\else
\CatchFileDef\temp{#1}{}
\global\expandafter\let\csname gitinput#1\endcsname\temp
\fi
\endgroup
\csname gitinput#1\endcsname
}

\renewcommand{\footsnippy}{%
Author Name,
Title of my Book,
\gitinput{version}
}


When you do \gitinput{version} the first time, the macro \gitinputversion is defined, expanding to the contents of the version.tex file. Then the \gitinputversion command is performed at any call of \gitinput{version}; but the file is not read in more than once.

This has an advantage over setting a reusable box, because the present method will respect the surrounding font shape and font size conditions.

-
Indeed "respect the surrounding font shape and font size conditions" is the advantage. I use the savebox in this specific instance now, but I can imagine, I need your solution another time. Since I had to write the other answer myself, there is no doubt, that your answer is the one to be accepted :-) –  towi Aug 21 '14 at 12:01

Without any package I used a savebox as @MarcoDaniel suggested.

\newsavebox{\tversion}
\savebox{\tversion}{{\tiny\input{version}}}

\renewcommand{\footsnippy}{%
Author Name,
Title of my Book,
\usebox{\tversion}
}


As you can see, I had to add the formatting \tiny into the savebox, because the box itself is saved, not only the loaded file content. This means, that the formatting that was previously done inside the footsnippy command on the \input{version} text does not apply anymore with savebox. So i have to apply it inside the savebox.

-