In C, I can write #pragma once as a preprocessor directive at the top of a header file, which tells any compiler that supports it to include the file a maximum of one time per compilation cycle, regardless of how many times I #include that header file in the other source files. It is a common alternative to #ifndef/#define/#endif include guards, despite not being an officially documented/supported part of the standard.
La(TeX) has several facilities for so-called "include guards", many of which are outlined in the answers to Conditional typesetting / build.
My question is: Does there exist (or is there a possibility of) a construct in (La)TeX analogous to #pragma once in the C language; that is, a directive set on one line of a file which causes that file to be input only one time during the compilation?
MWE for Testing:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{mydefs.tex}
%<-- insert magic *#pragma once*-like line here to prevent errors
\newcommand{\foo}{foo}
\newcommand{\baz}{baz}
\end{filecontents*}
\begin{document}
\input{mydefs}
\input{mydefs}
\foo\ \baz\ test.
\end{document}
Note:
You might say to just use \providecommand and be done with it, which is a valid answer. But I would like to know if what I've proposed is possible with (La)TeX, for science!
\inputcommand to test first. – Ethan Bolker Aug 06 '14 at 16:15\usepackagedoes, I suppose? If you want to do things 'by hand' it's normal to do\csname myresevedname\endcsname\let\myreservedname\endinput(if it's not been defined, the\csnameconstruct will do nothing important, and on a second pass it will be set up equal to\endinput). – Joseph Wright Aug 06 '14 at 16:23gppon LaTeX files. – Raphael Aug 06 '14 at 20:58