%D A fixed variant if the t-tikz module distributed with tikz.

\ifdefined\pdflastxpos \else
    \unprotect
        \frozen\overloaded\protected\def\pdflastxpos{\numexpr\clf_lastxpos\relax}
        \frozen\overloaded\protected\def\pdflastypos{\numexpr\clf_lastypos\relax}
    \protect
\fi


\pushoverloadmode

    \pushcatcodetable

        \setcatcodetable\texcatcodes

        \catcode`\@=11
        \catcode`\|=12
        \catcode`\!=12

        \input t-pgf.tex
        \input t-pgffor.tex
        \input tikz.code.tex

    \popcatcodetable

\popoverloadmode

\permanent\protected\def\tikzerrormessage#1#2#3%
  {\writestatus{#1}{#2}}

\ifcase\contextlmtxmode

    \let\starttikzsettings\relax
    \let\stoptikzsettings \relax

    \protected\def\starttikzpicture
      {% \dontleavehmode
       \begingroup
       \ifdefined\PackageError\else \let\PackageError\tikzerrormessage \fi
       \tikzpicture}

    \protected\def\stoptikzpicture
      {\endtikzpicture
       \endgroup}

\else

    % for now:

    \overloadmode\zerocount

    % but this will be mandate for settings outside the start .. stop

    \permanent\protected\def\starttikzsettings
      {\pushoverloadmode}

    \permanent\protected\def\stoptikzsettings
      {\popoverloadmode}

    \permanent\protected\def\starttikzpicture
      {\dontleavehmode
       \hcontainer\bgroup
     % \pushoverloadmode
       \ifdefined\PackageError\else \let\PackageError\tikzerrormessage \fi
       \tikzpicture}

    \permanent\protected\def\stoptikzpicture
      {\endtikzpicture
     % \popoverloadmode
       \egroup}

\fi

% \input t-pgf.tex

\ifx\pgfdefined\undefined

    \let\pgfdefined\relax

   % \input t-pgfcor.tex

    \ifx\pgfcoredefined\undefined

        \let\pgfcoredefined=\relax

        \input t-pgfsys.tex

        \edef\pgfcoreatcode     {\the\catcode`\@}
        \edef\pgfcorebarcode    {\the\catcode`\|}
        \edef\pgfcoreexclaimcode{\the\catcode`\!}

        \catcode`\@=11
        \catcode`\|=12
        \catcode`\!=12

        \input pgfcore.code.tex

        \catcode`\@=\pgfcoreatcode
        \catcode`\|=\pgfcorebarcode
        \catcode`\!=\pgfcoreexclaimcode

        \let\startpgfpicture             \pgfpicture              \let\stoppgfpicture            \endpgfpicture
        \let\startpgfscope               \pgfscope                \let\stoppgfscope              \endpgfscope
        \let\startpgflowlevelscope       \pgflowlevelscope        \let\stoppgflowlevelscope      \endpgflowlevelscope
        \let\startpgfinterruptpath       \pgfinterruptpath        \let\stoppgfinterruptpath      \endpgfinterruptpath
        \let\startpgfinterruptpicture    \pgfinterruptpicture     \let\stoppgfinterruptpicture   \endpgfinterruptpicture
        \let\startpgfinterruptboundingbox\pgfinterruptboundinbox  \let\stoppgfinterruptboudingbox\endpgfinterruptboundingbox

    \fi

    \usepgfmodule[shapes,plot]

\fi

\stopmodule
