% \iffalse meta-comment
% An Infrastructure for Semantic Macros and Module Scoping
% Copyright (c) 2019 Michael Kohlhase, all rights reserved
%                this file is released under the
%                LaTeX Project Public License (LPPL)
% 
% The original of this file is in the public repository at 
% http://github.com/sLaTeX/sTeX/
%
% TODO update copyright  
%
%<*driver>
\def\stexdocpath{../doc}
\input{\stexdocpath/stex-docheader}
\stextoptitle{Tikzinput: Treating TIKZ code as images}{tikzinput}
\docmodule{chapter}
%</driver>
% \fi
%
% \begin{stexmanual}
%    \begin{sfragment}{Tikzinput Manual}
	%      \input{\stexdocpath/packages/stex-tikzinput}
%    \end{sfragment}
% \end{stexmanual}
%
% \begin{documentation}
%    \begin{sfragment}{Tikzinput Documentation}
%       TODO
%    \end{sfragment}
% \end{documentation}
%
% \begin{implementation}\label{pkg:tikzinput:impl}
%
% \begin{sfragment}{Tikzinput Implementation}
%
%    \begin{macrocode}
%<@@=tikzinput>
%<*package>

%%%%%%%%%%%%%   tikzinput.dtx   %%%%%%%%%%%%%

%    \end{macrocode}
%
%    \begin{macrocode}
\ProvidesExplPackage{tikzinput}{2025/11/11}{4.0.0}{tikzinput package}
\RequirePackage{l3keys2e}

\keys_define:nn { tikzinput } {
  image   .bool_set:N   = \c_tikzinput_image_bool,
  image   .default:n    = false ,
  unknown   .code:n       = {}
}

\ProcessKeysOptions { tikzinput }

\bool_if:NTF \c_tikzinput_image_bool {
  \RequirePackage{graphicx}

  \providecommand\usetikzlibrary[]{}
  \newcommand\tikzinput[2][]{\includegraphics[#1]{#2}}
}{
  \RequirePackage{tikz}
  \RequirePackage{standalone}

  \newcommand \tikzinput [2] [] {
    \setkeys{Gin}{#1}
    \ifx \Gin@ewidth \Gin@exclamation
      \ifx \Gin@eheight \Gin@exclamation
        \input { #2 }
      \else
        \resizebox{!}{ \Gin@eheight }{
          \input { #2 }
        }
      \fi
    \else
      \ifx \Gin@eheight \Gin@exclamation
        \resizebox{ \Gin@ewidth }{!}{
          \input { #2 }
        }
      \else
        \resizebox{ \Gin@ewidth }{ \Gin@eheight }{
          \input { #2 }
        }
      \fi
    \fi
  }
}

\newcommand \ctikzinput [2] [] {
  \begin{center}
    \tikzinput [#1] {#2}
  \end{center}
}
%    \end{macrocode}
%
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \end{sfragment}
% \end{implementation}
%
\endinput
% Local Variables:
% mode: doctex
% TeX-master: t
% End:

%  LocalWords:  libfolder jobname.dtx tikzinput.dtx usetikzlibrary Gin@ewidth Gin@eheight
%  LocalWords:  ctikzinput mhpath pgfkeys@spdef pgfutil@empty 1@atcode catcode l_tmpa_str
%  LocalWords:  pgfutil@InputIfFileExists libusetikzlibrary msg_error:nnn notinarchive
%  LocalWords:  seq_clear:N seq_set_eq:NN l_tmpa_seq c_stex_mathhub_seq seq_set_split:NnV
%  LocalWords:  l_tmpb_seq seq_if_empty_p:N tikzlibrary seq_put_right:No seq_pop_left:NN
