texlive[51050] Master: tikzmark (8may19)

commits+karl at tug.org commits+karl at tug.org
Wed May 8 23:16:33 CEST 2019


Revision: 51050
          http://tug.org/svn/texlive?view=revision&revision=51050
Author:   karl
Date:     2019-05-08 23:16:33 +0200 (Wed, 08 May 2019)
Log Message:
-----------
tikzmark (8may19)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/tikzmark/tikzmark.pdf
    trunk/Master/texmf-dist/source/latex/tikzmark/tikzmark.dtx
    trunk/Master/texmf-dist/tex/latex/tikzmark/tikzlibrarytikzmark.code.tex
    trunk/Master/tlpkg/libexec/ctan2tds

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt

Added: trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt	2019-05-08 21:16:33 UTC (rev 51050)
@@ -0,0 +1,10 @@
+----------------------------------------------------------------
+tikzmark --- remembering absolute positioning with TikZ
+E-mail: loopspace at mathforge.org
+Released under the LaTeX Project Public License v1.3c or later
+See http://www.latex-project.org/lppl.txt
+----------------------------------------------------------------
+
+The tikzmark package defines a command to "remember" a position
+on a page for later (or earlier) use, primarily (but not
+exclusively) with TikZ.


Property changes on: trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/doc/latex/tikzmark/tikzmark.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/tikzmark/tikzmark.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/tikzmark/tikzmark.dtx	2019-05-08 21:15:22 UTC (rev 51049)
+++ trunk/Master/texmf-dist/source/latex/tikzmark/tikzmark.dtx	2019-05-08 21:16:33 UTC (rev 51050)
@@ -201,7 +201,7 @@
 %</driver>
 % \fi
 %
-% \CheckSum{919}
+% \CheckSum{1119}
 %
 % \CharacterTable
 %  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -226,7 +226,8 @@
 % \changes{1.3}{2017/06/01}{Tikzmark no longer uses semi-colon (too many issues with catcodes) and fix for beamer-awareness}
 % \changes{1.4}{2017/10/29}{Bug fixes: spurious characters in aux file, tikzmark prefix/suffix ignored in iftikzmark test}
 % \changes{1.5}{2018/09/09}{Reintroduced the original command (now as tikzmarknode) with a mathchoice hack for different math modes}
-% \changes{1.6}{2019/10/18}{Added the ability to save node information between runs and between TeX documents}
+% \changes{1.6}{2018/10/18}{Added the ability to save node information between runs and between TeX documents}
+% \changes{1.7}{2019/05/07}{Added conditions to test if a tikzmark is on a particular page}
 %
 % \DoNotIndex{\newcommand,\newenvironment}
 %
@@ -233,7 +234,7 @@
 % \providecommand*{\url}{\texttt}
 % \title{The \textsf{tikzmark} package}
 % \author{Andrew Stacey \\ \url{loopspace at mathforge.org}}
-% \date{v1.6~from 2018/10/18}
+% \date{v1.7~from 2019/05/07}
 %
 %
 % \maketitle
@@ -406,9 +407,21 @@
 %
 % \item \Verb+\iftikzmark+\marg{name}\marg{true code}\marg{false code}
 %
-% This is a simple conditional to test if a particular mark is available.
+% This is a conditional to test if a particular mark is available.
 % It executes \Verb+true code+ if it is and \Verb+false code+ if not.
 %
+% \item \Verb+\iftikzmarkexists+\marg{name}
+%
+% This is a conditional to test if a particular mark is available which works with the lower level \TeX\ \Verb+\else+ and \Verb+\fi+.
+%
+% \item \Verb+\iftikzmarkoncurrentpage+\marg{name}
+%
+% This is a conditional to test if a particular mark is on the current page; it works with the lower level \TeX\ \Verb+\else+ and \Verb+\fi+.
+%
+% \item \Verb+\iftikzmarkonpage+\marg{name}\marg{page}
+%
+% This is a conditional to test if a particular mark is on a given page; it works with the lower level \TeX\ \Verb+\else+ and \Verb+\fi+.
+%
 % \item \Verb+\tikzmarknode+\oarg{options}\marg{name}\marg{contents}
 %
 % This is a reincarnation of the original \Verb+\tikzmark+ command which places its contents inside a \Verb+\tikz+ node.  It also defines a \Verb+tikzmark+ with the same name.  Using a sneaky trick with \Verb+\mathchoice+, it works inside a math environment.  The spacing either side might not be quite right as although it detects the math style it doesn't got beyond that. The \Verb+options+ are passed to the node.
@@ -437,6 +450,15 @@
 %
 % This is a key equivalent of the \Verb+\iftikzmark+ command.
 %
+% \item \Verb+/tikz/if tikzmark on current page=#1#2#3+
+%
+% This is a key equivalent of the \Verb+\iftikzmarkoncurrentpage+ command.
+% If true, the keys in \Verb+#2+ are executed, otherwise the keys in \Verb+#3+.
+%
+% \item \Verb+/tikz/if tikzmark on page=#1#2#3#4+
+%
+% This is a key equivalent of the \Verb+\iftikzmarkonpage+ command.
+%
 % \item \Verb+/tikz/next page+, \Verb+/tikz/next page vector+
 %
 % It is possible to refer to a mark on a different page to the current page.
@@ -477,6 +499,8 @@
 % The simplest way to turn a pseudo-node into a more normal node is to use the \Verb+fit+ library.
 % Using the above example, \Verb+\node[fit=(a),draw,inner sep=0pt] {};+ would draw a rectangle around the word \Verb+sub+ of exactly the same size as would appear had a normal node been created.
 %
+% Using a sneaky trick with \Verb+\mathchoice+, \Verb+subnode+ works inside a math environment.  The spacing either side might not be quite right as although it detects the math style it doesn't got beyond that.
+%
 % \item \emph{Node saving}
 %
 % The node saving system takes the information stored about a node and saves it for later use.
@@ -824,6 +848,36 @@
   next page/ignore/.style={%
     next page vector={\pgfqpoint{0pt}{0pt}}%
   },
+  if tikzmark on current page/.code n args={3}{%
+    \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+      \pgfkeysalso{#3}%
+    }{%
+      \@ifundefined{save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname}{%
+        \pgfkeysalso{#3}%
+      }{%
+        \ifnum\csname save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname\endcsname=\the\value{page}\relax%
+        \pgfkeysalso{#2}%
+        \else
+        \pgfkeysalso{#3}%
+        \fi
+      }%
+    }%
+  },
+  if tikzmark on page/.code n args={4}{%
+    \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+      \pgfkeysalso{#4}%
+    }{%
+      \@ifundefined{save at pg@\csname save at pt@\tikzmark at pp@name{#1}@label\endcsname}{%
+        \pgfkeysalso{#4}%
+      }{%
+        \ifnum\csname save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname\endcsname=#2\relax%
+        \pgfkeysalso{#3}%
+        \else
+        \pgfkeysalso{#4}%
+        \fi
+      }%
+    }%
+  },
 %    \end{macrocode}
 % Prefix and suffix for tikzmark names, shamelessly borrowed from the main tikz code  
 %    \begin{macrocode}
@@ -856,6 +910,16 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\tikzmarkalias}
+% Alias a tikzmark to another name (used in tikzmarknode)
+%    \begin{macrocode}
+\def\tikzmarkalias#1#2{%
+  \pgf at node@gnamelet{save at pt@#1}{save at pt@#2}%
+  \pgf at node@gnamelet{save at pt@#1 at offset}{save at pt@#2 at offset}%
+}
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\tmk at labeldef}
 % Auxiliary command for the coordinate system.
 %    \begin{macrocode}
@@ -897,14 +961,11 @@
       \@ifundefined{save at pg@\csname save at pt@\tmk at label\endcsname}{}{%
         \@ifundefined{save at pg@\pgfpictureid}{}{%
           \pgfkeysvalueof{/tikz/next page vector}%
+        \edef\tmk at pg{\the\numexpr \csname save at pg@\csname save at pt@\tmk at label\endcsname\endcsname - \csname save at pg@\pgfpictureid\endcsname\relax}%
         \advance \pgf at xa by %
-        \csname save at pg@\csname save at pt@\tmk at label\endcsname\endcsname\pgf at x\relax
+        \tmk at pg\pgf at x\relax
         \advance \pgf at ya by %
-        \csname save at pg@\csname save at pt@\tmk at label\endcsname\endcsname\pgf at y\relax
-        \advance \pgf at xa by %
-        -\csname save at pg@\pgfpictureid\endcsname\pgf at x\relax
-        \advance \pgf at ya by %
-        -\csname save at pg@\pgfpictureid\endcsname\pgf at y\relax
+        \tmk at pg\pgf at y\relax
         }%
       }%
       \pgf at x=\pgf at xa
@@ -911,8 +972,8 @@
       \pgf at y=\pgf at ya
     \pgftransforminvert
     \pgf at pos@transform{\pgf at x}{\pgf at y}%
-    }%
-  }
+  }%
+}
 %    \end{macrocode}
 % \end{macro}
 %
@@ -940,8 +1001,13 @@
   \ifx\pgfpictureid\@undefined
   \let\tikzmark at next=\tikzmark at outside
   \else
+  \relax
+  \ifx\scope\tikz at origscope\relax
+  \let\tikzmark at next=\tikzmark at outside
+  \else
   \let\tikzmark at next=\tikzmark at inside
   \fi
+  \fi
   \tikzmark at next%
 }
 %    \end{macrocode}
@@ -1000,6 +1066,7 @@
 %
 % \begin{macro}{\iftikzmark}
 %    \begin{macrocode}
+\newif\iftikzmark@
 \newcommand\iftikzmark[3]{%
     \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
       #3%
@@ -1006,19 +1073,72 @@
     }{%
       #2%
     }%
+}%
+%    \end{macrocode}
+%
+% A version suitable for \Verb+\if ... \else ... \fi+.
+%    \begin{macrocode}
+\newcommand\iftikzmarkexists[1]{%
+  \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+    \tikzmark at false%
+  }{%
+    \tikzmark at true%
   }%
+  \iftikzmark@
+}%
 %    \end{macrocode}
 % \end{macro}
 %
+%
+% \begin{macro}{\iftikzmarkonpage}
+%    \begin{macrocode}
+\newcommand\iftikzmarkonpage[2]{%
+  \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+    \tikzmark at false
+  }{%
+    \@ifundefined{save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname}{%
+      \tikzmark at false
+    }{%
+      \ifnum\csname save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname\endcsname=#2\relax%
+      \tikzmark at true
+      \else
+      \tikzmark at false
+      \fi
+    }%
+  }%
+  \iftikzmark@
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\iftikzmarkoncurrentpage}
+%    \begin{macrocode}
+\newcommand\iftikzmarkoncurrentpage[1]{%
+  \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+    \tikzmark at false
+  }{%
+    \@ifundefined{save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname}{%
+      \tikzmark at false
+    }{%
+      \ifnum\csname save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname\endcsname=\the\value{page}\relax%
+      \tikzmark at true
+      \else
+      \tikzmark at false
+      \fi
+    }%
+  }%
+  \iftikzmark@
+}
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\subnode}
 % Note: much of this code was inevitably adapted from the node defining code in the TikZ/PGF sources.
 %    \begin{macrocode}
-\newcommand\subnode[3][]{%
+\def\subnode@#1#2#3{%
   \begingroup
   \pgfmark{#2}%
   \setbox\pgfnodeparttextbox=\hbox\bgroup #3\egroup
-  \def\tikz at shape{rectangle}%
-  \def\tikz at anchor{center}%
   \def\tikz at fig@name{#2}%
   \tikzset{every subnode/.try,#1}%
   \pgfpointorigin
@@ -1028,46 +1148,86 @@
   \advance\pgf at y by -.5\dp\pgfnodeparttextbox
   \pgftransformshift{}%
   \setbox\@tempboxa=\hbox\bgroup
-  \pgfutil at ifundefined{pgf at sh@s@\tikz at shape}%
-  {\PackageError{pgf}{Unknown shape ``\tikz at shape''}{}}%
   {%
-    {%
-      \let\pgf at sh@savedmacros=\pgfutil at empty% MW
-      \let\pgf at sh@savedpoints=\pgfutil at empty%
-      \def\pgf at sm@shape at name{\tikz at shape}% CJ % TT added prefix!
-      \csname pgf at sh@s@\tikz at shape\endcsname%
-      \pgf at sh@savedpoints%
-      \pgf at sh@savedmacros% MW
-      \pgftransformshift{%
-        \pgf at sh@reanchor{\tikz at shape}{\tikz at anchor}%
-        \pgf at x=-\pgf at x%
-        \pgf at y=-\pgf at y%
-      }%
-      \expandafter\pgfsavepgf at process\csname pgf at sh@sa@\tikz at fig@name\endcsname{%
-      	\pgf at sh@reanchor{\tikz at shape}{\tikz at anchor}% FIXME : this is double work!
-      }%
-      % Save the saved points and the transformation matrix
-      \edef\pgf at node@name{\tikz at fig@name}%
-      \ifx\pgf at node@name\pgfutil at empty%
-      \else%
-        \expandafter\xdef\csname pgf at sh@ns@\pgf at node@name\endcsname{\tikz at shape}%
-      \edef\pgf at sh@@temp{%
-        \noexpand\gdef\expandafter\noexpand\csname pgf at sh@np@\pgf at node@name\endcsname}%
-      \expandafter\pgf at sh@@temp\expandafter{%
-        \pgf at sh@savedpoints}%
-      \edef\pgf at sh@@temp{%
-        \noexpand\gdef\expandafter\noexpand\csname pgf at sh@ma@\pgf at node@name\endcsname}% MW
-        \expandafter\pgf at sh@@temp\expandafter{\pgf at sh@savedmacros}% MW
-        \pgfgettransform\pgf at temp
-        \expandafter\xdef\csname pgf at sh@nt@\pgf at node@name\endcsname{\pgf at temp}%
-        \expandafter\xdef\csname pgf at sh@pi@\pgf at node@name\endcsname{\pgfpictureid}%
-      \fi%
+    \let\pgf at sh@savedmacros=\pgfutil at empty% MW
+    \let\pgf at sh@savedpoints=\pgfutil at empty%
+    \def\pgf at sm@shape at name{rectangle}% CJ % TT added prefix!
+    \pgf at sh@s at rectangle%
+    \pgf at sh@savedpoints%
+    \pgf at sh@savedmacros% MW
+    \pgftransformshift{%
+      \pgf at sh@reanchor{rectangle}{center}%
+      \pgf at x=-\pgf at x%
+      \pgf at y=-\pgf at y%
     }%
+    \expandafter\pgfsavepgf at process\csname pgf at sh@sa@\tikz at fig@name\endcsname{%
+      \pgf at sh@reanchor{rectangle}{center}% FIXME : this is double work!
+    }%
+    % Save the saved points and the transformation matrix
+    \edef\pgf at node@name{\tikz at fig@name}%
+    \ifx\pgf at node@name\pgfutil at empty%
+    \else%
+    \expandafter\xdef\csname pgf at sh@ns@\pgf at node@name\endcsname{rectangle}%
+    \edef\pgf at sh@@temp{%
+      \noexpand\gdef\expandafter\noexpand\csname pgf at sh@np@\pgf at node@name\endcsname}%
+    \expandafter\pgf at sh@@temp\expandafter{%
+      \pgf at sh@savedpoints}%
+    \edef\pgf at sh@@temp{%
+      \noexpand\gdef\expandafter\noexpand\csname pgf at sh@ma@\pgf at node@name\endcsname}% MW
+    \expandafter\pgf at sh@@temp\expandafter{\pgf at sh@savedmacros}% MW
+    \pgfgettransform\pgf at temp
+    \expandafter\xdef\csname pgf at sh@nt@\pgf at node@name\endcsname{\pgf at temp}%
+    \expandafter\xdef\csname pgf at sh@pi@\pgf at node@name\endcsname{\pgfpictureid}%
+    \fi%
   }%
   \egroup
   \box\pgfnodeparttextbox
   \endgroup
 }
+
+\newcommand\subnode[3][]{%
+  \ifmmode
+  \mathchoice{%
+    \subnode@{#1}{#2-d}{\(\displaystyle #3\)}%
+  }{%
+    \subnode@{#1}{#2-t}{\(\textstyle #3\)}%
+  }{%
+    \subnode@{#1}{#2-s}{\(\scriptstyle #3\)}%
+  }{%
+    \subnode@{#1}{#2-ss}{\(\scriptscriptstyle #3\)}%
+  }%
+  \let\pgf at nodecallback\pgfutil at gobble
+  \def\tzmk at prfx{pgf at sys@pdf at mark@pos at pgfid}%
+  \edef\tzmk at pic{\tzmk at prfx\the\pgf at picture@serial at count}
+  \expandafter\ifx\csname\tzmk at pic\endcsname\relax
+  \edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-1\relax}%
+  \expandafter\ifx\csname\tzmk at pic\endcsname\relax
+\edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-2\relax}%
+  \expandafter\ifx\csname\tzmk at pic\endcsname\relax
+\edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-3\relax}%
+  \expandafter\ifx\csname\tzmk at pic\endcsname\relax
+%    \pgfnodealias{#2}{#2-t}%  %% Fallback
+  \else
+    \pgfnodealias{#2}{#2-d}%
+    \tikzmarkalias{#2}{#2-d}%
+  \fi
+  \else
+    \pgfnodealias{#2}{#2-t}%
+    \tikzmarkalias{#2}{#2-t}%
+  \fi
+  \else
+    \pgfnodealias{#2}{#2-s}%
+    \tikzmarkalias{#2}{#2-s}%
+  \fi
+  \else
+    \pgfnodealias{#2}{#2-ss}%
+    \tikzmarkalias{#2}{#2-ss}%
+  \fi
+  \else
+    \subnode@{#1}{#2}{#3}%
+  \fi
+}
+
 %    \end{macrocode}
 % \end{macro}
 %
@@ -1086,6 +1246,7 @@
     \node[
       anchor=base,
       inner sep=0pt,
+      minimum width=0pt,
       name={#2},
       node contents={#3},
       every tikzmarknode/.try,
@@ -1106,7 +1267,7 @@
   }%
   \let\pgf at nodecallback\pgfutil at gobble
   \def\tzmk at prfx{pgf at sys@pdf at mark@pos at pgfid}%
-  \edef\tzmk at pic{\tzmk at prfx\the\pgf at picture@serial at count}
+  \edef\tzmk at pic{\tzmk at prfx\the\pgf at picture@serial at count}%
   \expandafter\ifx\csname\tzmk at pic\endcsname\relax
   \edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-1\relax}%
   \expandafter\ifx\csname\tzmk at pic\endcsname\relax
@@ -1114,18 +1275,22 @@
   \expandafter\ifx\csname\tzmk at pic\endcsname\relax
 \edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-3\relax}%
   \expandafter\ifx\csname\tzmk at pic\endcsname\relax
-    \pgfnodealias{#2}{#2-t}%  %% Fallback
+  % No fallback due to potential nested mathchoices
   \else
     \pgfnodealias{#2}{#2-d}%
+    \tikzmarkalias{#2}{#2-d}%
   \fi
   \else
     \pgfnodealias{#2}{#2-t}%
+    \tikzmarkalias{#2}{#2-t}%
   \fi
   \else
     \pgfnodealias{#2}{#2-s}%
+    \tikzmarkalias{#2}{#2-s}%
   \fi
   \else
     \pgfnodealias{#2}{#2-ss}%
+    \tikzmarkalias{#2}{#2-ss}%
   \fi
   \else
     \tikzmarknode@{#1}{#2}{#3}%
@@ -1207,6 +1372,17 @@
 \bool_new:N \l__sn_file_bool
 %    \end{macrocode}
 %
+% This boolean is for whether we are in the preamble or not.
+%    \begin{macrocode}
+\bool_new:N \g__sn_preamble_bool
+\bool_set_true:N \g__sn_preamble_bool
+%    \end{macrocode}
+%
+%    \begin{macrocode}    
+\msg_new:nnn {tikzmark} {no file} {File~ "#1"~ doesn't~ exist.}
+\msg_new:nnn {tikzmark} {loading nodes} {Loading~ nodes~ from~ "#1".}
+%    \end{macrocode}
+%
 % Dimensions and token lists for shifting
 %    \begin{macrocode}    
 \dim_new:N \l__sn_x_dim
@@ -1224,7 +1400,7 @@
 \iow_new:N \g__sn_stream
 \bool_new:N \g__sn_stream_bool
 \tl_new:N \g__sn_filename_tl
-\tl_set:Nx \g__sn_filename_tl {\c_sys_jobname_str}    
+\tl_gset:Nx \g__sn_filename_tl {\c_sys_jobname_str}    
 
 \cs_new_nopar:Npn \sn_open_stream:
 {
@@ -1378,8 +1554,7 @@
 {
   \save_nodes:Nn \l__sn_tmpa_tl {#1}
 %    \end{macrocode}  
-% Save the token list to the aux file so that on reading the aux
-% file, we restore the node definitions
+% Save the token list to the nodes file so that on reading it back in, we restore the node definitions
 %    \begin{macrocode}
   \sn_open_stream:
   \iow_now:Nx \g__sn_stream
@@ -1416,13 +1591,18 @@
 %    \begin{macrocode}
 \cs_new_nopar:Npn \restore_nodes_from_file:n #1
 {
-  \file_if_exist:nT {#1.nodes}
+  \file_if_exist:nTF {#1.nodes}
   {
+    \msg_log:nnn {tikzmark} {loading nodes} {#1}
     \ExplSyntaxOn
     \file_input:n {#1.nodes}
     \ExplSyntaxOff
   }
+  {
+    \msg_warning:nnn {tikzmark} {no file} {#1}
+  }
 }
+\AtBeginDocument{\bool_gset_false:N \g__sn_preamble_bool}
 %    \end{macrocode}
 % \end{macro}
 %
@@ -1584,16 +1764,23 @@
 % Restore nodes from file
 %    \begin{macrocode}
   restore~ nodes~ from~ file/.code={
-    \tikz_fig_must_be_named:
-    \pgfkeysalso{append~ after~ command={
-        \pgfextra{
-          \scope
-          \split_argument:NNn \tikzset \restore_nodes_from_file:n {#1}
-          \endscope
+    \bool_if:NTF \g__sn_preamble_bool
+    {
+      \restore_nodes_from_file:n {#1}
+    }
+    {
+      \tikz_fig_must_be_named:
+      \pgfkeysalso{append~ after~ command={
+          \pgfextra{
+            \scope
+            \split_argument:NNn \tikzset \restore_nodes_from_file:n {#1}
+            \endscope
+          }
         }
       }
     }
   },
+  restore~ nodes~ from~ file/.default = \g__sn_filename_tl,
 %    \end{macrocode}  
 % Restore nodes from list
 %    \begin{macrocode}

Modified: trunk/Master/texmf-dist/tex/latex/tikzmark/tikzlibrarytikzmark.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/tikzmark/tikzlibrarytikzmark.code.tex	2019-05-08 21:15:22 UTC (rev 51049)
+++ trunk/Master/texmf-dist/tex/latex/tikzmark/tikzlibrarytikzmark.code.tex	2019-05-08 21:16:33 UTC (rev 51050)
@@ -61,6 +61,36 @@
   next page/ignore/.style={%
     next page vector={\pgfqpoint{0pt}{0pt}}%
   },
+  if tikzmark on current page/.code n args={3}{%
+    \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+      \pgfkeysalso{#3}%
+    }{%
+      \@ifundefined{save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname}{%
+        \pgfkeysalso{#3}%
+      }{%
+        \ifnum\csname save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname\endcsname=\the\value{page}\relax%
+        \pgfkeysalso{#2}%
+        \else
+        \pgfkeysalso{#3}%
+        \fi
+      }%
+    }%
+  },
+  if tikzmark on page/.code n args={4}{%
+    \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+      \pgfkeysalso{#4}%
+    }{%
+      \@ifundefined{save at pg@\csname save at pt@\tikzmark at pp@name{#1}@label\endcsname}{%
+        \pgfkeysalso{#4}%
+      }{%
+        \ifnum\csname save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname\endcsname=#2\relax%
+        \pgfkeysalso{#3}%
+        \else
+        \pgfkeysalso{#4}%
+        \fi
+      }%
+    }%
+  },
   tikzmark prefix/.initial=,%
   tikzmark suffix/.initial=,%
 }
@@ -77,6 +107,10 @@
 \def\savepicturepage#1#2{%
   \expandafter\gdef\csname save at pg@#1\endcsname{#2}%
 }
+\def\tikzmarkalias#1#2{%
+  \pgf at node@gnamelet{save at pt@#1}{save at pt@#2}%
+  \pgf at node@gnamelet{save at pt@#1 at offset}{save at pt@#2 at offset}%
+}
 \def\tmk at labeldef#1,#2\@nil{%
   \edef\tmk at label{\tikzmark at pp@name{#1}}%
   \def\tmk at def{#2}%
@@ -109,14 +143,11 @@
       \@ifundefined{save at pg@\csname save at pt@\tmk at label\endcsname}{}{%
         \@ifundefined{save at pg@\pgfpictureid}{}{%
           \pgfkeysvalueof{/tikz/next page vector}%
+        \edef\tmk at pg{\the\numexpr \csname save at pg@\csname save at pt@\tmk at label\endcsname\endcsname - \csname save at pg@\pgfpictureid\endcsname\relax}%
         \advance \pgf at xa by %
-        \csname save at pg@\csname save at pt@\tmk at label\endcsname\endcsname\pgf at x\relax
+        \tmk at pg\pgf at x\relax
         \advance \pgf at ya by %
-        \csname save at pg@\csname save at pt@\tmk at label\endcsname\endcsname\pgf at y\relax
-        \advance \pgf at xa by %
-        -\csname save at pg@\pgfpictureid\endcsname\pgf at x\relax
-        \advance \pgf at ya by %
-        -\csname save at pg@\pgfpictureid\endcsname\pgf at y\relax
+        \tmk at pg\pgf at y\relax
         }%
       }%
       \pgf at x=\pgf at xa
@@ -123,8 +154,8 @@
       \pgf at y=\pgf at ya
     \pgftransforminvert
     \pgf at pos@transform{\pgf at x}{\pgf at y}%
-    }%
-  }
+  }%
+}
 \newcommand\tikzmark at outside[2][]{%
 \tikz[remember picture with id=#2]{#1}%
 }
@@ -138,8 +169,13 @@
   \ifx\pgfpictureid\@undefined
   \let\tikzmark at next=\tikzmark at outside
   \else
+  \relax
+  \ifx\scope\tikz at origscope\relax
+  \let\tikzmark at next=\tikzmark at outside
+  \else
   \let\tikzmark at next=\tikzmark at inside
   \fi
+  \fi
   \tikzmark at next%
 }
 \newcommand\pgfmark[1]{%
@@ -171,6 +207,7 @@
     tikzmark suffix=-\the\beamer at slideinframe
   }
 }{}
+\newif\iftikzmark@
 \newcommand\iftikzmark[3]{%
     \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
       #3%
@@ -177,13 +214,51 @@
     }{%
       #2%
     }%
+}%
+\newcommand\iftikzmarkexists[1]{%
+  \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+    \tikzmark at false%
+  }{%
+    \tikzmark at true%
   }%
-\newcommand\subnode[3][]{%
+  \iftikzmark@
+}%
+\newcommand\iftikzmarkonpage[2]{%
+  \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+    \tikzmark at false
+  }{%
+    \@ifundefined{save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname}{%
+      \tikzmark at false
+    }{%
+      \ifnum\csname save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname\endcsname=#2\relax%
+      \tikzmark at true
+      \else
+      \tikzmark at false
+      \fi
+    }%
+  }%
+  \iftikzmark@
+}
+\newcommand\iftikzmarkoncurrentpage[1]{%
+  \@ifundefined{save at pt@\tikzmark at pp@name{#1}}{%
+    \tikzmark at false
+  }{%
+    \@ifundefined{save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname}{%
+      \tikzmark at false
+    }{%
+      \ifnum\csname save at pg@\csname save at pt@\tikzmark at pp@name{#1}\endcsname\endcsname=\the\value{page}\relax%
+      \tikzmark at true
+      \else
+      \tikzmark at false
+      \fi
+    }%
+  }%
+  \iftikzmark@
+}
+\def\subnode@#1#2#3{%
   \begingroup
   \pgfmark{#2}%
   \setbox\pgfnodeparttextbox=\hbox\bgroup #3\egroup
-  \def\tikz at shape{rectangle}%
-  \def\tikz at anchor{center}%
   \def\tikz at fig@name{#2}%
   \tikzset{every subnode/.try,#1}%
   \pgfpointorigin
@@ -193,46 +268,85 @@
   \advance\pgf at y by -.5\dp\pgfnodeparttextbox
   \pgftransformshift{}%
   \setbox\@tempboxa=\hbox\bgroup
-  \pgfutil at ifundefined{pgf at sh@s@\tikz at shape}%
-  {\PackageError{pgf}{Unknown shape ``\tikz at shape''}{}}%
   {%
-    {%
-      \let\pgf at sh@savedmacros=\pgfutil at empty% MW
-      \let\pgf at sh@savedpoints=\pgfutil at empty%
-      \def\pgf at sm@shape at name{\tikz at shape}% CJ % TT added prefix!
-      \csname pgf at sh@s@\tikz at shape\endcsname%
-      \pgf at sh@savedpoints%
-      \pgf at sh@savedmacros% MW
-      \pgftransformshift{%
-        \pgf at sh@reanchor{\tikz at shape}{\tikz at anchor}%
-        \pgf at x=-\pgf at x%
-        \pgf at y=-\pgf at y%
-      }%
-      \expandafter\pgfsavepgf at process\csname pgf at sh@sa@\tikz at fig@name\endcsname{%
-       \pgf at sh@reanchor{\tikz at shape}{\tikz at anchor}% FIXME : this is double work!
-      }%
-      % Save the saved points and the transformation matrix
-      \edef\pgf at node@name{\tikz at fig@name}%
-      \ifx\pgf at node@name\pgfutil at empty%
-      \else%
-        \expandafter\xdef\csname pgf at sh@ns@\pgf at node@name\endcsname{\tikz at shape}%
-      \edef\pgf at sh@@temp{%
-        \noexpand\gdef\expandafter\noexpand\csname pgf at sh@np@\pgf at node@name\endcsname}%
-      \expandafter\pgf at sh@@temp\expandafter{%
-        \pgf at sh@savedpoints}%
-      \edef\pgf at sh@@temp{%
-        \noexpand\gdef\expandafter\noexpand\csname pgf at sh@ma@\pgf at node@name\endcsname}% MW
-        \expandafter\pgf at sh@@temp\expandafter{\pgf at sh@savedmacros}% MW
-        \pgfgettransform\pgf at temp
-        \expandafter\xdef\csname pgf at sh@nt@\pgf at node@name\endcsname{\pgf at temp}%
-        \expandafter\xdef\csname pgf at sh@pi@\pgf at node@name\endcsname{\pgfpictureid}%
-      \fi%
+    \let\pgf at sh@savedmacros=\pgfutil at empty% MW
+    \let\pgf at sh@savedpoints=\pgfutil at empty%
+    \def\pgf at sm@shape at name{rectangle}% CJ % TT added prefix!
+    \pgf at sh@s at rectangle%
+    \pgf at sh@savedpoints%
+    \pgf at sh@savedmacros% MW
+    \pgftransformshift{%
+      \pgf at sh@reanchor{rectangle}{center}%
+      \pgf at x=-\pgf at x%
+      \pgf at y=-\pgf at y%
     }%
+    \expandafter\pgfsavepgf at process\csname pgf at sh@sa@\tikz at fig@name\endcsname{%
+      \pgf at sh@reanchor{rectangle}{center}% FIXME : this is double work!
+    }%
+    % Save the saved points and the transformation matrix
+    \edef\pgf at node@name{\tikz at fig@name}%
+    \ifx\pgf at node@name\pgfutil at empty%
+    \else%
+    \expandafter\xdef\csname pgf at sh@ns@\pgf at node@name\endcsname{rectangle}%
+    \edef\pgf at sh@@temp{%
+      \noexpand\gdef\expandafter\noexpand\csname pgf at sh@np@\pgf at node@name\endcsname}%
+    \expandafter\pgf at sh@@temp\expandafter{%
+      \pgf at sh@savedpoints}%
+    \edef\pgf at sh@@temp{%
+      \noexpand\gdef\expandafter\noexpand\csname pgf at sh@ma@\pgf at node@name\endcsname}% MW
+    \expandafter\pgf at sh@@temp\expandafter{\pgf at sh@savedmacros}% MW
+    \pgfgettransform\pgf at temp
+    \expandafter\xdef\csname pgf at sh@nt@\pgf at node@name\endcsname{\pgf at temp}%
+    \expandafter\xdef\csname pgf at sh@pi@\pgf at node@name\endcsname{\pgfpictureid}%
+    \fi%
   }%
   \egroup
   \box\pgfnodeparttextbox
   \endgroup
 }
+
+\newcommand\subnode[3][]{%
+  \ifmmode
+  \mathchoice{%
+    \subnode@{#1}{#2-d}{\(\displaystyle #3\)}%
+  }{%
+    \subnode@{#1}{#2-t}{\(\textstyle #3\)}%
+  }{%
+    \subnode@{#1}{#2-s}{\(\scriptstyle #3\)}%
+  }{%
+    \subnode@{#1}{#2-ss}{\(\scriptscriptstyle #3\)}%
+  }%
+  \let\pgf at nodecallback\pgfutil at gobble
+  \def\tzmk at prfx{pgf at sys@pdf at mark@pos at pgfid}%
+  \edef\tzmk at pic{\tzmk at prfx\the\pgf at picture@serial at count}
+  \expandafter\ifx\csname\tzmk at pic\endcsname\relax
+  \edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-1\relax}%
+  \expandafter\ifx\csname\tzmk at pic\endcsname\relax
+\edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-2\relax}%
+  \expandafter\ifx\csname\tzmk at pic\endcsname\relax
+\edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-3\relax}%
+  \expandafter\ifx\csname\tzmk at pic\endcsname\relax
+  \else
+    \pgfnodealias{#2}{#2-d}%
+    \tikzmarkalias{#2}{#2-d}%
+  \fi
+  \else
+    \pgfnodealias{#2}{#2-t}%
+    \tikzmarkalias{#2}{#2-t}%
+  \fi
+  \else
+    \pgfnodealias{#2}{#2-s}%
+    \tikzmarkalias{#2}{#2-s}%
+  \fi
+  \else
+    \pgfnodealias{#2}{#2-ss}%
+    \tikzmarkalias{#2}{#2-ss}%
+  \fi
+  \else
+    \subnode@{#1}{#2}{#3}%
+  \fi
+}
+
 \def\tikzmarknode@#1#2#3{%
   \tikz[%
     remember picture,
@@ -243,6 +357,7 @@
     \node[
       anchor=base,
       inner sep=0pt,
+      minimum width=0pt,
       name={#2},
       node contents={#3},
       every tikzmarknode/.try,
@@ -263,7 +378,7 @@
   }%
   \let\pgf at nodecallback\pgfutil at gobble
   \def\tzmk at prfx{pgf at sys@pdf at mark@pos at pgfid}%
-  \edef\tzmk at pic{\tzmk at prfx\the\pgf at picture@serial at count}
+  \edef\tzmk at pic{\tzmk at prfx\the\pgf at picture@serial at count}%
   \expandafter\ifx\csname\tzmk at pic\endcsname\relax
   \edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-1\relax}%
   \expandafter\ifx\csname\tzmk at pic\endcsname\relax
@@ -271,18 +386,22 @@
   \expandafter\ifx\csname\tzmk at pic\endcsname\relax
 \edef\tzmk at pic{\tzmk at prfx\the\numexpr\the\pgf at picture@serial at count-3\relax}%
   \expandafter\ifx\csname\tzmk at pic\endcsname\relax
-    \pgfnodealias{#2}{#2-t}%  %% Fallback
+  % No fallback due to potential nested mathchoices
   \else
     \pgfnodealias{#2}{#2-d}%
+    \tikzmarkalias{#2}{#2-d}%
   \fi
   \else
     \pgfnodealias{#2}{#2-t}%
+    \tikzmarkalias{#2}{#2-t}%
   \fi
   \else
     \pgfnodealias{#2}{#2-s}%
+    \tikzmarkalias{#2}{#2-s}%
   \fi
   \else
     \pgfnodealias{#2}{#2-ss}%
+    \tikzmarkalias{#2}{#2-ss}%
   \fi
   \else
     \tikzmarknode@{#1}{#2}{#3}%
@@ -324,6 +443,10 @@
 \tl_new:N \l__sn_group_tl
 \clist_new:N \l__sn_nodes_clist
 \bool_new:N \l__sn_file_bool
+\bool_new:N \g__sn_preamble_bool
+\bool_set_true:N \g__sn_preamble_bool
+\msg_new:nnn {tikzmark} {no file} {File~ "#1"~ doesn't~ exist.}
+\msg_new:nnn {tikzmark} {loading nodes} {Loading~ nodes~ from~ "#1".}
 \dim_new:N \l__sn_x_dim
 \dim_new:N \l__sn_y_dim
 \dim_new:N \l__sn_xa_dim
@@ -335,7 +458,7 @@
 \iow_new:N \g__sn_stream
 \bool_new:N \g__sn_stream_bool
 \tl_new:N \g__sn_filename_tl
-\tl_set:Nx \g__sn_filename_tl {\c_sys_jobname_str}
+\tl_gset:Nx \g__sn_filename_tl {\c_sys_jobname_str}
 
 \cs_new_nopar:Npn \sn_open_stream:
 {
@@ -445,13 +568,18 @@
 }
 \cs_new_nopar:Npn \restore_nodes_from_file:n #1
 {
-  \file_if_exist:nT {#1.nodes}
+  \file_if_exist:nTF {#1.nodes}
   {
+    \msg_log:nnn {tikzmark} {loading nodes} {#1}
     \ExplSyntaxOn
     \file_input:n {#1.nodes}
     \ExplSyntaxOff
   }
+  {
+    \msg_warning:nnn {tikzmark} {no file} {#1}
+  }
 }
+\AtBeginDocument{\bool_gset_false:N \g__sn_preamble_bool}
 
 \cs_new_nopar:Npn \compose_transformations:Nnn #1#2#3
 {
@@ -568,16 +696,23 @@
     }
   },
   restore~ nodes~ from~ file/.code={
-    \tikz_fig_must_be_named:
-    \pgfkeysalso{append~ after~ command={
-        \pgfextra{
-          \scope
-          \split_argument:NNn \tikzset \restore_nodes_from_file:n {#1}
-          \endscope
+    \bool_if:NTF \g__sn_preamble_bool
+    {
+      \restore_nodes_from_file:n {#1}
+    }
+    {
+      \tikz_fig_must_be_named:
+      \pgfkeysalso{append~ after~ command={
+          \pgfextra{
+            \scope
+            \split_argument:NNn \tikzset \restore_nodes_from_file:n {#1}
+            \endscope
+          }
         }
       }
     }
   },
+  restore~ nodes~ from~ file/.default = \g__sn_filename_tl,
   restore~ nodes~ from~ list/.code={
     \tikz_fig_must_be_named:
     \pgfkeysalso{append~ after~ command={

Modified: trunk/Master/tlpkg/libexec/ctan2tds
===================================================================
--- trunk/Master/tlpkg/libexec/ctan2tds	2019-05-08 21:15:22 UTC (rev 51049)
+++ trunk/Master/tlpkg/libexec/ctan2tds	2019-05-08 21:16:33 UTC (rev 51050)
@@ -2696,6 +2696,7 @@
  'thucoursework' => 'pdflatex-preserve-pdf --engine xelatex',
  'thumb'        => 'latex -translate-file=empty.tcx',   # no 8-bit
  'tikz-page'	=> 'tex -8bit',    # no doc remake, 8-bit name
+ 'tikzmark'	=> 'tex',
  'todonotes'    => 'latex',  # requires interaction
  'toptesi'      => 'latex',  # requires interaction
  'tudscr'       => 'tex',



More information about the tex-live-commits mailing list