# Block LaTeX from accidentally processing input file

I have several files that contain common definitions for a series of documents I am working with. Often times when I modify a file meant only for inclusion (not a standalone document) I will reflexively tell emacs to compile it. That generates an error and leaves .out and .log files that I have to go clean up.

Is there some way to put an "include block" at the start of the file to tell LaTeX to silently stop if it is processing the current file as a base document?

definitions should be in a .sty file which also makes this test a bit easer.

If mydefs.sty is

\makeatletter
\ifx\@currname\@empty\expandafter\@@end\fi

\def\zz{zzz}


then processing at the top level does not much at all:

\$ pdflatex mydefs.sty
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./mydefs.sty
LaTeX2e <2017/01/01>
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
)
No pages of output.
Transcript written on mydefs.log.


But it can be used as a package as usual:

\documentclass{article}
\usepackage{mydefs}

\begin{document}

\zz

\end{document}


• Thank you. Will investigate using them as style files rather than just raw input. – Craig Jan 12 '17 at 20:20

I have found another way, very similar to what @David posted put the following at the head of the inputted file:

\ifx\indocument\undefined
\stop
\fi


Then in the document put

\def\indocument{}


before the \input. Which is essentially the same answer just not using the package handling infrastructure.