%%
%% This is file `tikzlibrarytikzmark.code.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tikzmark.dtx  (with options: `tikzlibrary')
%% ----------------------------------------------------------------
%% tikzmark --- remembering absolute positioning with TikZ.
%% E-mail: loopspace@mathforge.org
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%% 
\tikzset{%
  remember picture with id/.style={%
    remember picture,
    overlay,
    save picture id=#1,
  },
  every picture/.append style={%
    execute at end picture={%
      \ifpgfrememberpicturepositiononpage%
      \edef\pgf@temp{%
        \noexpand\write\noexpand\pgfutil@auxout{%
        \string\savepicturepage{\pgfpictureid}{\noexpand\thepage}}}%
      \pgf@temp
      \fi%
    },
  },
  save picture id/.code={%
      \protected@write\pgfutil@auxout{}{%
        \string\savepointas{\tikzmark@pp@name{#1}}{\pgfpictureid}{0pt}{0pt}}%
  },
  if picture id/.code args={#1#2#3}{%
    \@ifundefined{save@pt@\tikzmark@pp@name{#1}}{%
      \pgfkeysalso{#3}%
    }{
      \pgfkeysalso{#2}%
    }
  },
  next page/.is choice,
  next page vector/.initial={\pgfqpoint{0pt}{0pt}},
  next page/below/.style={%
    next page vector={\pgfqpoint{0pt}{-\the\paperheight}}%
  },
  next page/above/.style={%
    next page vector={\pgfqpoint{0pt}{\the\paperheight}}%
  },
  next page/left/.style={%
    next page vector={\pgfqpoint{-\the\paperwidth}{0pt}}%
  },
  next page/right/.style={%
    next page vector={\pgfqpoint{\the\paperwidth}{0pt}}%
  },
  next page/ignore/.style={%
    next page vector={\pgfqpoint{0pt}{0pt}}%
  },
  tikzmark prefix/.initial=,%
  tikzmark suffix/.initial=,%
}
\def\tikzmark@pp@name#1{\csname pgfk@/tikz/tikzmark prefix\endcsname#1\csname pgfk@/tikz/tikzmark suffix\endcsname}%
\def\savepointas#1#2#3#4{%
  \expandafter\gdef\csname save@pt@#1\endcsname{#2}%
  \expandafter\gdef\csname save@pt@#1@offset\endcsname{\pgfqpoint{#3}{#4}}%
}
\def\savepicturepage#1#2{%
  \expandafter\gdef\csname save@pg@#1\endcsname{#2}%
}
\def\tmk@labeldef#1,#2\@nil{%
  \edef\tmk@label{\tikzmark@pp@name{#1}}%
  \def\tmk@def{#2}%
}
\tikzdeclarecoordinatesystem{pic}{%
  \pgfutil@in@,{#1}%
  \ifpgfutil@in@%
    \tmk@labeldef#1\@nil
  \else
    \tmk@labeldef#1,(0pt,0pt)\@nil
  \fi
  \@ifundefined{save@pt@\tmk@label}{%
    \tikz@scan@one@point\pgfutil@firstofone\tmk@def
  }{%
      \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
      \pgfsys@getposition{\pgfpictureid}\save@this@pic%
      \pgf@process{\pgfpointorigin\save@this@pic}%
      \pgf@xa=\pgf@x
      \pgf@ya=\pgf@y
      \pgf@process{\pgfpointorigin\save@orig@pic}%
      \advance\pgf@x by -\pgf@xa
      \advance\pgf@y by -\pgf@ya
      \pgf@xa=\pgf@x
      \pgf@ya=\pgf@y
    \pgf@process{\pgfpointorigin\csname save@pt@\tmk@label @offset\endcsname}%
    \advance\pgf@xa by \pgf@x
    \advance\pgf@ya by \pgf@y
      \@ifundefined{save@pg@\csname save@pt@\tmk@label\endcsname}{}{%
        \@ifundefined{save@pg@\pgfpictureid}{}{%
          \pgfkeysvalueof{/tikz/next page vector}%
          \advance \pgf@xa by \csname save@pg@\csname save@pt@\tmk@label\endcsname\endcsname\pgf@x\relax
\advance \pgf@ya by \csname save@pg@\csname save@pt@\tmk@label\endcsname\endcsname\pgf@y\relax
          \advance \pgf@xa by -\csname save@pg@\pgfpictureid\endcsname\pgf@x\relax
\advance \pgf@ya by -\csname save@pg@\pgfpictureid\endcsname\pgf@y\relax
        }%
      }%
      \pgf@x=\pgf@xa
      \pgf@y=\pgf@ya
    \pgftransforminvert
    \pgf@pos@transform{\pgf@x}{\pgf@y}%
    }%
  }
\begingroup
\catcode`\;=\active
\gdef\tikzmark@active#1#2{%
\tikz[remember picture with id=#2] #1;}
\endgroup
\def\tikzmark@nonactive#1#2{%
\tikz[remember picture with id=#2] #1;}
\newcommand\tikzmark@outside[2][]{%
  \ifnum\catcode`\;=\active
   \let\tikzmark@next=\tikzmark@active
  \else
   \let\tikzmark@next=\tikzmark@nonactive
  \fi
  \tikzmark@next{#1}{#2}%
}
\def\tikzmark@inside#1#2{%
  \tikzset{remember picture}%
  \tikz@scan@one@point\pgfutil@firstofone#2\relax
  \protected@write\pgfutil@auxout{}{%
    \string\savepointas{\tikzmark@pp@name{#1}}{\pgfpictureid}{\the\pgf@x pt}{\the\pgf@y pt}}%
}
\def\tikzmark{%
  \ifx\pgfpictureid\@undefined
  \let\tikzmark@next=\tikzmark@outside
  \else
  \let\tikzmark@next=\tikzmark@inside
  \fi
  \tikzmark@next%
}
\newcommand\pgfmark[1]{%
    \bgroup
    \global\advance\pgf@picture@serial@count by1\relax%
    \edef\pgfpictureid{pgfid\the\pgf@picture@serial@count}%
      \pgfsys@markposition{\pgfpictureid}%
    \edef\pgf@temp{%
      \noexpand\write\noexpand\pgfutil@auxout{%
        \string\savepicturepage{\pgfpictureid}{\noexpand\thepage}}}%
    \pgf@temp
    \protected@write\pgfutil@auxout{}{%
      \string\savepointas{\tikzmark@pp@name{#1}}{\pgfpictureid}{0pt}{0pt}}%
    \egroup
  }
\@ifclassloaded{beamer}{
  \renewcommand<>{\tikzmark}[2][]{\only#3{\beameroriginal{\tikzmark}[{#1}]{#2}}}
}{}
\@ifclassloaded{beamer}{
  \renewcommand<>{\pgfmark}[1]{\only#2{\beameroriginal{\pgfmark}{#1}}}
}{}
\@ifclassloaded{beamer}{
  \tikzset{
    tikzmark suffix=-\the\beamer@slideinframe
  }
}{}
\newcommand\iftikzmark[3]{%
    \@ifundefined{save@pt@#1}{%
      #3%
    }{%
      #2%
    }%
  }%
\newcommand\subnode[3][]{%
  \begingroup
  \pgfmark{#2}%
  \setbox\pgfnodeparttextbox=\hbox\bgroup #3\egroup
  \def\tikz@shape{rectangle}%
  \def\tikz@anchor{center}%
  \def\tikz@fig@name{#2}%
  \tikzset{every subnode/.try,#1}%
  \pgfpointorigin
  \tikz@scan@one@point\pgfutil@firstofone(pic cs:#2)\relax
  \advance\pgf@x by .5\wd\pgfnodeparttextbox
  \advance\pgf@y by .5\ht\pgfnodeparttextbox
  \advance\pgf@y by -.5\dp\pgfnodeparttextbox
  \pgftransformshift{}%
  \setbox\@tempboxa=\hbox\bgroup
  \pgfutil@ifundefined{pgf@sh@s@\tikz@shape}%
  {\PackageError{pgf}{Unknown shape ``\tikz@shape''}{}}%
  {%
    {%
      \let\pgf@sh@savedmacros=\pgfutil@empty% MW
      \let\pgf@sh@savedpoints=\pgfutil@empty%
      \def\pgf@sm@shape@name{\tikz@shape}% CJ % TT added prefix!
      \csname pgf@sh@s@\tikz@shape\endcsname%
      \pgf@sh@savedpoints%
      \pgf@sh@savedmacros% MW
      \pgftransformshift{%
        \pgf@sh@reanchor{\tikz@shape}{\tikz@anchor}%
        \pgf@x=-\pgf@x%
        \pgf@y=-\pgf@y%
      }%
      \expandafter\pgfsavepgf@process\csname pgf@sh@sa@\tikz@fig@name\endcsname{%
       \pgf@sh@reanchor{\tikz@shape}{\tikz@anchor}% FIXME : this is double work!
      }%
      % Save the saved points and the transformation matrix
      \edef\pgf@node@name{\tikz@fig@name}%
      \ifx\pgf@node@name\pgfutil@empty%
      \else%
        \expandafter\xdef\csname pgf@sh@ns@\pgf@node@name\endcsname{\tikz@shape}%
        \edef\pgf@sh@@temp{\noexpand\gdef\expandafter\noexpand\csname pgf@sh@np@\pgf@node@name\endcsname}%
        \expandafter\pgf@sh@@temp\expandafter{\pgf@sh@savedpoints}%
        \edef\pgf@sh@@temp{\noexpand\gdef\expandafter\noexpand\csname pgf@sh@ma@\pgf@node@name\endcsname}% MW
        \expandafter\pgf@sh@@temp\expandafter{\pgf@sh@savedmacros}% MW
        \pgfgettransform\pgf@temp
        \expandafter\xdef\csname pgf@sh@nt@\pgf@node@name\endcsname{\pgf@temp}%
        \expandafter\xdef\csname pgf@sh@pi@\pgf@node@name\endcsname{\pgfpictureid}%
      \fi%
    }%
  }%
  \egroup
  \box\pgfnodeparttextbox
  \endgroup
}
\def\usetikzmarklibrary{\pgfutil@ifnextchar[{\use@tikzmarklibrary}{\use@@tikzmarklibrary}}%}
\def\use@tikzmarklibrary[#1]{\use@@tikzmarklibrary{#1}}
\def\use@@tikzmarklibrary#1{%
  \edef\pgf@list{#1}%
  \pgfutil@for\pgf@temp:=\pgf@list\do{%
    \expandafter\pgfkeys@spdef\expandafter\pgf@temp\expandafter{\pgf@temp}%
    \ifx\pgf@temp\pgfutil@empty
    \else
      \expandafter\ifx\csname tikzmark@library@\pgf@temp @loaded\endcsname\relax%
      \expandafter\global\expandafter\let\csname tikzmark@library@\pgf@temp @loaded\endcsname=\pgfutil@empty%
      \expandafter\edef\csname tikzmark@library@#1@atcode\endcsname{\the\catcode`\@}
      \expandafter\edef\csname tikzmark@library@#1@barcode\endcsname{\the\catcode`\|}
      \catcode`\@=11
      \catcode`\|=12
      \pgfutil@InputIfFileExists{tikzmarklibrary\pgf@temp.code.tex}{}{
          \PackageError{tikzmark}{I did not find the tikzmark extras library '\pgf@temp'.}{}
        }%
      \catcode`\@=\csname tikzmark@library@#1@atcode\endcsname
      \catcode`\|=\csname tikzmark@library@#1@barcode\endcsname
      \fi%
    \fi
  }%
}

%% 
%% Copyright (C) 2011-2016 by Andrew Stacey <loopspace@mathforge.org>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
%% version 1.3c of this license or (at your option) any later
%% version.  The latest version of this license is in the file:
%% 
%% http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%% Andrew Stacey.
%% 
%% This work consists of the file  tikzmark.dtx
%% and the derived files           tikzmark.ins,
%%                                 tikzmark.pdf,
%%                                 tikzlibrarytikzmark.code.tex, and
%%                                 tikzmarklibrarylistings.code.tex
%% 
%%
%% End of file `tikzlibrarytikzmark.code.tex'.
