% Copyright 2019 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.
%
% In addition to the above licenses, this particular file may also be
% directly inlined into other documents and this copyright notice may
% be removed. Additionally, when you inline this file, you may modify
% it as needed and you may remove comments.
%
% This file is intended to be distributed or even inlined into a file
% when a document needs to be typeset on a system that does not have
% pgf/TikZ installed.

% "environment" for reading an external graphic. Note that there are
% no (!) braces around the "name" of the environment
%
% #1 = name of the graphics file
%
% Example:
%
% \beginpgfgraphicnamed{mygraph}
%   \begin{tikzpicture}
%     ...
%   \end{tikzpicture}
% \endpgfgraphicnamed

\long\def\beginpgfgraphicnamed#1#2\endpgfgraphicnamed{%
    \begingroup
    \setbox1=\hbox{\includegraphics{#1}}%
    \openin1=#1.dpth
    \ifeof1    \box1
    \else
        \read1 to\pgfincludeexternalgraphicsdp    \closein1
        \dimen0=\pgfincludeexternalgraphicsdp\relax
        \hbox{\lower\dimen0 \box1 }%
    \fi
    \endgroup
}
