If what you want to include are common definitions for a project of yours, I recommend you make a package file, say, adampics.sty
:
% Next line is optional
\ProvidesPackage{adampics}[2020-10-10 v1.0 Common definitions for Adam's documents]
\newcommand{\picA}{...}
\newcommand{\picZ}{...}
then just do \usepackage{adampics}
in your documents.
If, for some reason, you do need to read in the complete file and extract a part of it, then you can do something like this. In the file to be input, add two anchors \csname adamSTARTinput\endcsname
and \csname adamSTOPinput\endcsname
:
% loadedfile.tex
\documentclass[11pt]{amsart}
\title{My Tikz Pictures}
\begin{document}
\maketitle
\csname adamSTARTinput\endcsname
\newcommand{\picA}{...}
\newcommand{\picZ}{...}
\csname adamSTOPinput\endcsname
\begin{document}
....
\end{document}
being a \csname ...\endcsname
-generated macro, they will do nothing as long as they aren't defined, so running the document above standalone will proceed normally.
Then in the caller document, do:
\documentclass{article}
\makeatletter
\def\inputfilepart#1{%
\let\adamSTOPinput\endinput
\long\def\loadfilepartaux##1%
\csname adamSTARTinput\endcsname{}
\expandafter\loadfilepartaux\@@input "#1"
}
\makeatother
\begin{document}
\texttt{\meaning\picZ} % undefined
\inputfilepart{loadedfile.tex}
\texttt{\meaning\picZ} % \long macro:->...
\end{document}
(but you have to make sure that the anchors do exist in the loaded file, and that the anchors are not within braces).