texlive[64819] Master/texmf-dist: tikzmark (26oct22)

commits+karl at tug.org commits+karl at tug.org
Wed Oct 26 21:59:50 CEST 2022


Revision: 64819
          http://tug.org/svn/texlive?view=revision&revision=64819
Author:   karl
Date:     2022-10-26 21:59:50 +0200 (Wed, 26 Oct 2022)
Log Message:
-----------
tikzmark (26oct22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/tikzmark/README
    trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt
    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/texmf-dist/tex/latex/tikzmark/tikzmarklibrarylistings.code.tex

Added Paths:
-----------
    trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryams.code.tex
    trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryhighlighting.code.tex

Modified: trunk/Master/texmf-dist/doc/latex/tikzmark/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/tikzmark/README	2022-10-26 19:59:14 UTC (rev 64818)
+++ trunk/Master/texmf-dist/doc/latex/tikzmark/README	2022-10-26 19:59:50 UTC (rev 64819)
@@ -8,3 +8,4 @@
 The tikzmark package defines a command to "remember" a position
 on a page for later (or earlier) use, primarily (but not
 exclusively) with TikZ.
+

Modified: trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt	2022-10-26 19:59:14 UTC (rev 64818)
+++ trunk/Master/texmf-dist/doc/latex/tikzmark/README.txt	2022-10-26 19:59:50 UTC (rev 64819)
@@ -8,3 +8,4 @@
 The tikzmark package defines a command to "remember" a position
 on a page for later (or earlier) use, primarily (but not
 exclusively) with TikZ.
+

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	2022-10-26 19:59:14 UTC (rev 64818)
+++ trunk/Master/texmf-dist/source/latex/tikzmark/tikzmark.dtx	2022-10-26 19:59:50 UTC (rev 64819)
@@ -53,6 +53,8 @@
                                 tikzmark.pdf,
                                 tikzlibrarytikzmark.code.tex, and
                                 tikzmarklibrarylistings.code.tex
+                                tikzmarklibraryhighlighting.code.tex
+                                tikzmarklibraryams.code.tex
 
 \endpostamble
 \usedir{tex/latex/tikzmark}
@@ -62,9 +64,12 @@
 \generate{
   \file{tikzmarklibrarylistings.code.tex}{\from{\jobname.dtx}{listings}}
 }
-%\generate{
-% \file{tikzmarklibraryhighlight.code.tex}{\from{\jobname.dtx}{highlight}}
-%}
+\generate{
+  \file{tikzmarklibraryhighlighting.code.tex}{\from{\jobname.dtx}{highlighting}}
+}
+\generate{
+  \file{tikzmarklibraryams.code.tex}{\from{\jobname.dtx}{ams}}
+}
 %</install>
 %<install>\endbatchfile
 %<*internal>
@@ -91,8 +96,8 @@
 %\usepackage{morefloats}
 \usepackage{listings}
 \usepackage{tikz}
-\usetikzlibrary{fit,arrows,tikzmark,shadows,decorations.pathreplacing,calc}
-\usetikzmarklibrary{listings}
+\usetikzlibrary{fit,arrows.meta,tikzmark,shadows,decorations.pathreplacing,calc}
+\usetikzmarklibrary{ams,listings,highlighting}
 
 %\usepackage[numbered]{hypdoc}
 \definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9} 
@@ -206,7 +211,7 @@
 %</driver>
 % \fi
 %
-% \CheckSum{1178}
+% \CheckSum{1891}
 %
 % \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
@@ -235,8 +240,16 @@
 % \changes{1.7}{2019/05/07}{Added conditions to test if a tikzmark is on a particular page}
 % \changes{1.8}{2019/10/04}{Fixed some bugs with subnode and tikzmarknode inside maths}
 % \changes{1.10}{2021/02/16}{Tikzmarknode is now prefix and suffix aware, and added a test to see if a picture id has been saved to the aux file for times when pictures are thrown away, eg in AMS's text command}
+% \changes{1.11}{2021/08/16}{Tikzmark inside a tikzpicture was not applying any surrounding transformation before saving the coordinates.  Code for adjusting a pic's location based on an internal coordinate.}
+% \changes{1.12}{2021/08/24}{Experimental library for creating pseudo-nodes around AMSMath equation alignment boxes.}
+% \changes{1.14}{2022/01/28}{Reimplementing the highlighting code using LaTeX3 hooks.}
+% \changes{1.15}{2022/08/24}{Improvements to highlighting code}
 %
 % \DoNotIndex{\newcommand,\newenvironment}
+% \pdfstringdefDisableCommands{%
+%  \def\\{}%
+%  \def\url#1{<#1>}%
+% }
 %
 % \GetFileInfo{tikzlibrarytikzmark.code.tex}
 % \providecommand*{\url}{\texttt}
@@ -382,6 +395,8 @@
 %
 % This package defines the following commands and usable stuff.
 %
+% \subsection{Core Commands}
+%
 % \begin{enumerate}
 % \item \Verb+\tikzmark+\oarg{drawing command}\marg{name}
 %
@@ -459,7 +474,7 @@
 % In such a situation, when defining nodes then the last one ``wins'' in that each node remembers the id of the last processed picture.
 % However, only the one that is actually used has its location remembered on the page (since the others don't have a position).
 % This can lead to the situation whereby a node becomes disassociated from its picture and so using it for later reference fails.
-% This key tries to get around that situation by checking the \Verb+aux+ file to see if the current picture was actually typeset last time (by checking for the presence of the remembered location) and if it find that it wasn't, it quietly appends the string \Verb+discard-+ to each node name.
+% This key tries to get around that situation by checking the \Verb+aux+ file to see if the current picture was actually typeset last time (by checking for the presence of the remembered location) and if it finds that it wasn't, it quietly appends the string \Verb+discard-+ to each node name.
 % The idea being that the version of the picture that is actually typeset will not have this happen and so its nodes ``survive''.
 %
 % \item \Verb+/tikz/maybe define node=#1+
@@ -504,8 +519,36 @@
 %
 % This was inspired by the question \href{http://tex.stackexchange.com/q/302517/86}{using tikzmark subnode with overlays beamer} on TeX-SX.
 %
-% \item \Verb+\subnode[options]{name}{content}+
+% \end{enumerate}
 %
+% \subsection{Pic and Scope Positioning}
+%
+% \Verb+scope anchor+, \Verb+pic anchor+, and \Verb+surround pic+.
+%
+% These keys can be used to enable advanced positioning of \Verb+scope+s and \Verb+pic+s.
+% The standard positioning of a \Verb+pic+ places its internal origin at the location specified on the \Verb!\pic! command.
+% This is more limited than what is available to a \Verb+node+ whereby any of the defined anchors can be placed at the given position.
+% The key \Verb+pic anchor+ allows a little more flexibility to \Verb+pic+ positioning by allowing a \Verb+pic anchor+ to be defined and used as the point to place at the given position.
+%
+% When invoking the \Verb!pic! the key \Verb!pic anchor={coordinate}! can be used to specify a point inside the \Verb!pic! to use as the anchor.
+% This point is evaluated inside the \Verb!pic! so if using a node then the node name should be specified as if inside the \Verb!pic!.
+%
+% The node positioning syntax, things like \Verb!below! and \Verb!below=5pt of!, sets the anchor of the following node.
+% Using \Verb!pic anchor! without a coordinate uses this anchor on the bounding box of the pic when positioning the pic.
+%
+% Internally, this works by adjusting the location of the \Verb!pic!'s surrounding scope.
+% So the code can equally be used on \Verb!scope!s.
+% For a \Verb!scope!, use the \Verb!scope anchor! version on the scope directly.
+% The keys \Verb!name! and \Verb!anchor! can be used on the scope as if on a \Verb!node! with the same effect on the positioning.
+%
+% The key \Verb!surround pic! saves the bounding box of the pic as if it were the boundary of a rectangular node, using the name of the pic as the name of the node.
+%
+% This was inspired by the questions \href{https://tex.stackexchange.com/q/185279/86}{Anchoring TiKZ pics} and \href{https://tex.stackexchange.com/q/567245/86}{Reposition Tikz Scope After Size Known}.
+%
+% \subsection{Subnodes}
+%
+% \Verb+\subnode[options]{name}{content}+
+%
 % This produces a pseudo-node named \Verb+name+ around the \Verb+content+.
 % The design purpose of this is to create a ``subnode'' inside a TikZ node.
 % As far as TikZ is concerned, the contents of a node is just a box.
@@ -525,10 +568,13 @@
 % 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.
+% 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}
+% Note that because of the way that this works, the outer \Verb!tikzpicture! must have the \Verb!remember picture! option set.
 %
+% \subsection{Node saving}
+%
 % The node saving system takes the information stored about a node and saves it for later use.
 % That later use can be in the same document, in which case it should be saved just to the memory of the current TeX process, or it can be used earlier in the same document or another document altogether (in particular, if the nodes are defined in a \Verb+tikzpicture+ that has been externalised, this can be used to import the node information into the main file) in which cases the node data is saved to a file.
 %
@@ -539,10 +585,19 @@
 % The keys for working with saving and restoring nodes are as follows.
 %
 % \begin{itemize}
-% \item \Verb+save node+
+% \item \Verb+save node+,  \Verb+save node=<name>+
 %
-% This is the key to put on a node that is to be saved.
+% This is the key that indicates a node to be saved.
+% The version with no argument is to be used directly in the keys for a node and it saves that node.
+% With an argument then it saves a node that has been declared somewhere in the current tikz picture (it may not always be convenient to issue the \Verb+save node+ key directly on the node itself).
+% Since the list is saved up to the end of the picture, this can be invoked before the node is defined.
 %
+% \item \Verb+\SaveNode[group name]{name}+
+%
+% This command is for outside a tikzpicture and saves the named node directly.
+% The optional argument is a group name for saving to a group.
+% If this is not specified then the node is saved to a file.
+%
 % \item \Verb+set node group=<name>+
 %
 % Nodes are grouped together into a list that can be saved either to a file or for use later on in the document.
@@ -579,21 +634,17 @@
 % If there is a transformation in place on the containing node, this key applies that transformation to all the nodes in the inner picture.
 %
 % \end{itemize}
-% \end{enumerate}
 %
-% \section{Examples and Extras}
+% \section{Examples}
 %
 % The \Verb+\tikzmark+ command has been used in numerous answers on \href{http://tex.stackexchange.com}{TeX-SX}.
-% The plan is to gather some of these into extra libraries which can be loaded via \Verb+\usetikzmarklibrary+.
 %
-% At present, this is the code listings library (which works with the \Verb+listings+ package).
-% One that is in development (as it has featured much on the TeX-SX website) is highlighting, however this is not so straightforward to implement so is still under development.
-%
 % \subsection{Basic Examples}
 %
 % A simple example of the \Verb+\tikzmark+ macro is the following.
 %
 % \begin{example}
+% \tikzset{tikzmark prefix=ex1-}
 % \[
 %  \tikzmark{a} e^{i \pi/2} = i
 % \]
@@ -602,6 +653,7 @@
 % \end{example}
 %
 % \begin{example}
+% \tikzset{tikzmark prefix=ex2-}
 % \begin{itemize}
 % \item A first item,\tikzmark{b}
 % \item A second item,\tikzmark{c}
@@ -613,6 +665,7 @@
 % \end{example}
 %
 % \begin{example}
+% \tikzset{tikzmark prefix=ex3-}
 % \begin{tikzpicture}[remember picture]
 % \node (a) at (0,0) {This has a \subnode{sub}{subnode} in it};
 % \draw[->] (0,-1) to[bend right] (sub);
@@ -622,7 +675,7 @@
 % An example using \Verb+\tikzmark+ inside a \Verb+tikzpicture+
 %
 % \begin{example}
-% \tikzset{tikzmark prefix=ex3-}
+% \tikzset{tikzmark prefix=ex4-}
 % \begin{tikzpicture}[remember picture,overlay]
 % \draw[->,line width=1mm,cyan] (pic cs:a) to[bend left] (pic cs:b);
 % \end{tikzpicture}
@@ -638,6 +691,7 @@
 % The \Verb+\tikmarknode+ puts a node around some text, which can be referred to later, and adds a \Verb+\tikzmark+ at its origin.
 %
 % \begin{example}
+% \tikzset{tikzmark prefix=ex5-}
 % Putting a node around \tikzmarknode{txt}{some text} means we can connect text together, including in maths:
 % \[
 % \tikzmarknode{a}{\sum_{k=1}^n} k^{\tikzmarknode{b}{2}}
@@ -719,6 +773,13 @@
 % \fbox{\IfFileExists{tikzrefextnodes.pdf}{\includegraphics{tikzrefextnodes}}{}}
 % \end{center}
 %
+% \section{Additional Libraries}
+%
+% Some of the more ambitious uses of \Verb!\tikzmark! involve a fair bit of extra code and so are worth gathering in to extra libraries of their own.
+% These can be loaded via \Verb+\usetikzmarklibrary+.
+%
+% At present, there are three libraries: one for code listings which works with the \Verb+listings+ package, one for AMSMath equations, and one for highlighting.
+%
 % \subsection{Code Listings}
 %
 % If the \Verb+listings+ package has been loaded then issuing
@@ -749,6 +810,7 @@
 % The following example shows this, where the red dots are the \Verb+start+, the blue are \Verb+end+, and the green are \Verb+first+.
 %
 % \begin{example}
+% \tikzset{tikzmark prefix=ex6-}
 % \begin{tikzpicture}[remember picture]
 % \foreach \k in {0,...,7} {
 % \iftikzmark{line-code-\k-start}{\fill[red,overlay] (pic cs:line-code-\k-start) circle[radius=4pt];}{\message{No start for \k}}
@@ -788,8 +850,216 @@
 % \end{lstlisting}
 % \end{example}
 %
+% \subsection{AMS Equation Environments}
 %
+% \textbf{This is an experimental library.}
 %
+% If the \Verb+amsmath+ package has been loaded then issuing
+%
+% \Verb+\usetikzmarklibrary{ams}+
+%
+% \noindent loads some code that places pseudo-nodes around the boxes that are used in AMSMath's various equation alignment environments, such as \Verb!align! and \Verb!gather!.
+% These environments work by constructing boxes with each of the pieces of the equations that are then put together into the grid.
+% This library hooks in to the unboxing code, before the box is typeset then it measures it and stores that information in various macros as if it were a TikZ node.
+% The aim is that this doesn't disturb the placement, but as far as TikZ is concerned then there is a node there that can be referred to later.
+%
+% As it is experimental, even if this library is loaded then it isn't automatically switched on.
+% To do that, use either the \Verb!tikzmarkmath! environment or the \Verb!\tikzmarkmath! command.
+% Each has an optional argument which is a prefix for the node names (the default is \Verb!equation!).
+% The node names are then of the form \Verb!<prefix>-<number>!.
+% The numbering is held in a counter called \Verb!tikzmarkequation! and is reset when the command is invoked or the environment is started.
+% As usual, redefining \Verb!\thetikzmarkequation! changes the styling of the \Verb!<number>!.
+%
+% To disable the marking, either end the environment or use \Verb!\endtikzmarkmath!.
+% The ending command explicitly removes the hook rather than rely on \TeX\ groupings.
+% It also prints out the number of nodes created to the log file and terminal.
+% This can be useful with figuring out which nodes to use, since the box that this library hooks into is used many times.
+% For example, equation numbers are included with this.
+%
+% The box is also used when assembling a \Verb!\sqrt[3]{4}! command, and as that uses \Verb!\mathchoice! then there are more boxes created than used.
+% So the count of number of nodes created can be more than are actually there.
+%
+% \begin{example}
+% \begin{tikzmarkmath}[pythagoras]
+% 
+% \begin{gather}
+% a^2 = b^2 + c^2
+% \end{gather}
+% 
+% \begin{gather}
+% a = \sqrt[2]{b^2 + c^2}
+% \end{gather}
+% \end{tikzmarkmath}
+% 
+% \begin{tikzpicture}[remember picture, overlay]
+% \foreach \k in {1,2,3,7,8} {
+%   \draw[red]  (pic cs:pythagoras-\k) -- ++(135:1) node[draw,red,circle,font=\tiny,above left] {\k};
+%   \node[draw,blue,fit=(pythagoras-\k),inner sep=0pt] {};
+% }
+% \end{tikzpicture}
+% % \end{example}
+%
+%
+% \subsection{Highlighting}
+%
+% I've returned to the highlighting library.
+% The \LaTeX3 hook mechanism makes a couple of things possible that were tricky before.
+%
+% The idea of the highlighting mechanism is to use two \Verb!\tikzmark!s to mark a start and end of a region to be highlighted.
+% The region is considered to be formed by lines of text, with the first mark at the baseline of the start and the second at the baseline of the end.
+%
+% The highlighting itself is done by inserting code in the shipout routine before the page itself is laid out.
+% So the highlighting is on a separate layer to the text itself, which can be either behind or in front of the text layer.
+% The hook mechanisem also makes it relatively simple to support page breaks between the start and end of highlighting.
+%
+% Since the highlighting is separate to the flow of the text, it doesn't make sense to use an environment to mark the start and end of the highlighting so instead there are two commands: \Verb!\StartHighlighting[options]! and \Verb!\StopHighlighting!, or a single command \Verb!\Highlight[options]{text}! that just highlights the \Verb!text!.
+% At the moment, nesting highlighting is not supported.
+%
+% The optional argument to \Verb!\StartHighlighting! (or \Verb!\Highlight!) consists of key-value pairs that control the behaviour of the highlighted region.
+% There are particular keys in the \Verb!/tikz/highlighter! family which control the size of the highlighted region.
+%
+% The keys are as follows:
+%
+% \begin{itemize}
+% \item \texttt{direction}
+% \item \texttt{layer}
+% \item \texttt{initial height}
+% \item \texttt{initial depth}
+% \item \texttt{initial offset}
+% \item \texttt{final height}
+% \item \texttt{final depth}
+% \item \texttt{final offset}
+% \item \texttt{left margin}
+% \item \texttt{right margin}
+% \item \texttt{height}
+% \item \texttt{depth}
+% \item \texttt{offset}
+% \item \texttt{margin}
+% \end{itemize}
+%
+% The highlighting code draws a region which can be styled with standard TikZ keys, more of which in a moment.
+% Although it is a single region, the \emph{intention} is to simulate using an actual highlighter.
+% The first key, \Verb!direction!, is used to draw the region as if the highlighter were used in a particular direction.
+% The options are \Verb!horizontal!, \Verb!vertical!, or \Verb!box!.
+% The default is \Verb!horizontal!.
+%
+% The second key, \Verb!layer!, determines whether the highlighter is rendered on the \Verb!background! or \Verb!foreground! layer.
+% Using the \Verb!background! layer puts the highlighting underneath the text, which will make the text easier to read.
+% The \Verb!foreground! option puts the highlighting over the text, which can be used to fade the text.
+% The default is \Verb!background!.
+%
+% The shape of the region depends on a few things, such as whether the highlighting starts and ends on the same line.
+%
+% \begin{tikzpicture}[>=Latex]
+% \fill (0,0) circle[radius=2pt];
+% \fill (4,0) circle[radius=2pt];
+% \draw (-1,-1) rectangle (5,1);
+% \draw[dashed] (0,0) -- (4,0);
+% \draw[<->] (0,0) -- +(-1,0);
+% \draw[<->] (0,0) -- +(0,1);
+% \draw[<->] (4,0) -- +(0,-1);
+% \draw[<->] (4,0) -- +(1,0);
+% \draw[<-] (-.5,0) to[out=90,in=-90] +(-1,1.5) node[above] {initial offset};
+% \draw[<-] (4.5,0) to[out=90,in=-90] +(1,1.5) node[above] {final offset};
+% \draw[<-] (0,.5) to[out=0,in=180] +(1,1.5) node[right] {initial height};
+% \draw[<-] (4,-.5) to[out=0,in=180] +(1,-1.5) node[right] {final depth};
+% \node[anchor=base] at (2,0) {Single line};
+% \end{tikzpicture}
+%
+% \begin{tikzpicture}[>=Latex]
+% \fill (0,0) circle[radius=2pt];
+% \draw (-1,-1) rectangle (4,1);
+% \draw[dashed] (0,0) -- (4,0);
+% \draw[<->] (0,0) -- +(-1,0);
+% \draw[<->] (0,0) -- +(0,1);
+% \draw[<->] (0,0) -- +(0,-1);
+% \draw[<-] (-.5,0) to[out=90,in=-90] +(-1,1.5) node[above] {initial offset};
+% \draw[<-] (0,.5) to[out=0,in=180] +(1,1.5) node[right] {initial height};
+% \draw[<-] (0,-.5) to[out=0,in=180] +(1,-1.5) node[right] {initial depth};
+% \node[anchor=base] at (2,0) {Split line};
+% \begin{scope}[yshift=-3cm,xshift=-5cm]
+% \fill (4,0) circle[radius=2pt];
+% \draw (0,-1) rectangle (5,1);
+% \draw[dashed] (0,0) -- (4,0);
+% \draw[<->] (4,0) -- +(1,0);
+% \draw[<->] (4,0) -- +(0,1);
+% \draw[<->] (4,0) -- +(0,-1);
+% \draw[<-] (4.5,0) to[out=90,in=180] +(2.5,0) node[right] {final offset};
+% \draw[<-] (4,.5) to[out=180,in=0] +(-1,1.5) node[left] {final height};
+% \draw[<-] (4,-.5) to[out=0,in=180] +(1.5,-1) node[right] {final depth};
+% \node[anchor=base] at (2,0) {Split line};
+% \end{scope}
+% \end{tikzpicture}
+%
+% \begin{tikzpicture}[>=Latex]
+% \fill (0,0) circle[radius=2pt];
+% \fill (4,0) circle[radius=2pt];
+% \fill (-4,-1) circle[radius=2pt];
+% \fill (4,-1) circle[radius=2pt];
+% \fill (-4,-2) circle[radius=2pt];
+% \fill (0,-2) circle[radius=2pt];
+% \draw (-1,0) -- (-1,1) -- (5,1) -- (5,-2) -- (1,-2) -- (1,-3) -- (-5,-3) -- (-5,0) -- cycle;
+% \draw[dashed] (0,0) -- (4,0);
+% \draw[dashed] (-4,-1) -- (4,-1);
+% \draw[dashed] (-4,-2) -- (0,-2);
+% \draw[<->] (0,0) -- +(-1,0);
+% \draw[<->] (0,0) -- +(0,1);
+% \draw[<->] (4,0) -- +(1,0);
+% \draw[<->] (0,-2) -- +(1,0);
+% \draw[<->] (0,-2) -- +(0,-1);
+% \draw[<->] (-4,-2) -- +(-1,0);
+% \draw[<-] (-.5,0) to[out=90,in=0] +(-1,.5) node[left] {initial offset};
+% \draw[<-] (0,.5) to[out=0,in=180] +(1,0) node[right] {initial height};
+% \draw[<-] (4.5,0) to[out=90,in=-90] +(1,1.5) node[above] {right margin};
+% \draw[<-] (.5,-2) to[out=-90,in=180] +(1,-.5) node[right] {final offset};
+% \draw[<-] (0,-2.5) to[out=180,in=0] +(-1,0) node[left] {final depth};
+% \draw[<-] (-4.5,-2) to[out=90,in=-90] +(-1,1.5) node[above] {left margin};
+% \node[anchor=base] at (0,-1) {Multiple lines};
+% \end{tikzpicture}
+%
+% The \texttt{vertical} regions and the \texttt{box} are defined similarly.
+% With the vertical regions then the meaning of the \Verb!height!, \Verb!depth!, and \Verb!offset! are rotated \(90^\circ\), and the vertial regions don't stretch to the page boundaries.
+% The \texttt{box} region is always a rectangle.
+%
+% Once the region is defined, it can be styled using options directly on the \Verb!StartHighlighting! or \Verb!\Highlight! command and by using the following styles:
+%
+% \begin{itemize}
+% \item \texttt{every highlight picture}
+% \item \texttt{every <direction> highlight picture}
+% \item \texttt{every <layer> highlight picture}
+% \item \texttt{every highlight path}
+% \item \texttt{every <direction> highlight path}
+% \item \texttt{every <layer> highlight path}
+% \item \texttt{highlight path}
+% \item \texttt{<direction> highlight path}
+% \item \texttt{<layer> highlight path}
+% \end{itemize}
+%
+% The \Verb!picture! keys are for the surrounding \Verb!tikzpicture!, while the \Verb!path! keys are for the path itself.
+%
+% Lastly, a word about scoping the options.
+% Since the code that actually renders the highlighting is processed when the page is shipped out, it may well be that the settings in force when the highlighting was defined have changed.
+% The keys that adjust the size of the region (in the \Verb!highlighter! family) are saved at the moment of invocation but keys such as the colour or whether to fill or draw the path are not.
+% Therefore, it is wise to use styles that persist to set the rendering styles.
+%
+% \begin{example}
+% The sun was shining on the sea, shining with all its might.
+% \StartHighlighting[fill=cyan!50]
+% And this was very odd because it was the middle of the night.
+% \StopHighlighting
+% The moon was up there sulkily because she thought the sun had no
+% business to be there after the day was done.
+% \StartHighlighting[fill=magenta!50]
+% ``It's very rude of him,'' she said, ``to come and spoil the fun.''
+% \StopHighlighting
+
+% \noindent The sun was shining on the sea, shining with all its might.
+% And this was very odd because it was the middle of the night.
+% \StartHighlighting[fill=yellow!50]
+% The moon was up there sulkily because she thought the sun had no business to be there after the day was done\StopHighlighting.
+% ``It's very rude of him,'' she said, ``to come and spoil the fun.''
+% \end{example}
+%
 % \section{Acknowledgements}
 %
 % The \Verb+\tikzmark+ macro has been used and abused by many users of \href{http://tex.stackexchange.com}{TeX-SX}.
@@ -810,8 +1080,8 @@
 % The \Verb+save nodes+ code uses \LaTeX3.
 %    \begin{macrocode}
 \ProvidesFile{tikzlibrarytikzmark.code.tex}[%
-  2021/02/16
-  v1.10
+  2022/08/24
+  v1.15
   TikZ library for marking positions in a document]
 \RequirePackage{expl3, l3keys2e, xparse}
 %    \end{macrocode}
@@ -959,6 +1229,79 @@
 %    \begin{macrocode}
   tikzmark prefix/.initial=,%
   tikzmark suffix/.initial=,%
+  tikzmark clear ixes/.style={
+    tikzmark prefix={},
+    tikzmark suffix={}
+  },
+%    \end{macrocode}
+% Tikzmarks can be used to adjust the position of a scope or pic so that an internally defined coordinate is used to locate the scope or pic.
+%
+% The key used to adjust the location is \Verb!scope anchor={coordinate}! for \Verb!scope!s and \Verb!pic anchor={coordinate}! for \Verb!pic!s, where \Verb!coordinate! is evaluated internally to the \Verb!scope! or \Verb!pic!, so can use node names.
+%    \begin{macrocode}
+  scope anchor location/.initial={(0,0)},
+  scope anchor location/.default=@auto,
+  pic anchor/.style={
+    scope anchor location={#1},
+    next pic/.append style={
+      adjust scope position,
+    }
+  },
+  scope anchor/.style={
+    scope anchor location={#1},
+    adjust scope position,
+  },
+%    \end{macrocode}
+% The code that does the adjustment is added to the \Verb!pic! on its enclosing scope using the \Verb!every pic! key.
+%    \begin{macrocode}  
+  adjust scope position/.code={%
+    \pgfutil at ifundefined{tikz at fig@name}%
+    {\let\tikz at fig@name=\pgfutil at empty}{}%
+    \tikz at resetexpandcount%
+    \tikz at fig@mustbenamed
+    \pgfkeysgetvalue{/tikz/scope anchor location}\tkzmk at anchor
+    \ifx\tkzmk at anchor\tikz at auto@text
+    \tikzset{local bounding box/.expanded=\tikz at fig@name}%
+    \def\tkzmk at anchor{(\tikz at fig@name.\tikz at anchor)}%
+    \fi
+    \tikz at scan@one at point
+    \pgfutil at firstofone(pic cs:\tikz at fig@name-origin)\relax
+    \pgf at xa=\pgf at x
+    \pgf at ya=\pgf at y
+    \tikz at scan@one at point
+    \pgfutil at firstofone(pic cs:\tikz at fig@name-anchor)\relax
+    \advance\pgf at xa by -\pgf at x
+    \advance\pgf at ya by -\pgf at y
+    \tikzset{
+      shift={(\the\pgf at xa,\the\pgf at ya)},
+      execute at end scope={%
+        \tikzmark{\tikz at fig@name-origin}{(0,0)}%
+        \tikzmark{\tikz at fig@name-anchor}{\tkzmk at anchor}%
+      }
+    }
+  },
+%    \end{macrocode}
+%
+% To install this code on a pic, we hook in to the pic's enclosing scope using the \Verb+every pic+ key.
+% To avoid this bubbling down to pics within pics, we clear it once it has been executed.
+% So any code that triggers this adjustment adds \Verb!adjust pic position! to the !next pic! style.
+%    \begin{macrocode}
+  every pic/.append style={
+    next pic/.try,
+    next pic/.style={}
+  },
+%    \end{macrocode}
+%  
+% This code remembers the bounding box of a pic, saving it as if it were a node.
+%    \begin{macrocode}
+  save pic bounding box/.code={
+    \tikz at fig@mustbenamed
+    \tikzset{local bounding box/.expanded=\tikz at fig@name}
+  },
+  surround pic/.style={
+    next pic/.append style={
+      save pic bounding box
+    }
+  },
 }
 %    \end{macrocode}
 %
@@ -987,11 +1330,25 @@
 % \end{macro}
 %
 % \begin{macro}{\tikzmarkalias}
-% Alias a tikzmark to another name (used in tikzmarknode)
+% Alias a tikzmark to another name (used in tikzmarknode).
+% The alias is saved to the aux-file so that it is available prior to the definition.
+% The private one doesn't use the prefix-suffix for greater internal flexibility.
+% The public one does.
 %    \begin{macrocode}
+\def\@tikzmarkalias#1#2{%
+  \@ifundefined{save at pt@#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}%
+    \protected at write\pgfutil at auxout{}{%
+      \string\savepointas%
+      {#1}{\csname save at pt@#2\endcsname}%
+      \expandafter\expandafter\expandafter
+      \@gobble\csname save at pt@#2 at offset\endcsname
+    }%
+  }%
+}
 \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}%
+  \@tikzmarkalias{\tikzmark at pp@name{#1}}{\tikzmark at pp@name{#2}}%
 }
 %    \end{macrocode}
 % \end{macro}
@@ -1017,7 +1374,8 @@
     \tmk at labeldef#1,(0pt,0pt)\@nil
   \fi
   \@ifundefined{save at pt@\tmk at label}{%
-    \tikz at scan@one at point\pgfutil at firstofone\tmk at def
+    \expandafter\tikz at scan@one at point
+    \expandafter\pgfutil at firstofone\tmk at def\relax
   }{%
     \pgfsys at getposition{\csname save at pt@\tmk at label\endcsname}%
     \save at orig@pic%
@@ -1076,7 +1434,9 @@
 %    \begin{macrocode}
 \def\tikzmark at inside#1#2{%
   \tikzset{remember picture}%
+  \tikz at resetexpandcount%
   \tikz at scan@one at point\pgfutil at firstofone#2\relax
+  \pgf at pos@transform{\pgf at x}{\pgf at y}%
   \protected at write\pgfutil at auxout{}{%
     \string\savepointas%
     {\tikzmark at pp@name{#1}}{\pgfpictureid}{\the\pgf at x}{\the\pgf at y}}%
@@ -1103,18 +1463,22 @@
 % \begin{macro}{\pgfmark}
 %    \begin{macrocode}
 \newcommand\pgfmark[1]{%
-    \bgroup
-    \global\advance\pgf at picture@serial at count by1\relax%
-    \edef\pgfpictureid{pgfid\the\pgf at picture@serial at count}%
-      \pgfsys at markposition{\pgfpictureid}%
-    \edef\pgf at temp{%
-      \noexpand\write\noexpand\pgfutil at auxout{%
-        \string\savepicturepage{\pgfpictureid}{\noexpand\arabic{page}}}}%
-    \pgf at temp
-    \protected at write\pgfutil at auxout{}{%
-      \string\savepointas{\tikzmark at pp@name{#1}}{\pgfpictureid}{0pt}{0pt}}%
-    \egroup
-  }
+  \bgroup
+  \global\advance\pgf at picture@serial at count by1\relax%
+  \edef\pgfpictureid{pgfid\the\pgf at picture@serial at count}%
+  \pgfsys at markposition{\pgfpictureid}%
+  \edef\pgf at temp{%
+    \noexpand\write\noexpand\pgfutil at auxout{%
+      \string\savepicturepage
+      {\pgfpictureid}{\noexpand\arabic{page}}%
+    }%
+  }%
+  \pgf at temp
+  \protected at write\pgfutil at auxout{}{%
+    \string\savepointas
+    {\tikzmark at pp@name{#1}}{\pgfpictureid}{0pt}{0pt}}%
+  \egroup
+}
 %    \end{macrocode}
 % \end{macro}
 %
@@ -1183,7 +1547,9 @@
   \@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}{%
+    \@ifundefined{save at pg@%
+      \csname save at pt@\tikzmark at pp@name{#1}\endcsname%
+    }{%
       \tikzmark at false
     }{%
       \ifnum\csname save at pg@%
@@ -1206,7 +1572,9 @@
   \@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}{%
+    \@ifundefined{save at pg@%
+      \csname save at pt@\tikzmark at pp@name{#1}\endcsname%
+    }{%
       \tikzmark at false
     }{%
       \ifnum\csname save at pg@%
@@ -1225,13 +1593,15 @@
 %
 % \begin{macro}{\subnode}
 % Note: much of this code was inevitably adapted from the node defining code in the TikZ/PGF sources.
+%
+% The \Verb!\pgfmark! applies the current tikzmark prefix/suffix.
+% The current node prefix/suffix is applied by using the \Verb!name=! key.
 %    \begin{macrocode}
 \def\subnode@#1#2#3{%
   \begingroup
   \pgfmark{#2}%
   \setbox\pgfnodeparttextbox=\hbox\bgroup #3\egroup
-  \def\tikz at fig@name{#2}%
-  \tikzset{every subnode/.try,#1}%
+  \tikzset{every subnode/.try,#1,name=#2}%
   \pgfpointorigin
   \tikz at scan@one at point\pgfutil at firstofone(pic cs:#2)\relax
   \advance\pgf at x by .5\wd\pgfnodeparttextbox
@@ -1251,7 +1621,8 @@
       \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{%
+    \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
@@ -1258,17 +1629,22 @@
     \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}%
+    \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}%
+      \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
+      \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}%
+    \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
@@ -1291,31 +1667,34 @@
   \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}%
+  \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}%
+  \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}%
+  \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
-  \pgfutil at ifundefined{pgf at sh@ns@#2}{%
-    \pgfnodealias{#2}{#2-t}%
-    \tikzmarkalias{#2}{#2-t}%
+  \pgfutil at ifundefined{pgf at sh@ns@\tikz at pp@name{#2}}{%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-t}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
   }{}%
   \else
-    \pgfnodealias{#2}{#2-d}%
-    \tikzmarkalias{#2}{#2-d}%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-d}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-d}}%
   \fi
   \else
-    \pgfnodealias{#2}{#2-t}%
-    \tikzmarkalias{#2}{#2-t}%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-t}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
   \fi
   \else
-    \pgfnodealias{#2}{#2-s}%
-    \tikzmarkalias{#2}{#2-s}%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-s}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-s}}%
   \fi
   \else
-    \pgfnodealias{#2}{#2-ss}%
-    \tikzmarkalias{#2}{#2-ss}%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-ss}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-ss}}%
   \fi
   \else
     \subnode@{#1}{#2}{#3}%
@@ -1366,31 +1745,34 @@
   \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}%
+  \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}%
+  \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}%
+  \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
   \pgfutil at ifundefined{pgf at sh@ns@\tikz at pp@name{#2}}{%
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-t}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
   }{}%
   \else
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-d}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-d}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-d}}%
   \fi
   \else
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-t}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
   \fi
   \else
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-s}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-s}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-s}}%
   \fi
   \else
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-ss}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-ss}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-ss}}%
   \fi
   \else
     \tikzmarknode@{#1}{#2}{#3}%
@@ -1399,7 +1781,81 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\tikzmark at box}
+% This macro takes a name and a box.
+% It pretends that there is a tight-fitting rectangular PGF node around that box with the given name, and saves the required information so that that node can be used later on in a tikzpicture drawing.
 %
+% It does not actually build a node, and it doesn't create a TikZ drawing.
+% Rather, it measures the box and uses that information to define the various macros that store the information about the node.
+%
+% Apart from assigning a load of macros, it does also place a \Verb+\pgfmark+ just before the box.
+% This is needed to be able to locate the node on the page.
+%
+% The command is defined with an \Verb!@! because it is more likely to be used in other packages than by a user.
+%    \begin{macrocode}
+\def\tikzmark at box#1#2{%
+  \begingroup
+  \pgfmark{#1}%
+  \let\pgfnodeparttextbox=#2%
+  \edef\pgfpictureid{pgfid\the\pgf at picture@serial at count}%
+  \def\tikz at fig@name{#1}%
+  \pgfpointorigin
+  \advance\pgf at x by .5\wd\pgfnodeparttextbox
+  \advance\pgf at y by .5\ht\pgfnodeparttextbox
+  \advance\pgf at y by -.5\dp\pgfnodeparttextbox
+  \pgftransformshift{}%
+  \setbox\@tempboxa=\hbox\bgroup
+  {%
+    \tikzset{
+      inner sep=0pt, 
+      minimum size=0pt, 
+      outer sep=0pt, 
+      anchor=base
+    }%
+    \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
+  \endgroup
+  \box#2%
+}
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\usetikzmarklibrary}
 %    \begin{macrocode}
 \def\usetikzmarklibrary{%
@@ -1407,21 +1863,27 @@
   }%}
 \def\use at tikzmarklibrary[#1]{\use@@tikzmarklibrary{#1}}
 \def\use@@tikzmarklibrary#1{%
-  \edef\pgf at list{#1}%
-  \pgfutil at for\pgf at temp:=\pgf at list\do{%
-    \expandafter\pgfkeys at spdef\expandafter\pgf at temp\expandafter{\pgf at temp}%
+    \edef\pgf at list{#1}%
+    \pgfutil at for\pgf at temp:=\pgf at list\do{%
+      \expandafter\pgfkeys at spdef
+      \expandafter\pgf at temp\expandafter{\pgf at temp}%
     \ifx\pgf at temp\pgfutil at empty
     \else
-      \expandafter\ifx\csname tikzmark at library@\pgf at temp @loaded\endcsname\relax%
+      \expandafter\ifx
+      \csname tikzmark at library@\pgf at temp @loaded\endcsname\relax%
       \expandafter\global\expandafter\let%
-      \csname tikzmark at library@\pgf at temp @loaded\endcsname=\pgfutil at empty%
-      \expandafter\edef\csname tikzmark at library@#1 at atcode\endcsname{\the\catcode`\@}
-      \expandafter\edef\csname tikzmark at library@#1 at barcode\endcsname{\the\catcode`\|}
+      \csname tikzmark at library@\pgf at temp @loaded\endcsname
+      =\pgfutil at empty%
+      \expandafter\edef
+      \csname tikzmark at library@#1 at atcode\endcsname{\the\catcode`\@}
+      \expandafter\edef
+      \csname tikzmark at library@#1 at barcode\endcsname{\the\catcode`\|}
       \catcode`\@=11
       \catcode`\|=12
       \pgfutil at InputIfFileExists{tikzmarklibrary\pgf at temp.code.tex}{}{
-          \PackageError{tikzmark}{I did not find the tikzmark extras library '\pgf at temp'.}{}
-        }%
+        \PackageError{tikzmark}{
+          I did not find the tikzmark extras library '\pgf at temp'.}{}
+      }%
       \catcode`\@=\csname tikzmark at library@#1 at atcode\endcsname
       \catcode`\|=\csname tikzmark at library@#1 at barcode\endcsname
       \fi%
@@ -1428,7 +1890,6 @@
     \fi
   }%
 }
-
 %    \end{macrocode}
 % \end{macro}
 %
@@ -1436,8 +1897,17 @@
 %
 %    \begin{macrocode}  
 \ExplSyntaxOn
+\cs_new_protected:Nn \tikzmark_tl_put_right_braced:Nn
+ {
+  \tl_put_right:Nn #1 { { #2 } }
+ }
+\cs_generate_variant:Nn \tikzmark_tl_put_right_braced:Nn { NV, cV, cv, Nx, cx }
 %    \end{macrocode}
 %
+% This is how we handle return values from functions
+%    \begin{macrocode}
+\tl_new:N \g__sn_output_tl
+%    \end{macrocode}  
 % We save our information in a ``property list'', which is L3's
 % version of an associative array or dictionary.  They keys will give
 % the ability to store several groups of nodes and restore them at
@@ -1462,9 +1932,10 @@
 \tl_new:N \l__sn_group_tl
 %    \end{macrocode}
 %
-% We store up the nodes in a list and save them at the end of a given tikzpicture.    
+% We store up the nodes in a list and save them at the end of a given tikzpicture.
+% Has to be global as we're often in a group.    
 %    \begin{macrocode}    
-\clist_new:N \l__sn_nodes_clist
+\clist_new:N \g__sn_nodes_clist
 %    \end{macrocode}
 %
 % This boolean is for whether we save to a file or not.
@@ -1475,9 +1946,19 @@
 % 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
+\bool_gset_true:N \g__sn_preamble_bool
 %    \end{macrocode}
 %
+% Key interface for setting some of the options
+%    \begin{macrocode}
+\keys_define:nn {tikzmark / save nodes}
+{
+  file .bool_set:N = \l__sn_file_bool,
+  group  .tl_set:N = \l__sn_group_tl,
+}
+%    \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".}
@@ -1547,22 +2028,24 @@
 %
 % \begingroup
 % \catcode`_=12
-% \begin{macro}{\save_nodes:Nn}
+% \begin{macro}{\process_node:Nn}
 % This is the command that actually does the work.  It constructs a
 % token list which contains the code that will restore the node data
 % when invoked.  The two arguments are the token list to store this in
-% and a comma separated list of the node names to be saved.
+% and the node name to be saved.
 %    \begin{macrocode}
-\cs_new_nopar:Npn \save_nodes:Nn #1#2
+\cs_new_nopar:Npn \__sn_process_node:n #1
 {
+  \group_begin:
 %    \end{macrocode}
-% Clear our token lists
+% Clear our token list
 %    \begin{macrocode}
   \tl_clear:N \l__sn_tmpa_tl
 %    \end{macrocode}
 % Set the centre of the picture
 %    \begin{macrocode}  
-  \tikz_scan_point:NNn \l__sn_x_dim \l__sn_y_dim {(current~ bounding~ box.center)}
+  \tikz_scan_point:NNn \l__sn_x_dim \l__sn_y_dim
+  {(current~ bounding~ box.center)}
   \dim_set:Nn \l__sn_x_dim {-\l__sn_x_dim}
   \dim_set:Nn \l__sn_y_dim {-\l__sn_y_dim}
   \tl_set:Nx \l__sn_centre_tl {
@@ -1569,21 +2052,16 @@
     {1}{0}{0}{1}{\dim_use:N \l__sn_x_dim}{\dim_use:N \l__sn_y_dim}
   }
 %    \end{macrocode}  
-% Iterate over the list of node names
+% Test to see if the node has been defined
 %    \begin{macrocode}
-  \clist_map_inline:nn {#2}
+  \tl_if_exist:cT {pgf at sh@ns@#1}
   {
-%    \end{macrocode}  
-% Test to see if the node has been defined
-%    \begin{macrocode}
-    \tl_if_exist:cT {pgf at sh@ns@##1}
-    {
-%    \end{macrocode}  
+%    \end{macrocode}
 % The node information is stored in a series of macros of the form
 % \Verb+\pgf at sh@XX at nodename+ where XX is one of the following.
 %    \begin{macrocode}
-      \clist_map_inline:nn {ns,np,ma,pi}
-      {
+    \clist_map_inline:nn {ns,np,ma,pi}
+    {
 %    \end{macrocode}  
 % Our token list will look like:
 %
@@ -1594,36 +2072,36 @@
 %
 % This part puts the \Verb+\tl_set:cn {pgf at sh@XX at nodename}+ in place
 %    \begin{macrocode}
-        \tl_put_right:Nn \l__sn_tmpa_tl
-        {
-          \tl_gset:cn {pgf at sh@####1@ \tikz_set_node_name:n{##1} }
-        }
-%    \end{macrocode}  
+      \tl_put_right:Nn \l__sn_tmpa_tl
+      {
+        \tl_gset:cn {pgf at sh@##1@ \tikz_set_node_name:n{#1} }
+      }
+%    \end{macrocode}
 % Now we put the current contents in place.  We're doing this in
 % an expansive context to get at the contents.  The \Verb+\exp_not:v+
 % part takes the current value of \Verb+\pgf at sh@XX at nodename+ and puts
 % it in place, preventing further expansion.
 %    \begin{macrocode}
-        \tl_if_exist:cTF {pgf at sh@####1@##1}
-        {
-          \tl_put_right:Nx \l__sn_tmpa_tl {
-            {\exp_not:v {pgf at sh@####1@ \tikz_set_node_name:n {##1}}}
-          }
+      \tl_if_exist:cTF {pgf at sh@##1@#1}
+      {
+        \tl_put_right:Nx \l__sn_tmpa_tl {
+          {\exp_not:v {pgf at sh@##1@ \tikz_set_node_name:n {#1}}}
         }
-        {
-          \tl_put_right:Nx \l__sn_tmpa_tl {{}}
-        }
       }
-      \tl_put_right:Nn \l__sn_tmpa_tl
       {
-        \tl_gset:cn {pgf at sh@nt@ \tikz_set_node_name:n{##1} }
+        \tl_put_right:Nx \l__sn_tmpa_tl {{}}
       }
-      \compose_transformations:NVv \l__sn_tmpb_tl \l__sn_centre_tl {pgf at sh@nt@##1}
-      \tl_put_right:Nx \l__sn_tmpa_tl {{\exp_not:V \l__sn_tmpb_tl}}
-      \tl_put_right:Nn \l__sn_tmpa_tl {
-        \transform_node:Nn \l__sn_transformation_tl {
-          \tikz_set_node_name:n{##1}
-        }
+    }
+    \tl_put_right:Nn \l__sn_tmpa_tl
+    {
+      \tl_gset:cn {pgf at sh@nt@ \tikz_set_node_name:n{#1} }
+    }
+    \compose_transformations:NVv
+    \l__sn_tmpb_tl \l__sn_centre_tl {pgf at sh@nt@#1}
+    \tl_put_right:Nx \l__sn_tmpa_tl {{\exp_not:V \l__sn_tmpb_tl}}
+    \tl_put_right:Nn \l__sn_tmpa_tl {
+      \transform_node:Nn \l__sn_transformation_tl {
+        \tikz_set_node_name:n{#1}
       }
     }
   }
@@ -1631,8 +2109,21 @@
 % Once we've assembled our token list, we store it in the given
 % token list
 %    \begin{macrocode}
-  \tl_set_eq:NN #1 \l__sn_tmpa_tl
+  \tl_gset_eq:NN \g__sn_output_tl \l__sn_tmpa_tl
+  \group_end:
 }
+\cs_new_protected_nopar:Npn \process_node:Nn #1#2
+{
+  \__sn_process_node:n {#2}
+  \tl_set_eq:NN #1 \g__sn_output_tl
+  \tl_gclear:N \g__sn_output_tl
+}
+\cs_new_protected_nopar:Npn \process_gnode:Nn #1#2
+{
+  \__sn_process_node:n {#2}
+  \tl_gset_eq:NN #1 \g__sn_output_tl
+  \tl_gclear:N \g__sn_output_tl
+}
 %    \end{macrocode}  
 % \end{macro}
 %
@@ -1641,7 +2132,12 @@
 %    \begin{macrocode}
 \cs_new_nopar:Npn \save_nodes_to_list:nn #1#2
 {
-  \save_nodes:Nn \l__sn_tmpa_tl {#2}
+  \tl_clear:N \l__sn_tmpa_tl
+  \clist_map_inline:nn {#2}
+  {
+    \process_node:Nn \l__sn_tmpb_tl {##1}
+    \tl_put_right:NV \l__sn_tmpa_tl \l__sn_tmpb_tl
+  }
   \prop_gput:NnV \g__sn_prop {#1} \l__sn_tmpa_tl
 }
 %    \end{macrocode}
@@ -1650,24 +2146,27 @@
 % \begin{macro}{\save_nodes_to_file:n}
 % Save the nodes to a file
 %    \begin{macrocode}
+\cs_generate_variant:Nn \iow_now:Nn {NV}
 \cs_new_nopar:Npn \save_nodes_to_file:n #1
 {
-  \save_nodes:Nn \l__sn_tmpa_tl {#1}
+  \sn_open_stream:
+  \clist_map_inline:nn {#1}
+  {
+    \process_node:Nn \l__sn_tmpa_tl {##1}
 %    \end{macrocode}  
 % 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
-  {
-    \iow_newline:
-    \exp_not:V \l__sn_tmpa_tl
-    \iow_newline:
+    \iow_now:Nx \g__sn_stream
+    {
+      \iow_newline:
+      \exp_not:V \l__sn_tmpa_tl
+    }
   }
 }
 %    \end{macrocode}
 % \end{macro}
 %    \begin{macrocode}
-\cs_generate_variant:Nn \save_nodes_to_list:nn {VV}
+\cs_generate_variant:Nn \save_nodes_to_list:nn {VV, Vn}
 \cs_generate_variant:Nn \save_nodes_to_file:n {V}
 %    \end{macrocode}
 %
@@ -1702,6 +2201,7 @@
     \msg_warning:nnn {tikzmark} {no file} {#1}
   }
 }
+\cs_generate_variant:Nn \restore_nodes_from_file:n {x}
 \AtBeginDocument{\bool_gset_false:N \g__sn_preamble_bool}
 %    \end{macrocode}
 % \end{macro}
@@ -1781,7 +2281,8 @@
 % \end{macro}
 %
 %    \begin{macrocode}
-\cs_generate_variant:Nn \compose_transformations:Nnn {cVv,NVv,NVn,NvV,NnV}
+\cs_generate_variant:Nn \compose_transformations:Nnn
+{cVv,NVv,NVn,NvV,NnV}
 %    \end{macrocode}
 %
 % \begin{macro}{\transform_node:Nn}
@@ -1800,8 +2301,12 @@
   \tl_set_eq:Nc \l__sn_transformation_tl {pgf at sh@nt@#1}
   \tikz_scan_point:NNn \l__sn_x_dim \l__sn_y_dim {(#1.center)}
     
-  \dim_set:Nn \l__sn_x_dim {\l__sn_x_dim - \tl_item:cn {pgf at sh@nt@#1}{5}}
-  \dim_set:Nn \l__sn_y_dim {\l__sn_y_dim - \tl_item:cn {pgf at sh@nt@#1}{6}}
+  \dim_set:Nn \l__sn_x_dim {
+    \l__sn_x_dim - \tl_item:cn {pgf at sh@nt@#1}{5}
+  }
+  \dim_set:Nn \l__sn_y_dim {
+    \l__sn_y_dim - \tl_item:cn {pgf at sh@nt@#1}{6}
+  }
     
   \compose_transformations:NnV  \l__sn_transformation_tl {
     {1}{0}{0}{1}{\dim_use:N \l__sn_x_dim}{\dim_use:N \l__sn_y_dim}
@@ -1849,16 +2354,23 @@
     }
   },
 %    \end{macrocode}  
-% Append current node to the list of nodes to be saved
+% Append current node or named node to the list of nodes to be saved
 %    \begin{macrocode}
   save~ node/.code={
-    \tikz_fig_must_be_named:
-    \pgfkeysalso{append~ after~ command={
-        \pgfextra{
-          \clist_gput_right:Nv \l__sn_nodes_clist {tikz at last@fig at name}
+    \tl_if_eq:nnTF {#1} {\pgfkeysnovalue}
+    {
+      \tikz_fig_must_be_named:
+      \pgfkeysalso{
+        append~ after~ command={
+          \pgfextra{
+            \clist_gput_right:Nv \g__sn_nodes_clist {tikz at last@fig at name}
+          }
         }
       }
     }
+    {
+      \clist_gput_right:Nn \g__sn_nodes_clist {#1}
+    }
   },
 %    \end{macrocode}  
 % Restore nodes from file
@@ -1866,7 +2378,7 @@
   restore~ nodes~ from~ file/.code={
     \bool_if:NTF \g__sn_preamble_bool
     {
-      \restore_nodes_from_file:n {#1}
+      \restore_nodes_from_file:x {#1}
     }
     {
       \tikz_fig_must_be_named:
@@ -1873,7 +2385,7 @@
       \pgfkeysalso{append~ after~ command={
           \pgfextra{
             \scope
-            \split_argument:NNn \tikzset \restore_nodes_from_file:n {#1}
+            \split_argument:NNn \tikzset \restore_nodes_from_file:x {#1}
             \endscope
           }
         }
@@ -1929,23 +2441,52 @@
 %    \begin{macrocode}
 \cs_new_nopar:Npn \maybe_save_nodes:
 {
-  \clist_if_empty:NF \l__sn_nodes_clist
+  \clist_if_empty:NF \g__sn_nodes_clist
   {
     \bool_if:NTF \l__sn_file_bool
     {
-      \save_nodes_to_file:V \l__sn_nodes_clist
+      \save_nodes_to_file:V \g__sn_nodes_clist
     }
     {
       \tl_if_empty:NF \l__sn_group_tl
       {
-        \save_nodes_to_list:VV \l__sn_group_tl \l__sn_nodes_clist
+        \save_nodes_to_list:VV \l__sn_group_tl \g__sn_nodes_clist
       }
     }
-    \clist_gclear:N \l__sn_nodes_clist
+    \clist_gclear:N \g__sn_nodes_clist
   }
 }
-%    \end{macrocode}  
+%    \end{macrocode}
 % \end{macro}
+%
+% \begin{macro}{\SaveNode}
+% Command for saving a node outside a TikZ picture.
+%    \begin{macrocode}
+\DeclareDocumentCommand \SaveNode { o m }
+{
+  \group_begin:
+  \IfNoValueF {#1}
+  {
+    \keys_set:nn {tikzmark / save nodes}
+    {
+      file=false,
+      group=#1
+    }
+  }
+  \bool_if:NTF \l__sn_file_bool
+  {
+    \save_nodes_to_file:n {#2}
+  }
+  {
+    \tl_if_empty:NF \l__sn_group_tl
+    {
+      \save_nodes_to_list:Vn \l__sn_group_tl {#2}
+    }
+  }
+  \group_end:
+}
+%    \end{macrocode}
+% \end{macro}
 % \endgroup
 %    \begin{macrocode}
 \ExplSyntaxOff
@@ -2039,7 +2580,8 @@
 %
 % \begin{macrocode}
 }{%
-    \PackageError{tikzmark listings}{The listings package has not been loaded.}{}
+  \PackageError{tikzmark listings}%
+  {The listings package has not been loaded.}{}
 }
 %    \end{macrocode}
 % \iffalse
@@ -2046,7 +2588,767 @@
 %</listings>
 % \fi
 %
+% \subsection{AMS Math}
 %
+% This tikzmark library defines a routine that puts a pseudo-node (using \Verb+\tikzmark at box+) around all the pieces used in constructing the various math environments that the AMS Math package provides, such as \Verb+gather+ and \Verb+align+.
+% All of these (and their labels) work by putting various pieces into a box and then typesetting that box in the cells of an \Verb+halign+.
+% By using \Verb+\tikzmark at box+, this can be infiltrated to put nodes around each of those boxes as it is placed.
 %
+% \iffalse
+%<*ams>
+% \fi
+%    \begin{macrocode}
+\@ifpackageloaded{amsmath}{%
+%    \end{macrocode}
+%
+% \begin{macro}{tikzmarkmath}
+%
+% Defines an environment in which any AMS mathematical aligned environments get nodes around each piece of their contents.
+%
+% Start by saving the original \Verb+\boxz at + command. 
+%    \begin{macrocode}
+  \let\tikzmark at ams@boxz@=\boxz@
+%    \end{macrocode}
+%
+% We'll need a counter to keep track of the nodes.
+%    \begin{macrocode}
+  \newcounter{tikzmarkequation}
+%    \end{macrocode}
+%
+% The nodes will be labelled \Verb!<name>-<number>!.
+% By default the name is \Verb!equation! but this can be customised.
+%    \begin{macrocode}
+  \def\tikzmark at ams@name{equation}
+%    \end{macrocode}
+%
+% This is the substitute command.
+% I don't know if the \Verb=\ifmeasuring@= actually does anything, but it's here just in case at the moment.
+%    \begin{macrocode}
+  \def\tikzmark at boxz@{%
+    \ifmeasuring@
+    \tikzmark at ams@boxz@
+    \else
+    \stepcounter{tikzmarkequation}%
+    \tikzmark at box{\tikzmark at ams@name-\thetikzmarkequation}{\z@}%
+    \fi
+  }
+%    \end{macrocode}
+%
+% This is the environment that sets the node name and swaps out the box code.
+% At the end of the environment we swap back the code so that the commands can be used as standalone \Verb+\tikzmarkmath+ and \Verb+\endtikzmarkmath+ in occasions when it isn't appropriate to use an environment (for example, if it crosses sections, or if it is wanted to turn on this feature for an entire document).
+% At the end of the environment, the number of nodes is written out to the terminal and log file to make it easier to keep track.
+%    \begin{macrocode}
+  \newenvironment{tikzmarkmath}[1][equation]{%
+    \def\tikzmark at ams@name{#1}%
+    \setcounter{tikzmarkequation}{0}%
+    \let\boxz@=\tikzmark at boxz@
+  }{%
+    \let\boxz@=\tikzmark at ams@boxz@
+    \message{%
+      Tikzmark math environment
+      \tikzmark at ams@name\space had
+      \the\value{tikzmarkequation} nodes in it
+    }%
+  }
+%    \end{macrocode}
+% \end{macro}
+% \begin{macrocode}
+}{%
+  \PackageError{tikzmark AMS}%
+  {The amsmath package has not been loaded.}%
+  {}
+}
+%    \end{macrocode}
+% \iffalse
+%</ams>
+% \fi
+%
+% \iffalse
+%<*highlighting>
+% \fi
+%
+% \subsection{Highlighting}
+%
+% An early use of \Verb!\tikzmark! was to add highlighting to text by drawing over or under the text between two tikzmarks, for example the question \href{http://tex.stackexchange.com/q/46434/86}{How to "highlight" text/formulas with tikz?}.
+%
+% I was never totally happy with the overall mechanism, so didn't include it in the main tikzmark package.
+% Recently, I had occasion to revisit it and by using the new \LaTeX3 hook facility I got something that I was sufficiently happy with to add to the main package.
+%
+% The key idea is to hook into the \texttt{shipout/background} routine to insert the highlighting behind the text.
+% This allows us to draw the highlighting before the page is laid out and so is under the text.
+%
+% \LaTeX3 makes life just that little bit easier.
+%    \begin{macrocode}
+\ExplSyntaxOn
+%    \end{macrocode}
+%
+% Since the code that draws the highlighting will probably be very separate from the code that defines it, when storing the highlighting code then we want to expand the tikzmark full name.
+%    \begin{macrocode}
+\cs_new_protected_nopar:Npn \tikzmark_fix_name:Nn #1#2
+{
+  \tl_set:Nx #1 {\tikzmark at pp@name{#2}}
+}
+%    \end{macrocode}
+%
+% \begin{macro}{\StartHighlighting,\EndHighlighting,\Highlight}
+% These are the user interfaces for highlighting a section.
+% The first command inserts the drawing code into the relevant hook and places a tikzmark at the current location.
+% The second command indicates when the highlighting should stop.
+% The third is a short cut for highlighting its argument.
+%
+% These are commands rather than an environment to allow it to span, for example, different parts of an aligned equation.
+%    \begin{macrocode}
+\tl_new:N \g__tikzmark_highlighter_tl
+\tl_set:Nn \g__tikzmark_highlighter_tl {tikzmark~ highlighter~}
+\int_new:N \g__tikzmark_highlighter_int
+\tl_new:N \l__tikzmark_start_tl
+\tl_new:N \l__tikzmark_end_tl
+\tl_new:N \l__tikzmark_highlighter_name_tl
+\tl_new:N \l__tikzmark_tmpa_tl
+\tl_new:N \l__tikzmark_tmpb_tl
+\tl_new:N \l__tikzmark_tmpc_tl
+
+\cs_new_protected_nopar:Npn \tikzmark_bake_highlighter:N #1
+{
+  \tl_clear:N #1
+  \clist_map_inline:nn {direction,layer}
+  {
+    \tl_put_right:Nx #1 {
+      /tikz/highlighter/##1=\pgfkeysvalueof{/tikz/highlighter/##1},
+    }
+  }
+  \clist_map_inline:nn {
+    initial~ height,
+    initial~ depth,
+    initial~ offset,
+    final~ height,
+    final~ depth,
+    final~ offset,
+    left~ margin,
+    right~ margin,
+    top~ margin,
+    bottom~ margin,
+  }
+  {
+    \tl_put_right:Nx #1 {
+      /tikz/highlighter/##1=\dim_eval:n {\pgfkeysvalueof{/tikz/highlighter/##1}},
+    }
+  }
+}
+
+\cs_new_protected_nopar:Npn \tikzmark_start_highlighting:n #1
+{
+  \int_gincr:N \g__tikzmark_highlighter_int
+  \tl_set:Nx \l__tikzmark_highlighter_name_tl
+  {
+    \tl_use:N \g__tikzmark_highlighter_tl
+    \int_use:N \g__tikzmark_highlighter_int
+  }
+  \tl_set:Nn \l__tikzmark_tmpb_tl
+  {
+    every~ highlighter/.try,
+  }
+  \tikzmark_bake_highlighter:N \l__tikzmark_tmpc_tl
+  \tl_put_right:NV \l__tikzmark_tmpb_tl \l__tikzmark_tmpc_tl
+  \tl_put_right:Nn \l__tikzmark_tmpb_tl {#1}
+  \tikzmark_process_highlighting:VV
+  \l__tikzmark_tmpb_tl
+  \l__tikzmark_highlighter_name_tl
+  \tikzmark{highlight-start-\tl_use:N \l__tikzmark_highlighter_name_tl}
+}
+\cs_new_protected_nopar:Npn \tikzmark_end_highlighting:
+{
+  \tl_set:Nx \l__tikzmark_highlighter_name_tl
+  {
+    \tl_use:N \g__tikzmark_highlighter_tl
+    \int_use:N \g__tikzmark_highlighter_int
+  }
+  \tikzmark{highlight-end-\tl_use:N \l__tikzmark_highlighter_name_tl}
+}
+
+\NewDocumentCommand \StartHighlighting {O{}}
+{%
+  \tikzmark_start_highlighting:n {#1}
+}
+\NewDocumentCommand \StopHighlighting {}
+{%
+  \tikzmark_end_highlighting:
+}
+\NewDocumentCommand \Highlight {O{} m}
+{%
+  \tikzmark_start_highlighting:n {#1}
+  #2
+  \tikzmark_end_highlighting:
+}
+%    \end{macrocode}
+% \end{macro}
+%
+% The following code inserts the drawing command into the shipout hook.
+%    \begin{macrocode}
+%    \end{macrocode}
+% We need an ordinary colon, rather than a \LaTeX3 one
+%    \begin{macrocode}
+\tl_const:Nx \c__tikzmark_colon_tl
+{
+  \char_generate:nn {`:} {12}
+}
+
+\cs_generate_variant:Nn \hook_gput_next_code:nn {nV}
+%    \end{macrocode}
+% 
+%    \begin{macrocode}
+\cs_new_protected_nopar:Npn \tikzmark_highlight_or_shunt:nnnn #1#2#3#4
+{
+%    \end{macrocode}
+% First, test to check if the tikzmarks are actually defined yet,
+% if not then bail out.
+%    \begin{macrocode}
+  \bool_lazy_all:nT
+  {
+    {\tl_if_exist_p:c {save at pt@\tikzmark at pp@name{#2}}}
+    {\tl_if_exist_p:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#2}}}}
+    {\tl_if_exist_p:c {save at pt@\tikzmark at pp@name{#3}}}
+    {\tl_if_exist_p:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#3}}}}
+  }
+  {
+%    \end{macrocode}
+% Okay, so all the tikzmarks are defined. Now see if we're on the
+% right page.  Is our start tikzmark in the future?
+%    \begin{macrocode}
+    \int_compare:nTF
+    {
+      \tl_use:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#2}}}
+      >
+      \the\value{page}
+    }
+    {
+%    \end{macrocode}
+% It is, so we just punt our highlighting down the line
+%    \begin{macrocode}
+      \hook_gput_next_code:nn {#1} {
+        \tikzmark_highlight_or_shunt:nnnn {#1}{#2}{#3}{#4}
+      }
+    }
+    {
+%    \end{macrocode}
+% It isn't, so we have some highlighting to do.
+% We need to build our highlighting code.
+%    \begin{macrocode}
+      \tl_set:Nn \l__tikzmark_tmpa_tl {#4}
+%    \end{macrocode}
+% Is our starting tikzmark on \emph{this} page?
+%    \begin{macrocode}
+      \int_compare:nTF
+      {
+        \tl_use:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#2}}}
+        =
+        \the\value{page}
+      }
+      {
+%    \end{macrocode}
+% It is, so we use the starting tikzmark as our first coordinate.
+%    \begin{macrocode}
+        \tl_put_right:Nx \l__tikzmark_tmpa_tl
+        {
+          {
+            pic~ cs
+            \tl_use:N \c__tikzmark_colon_tl
+            #2
+          }
+        }
+      }
+      {
+%    \end{macrocode}
+% It isn't, so we use the north west corner of the page
+%    \begin{macrocode}
+        \tl_put_right:Nn \l__tikzmark_tmpa_tl
+        {
+          {
+            page.north~ west
+          }
+        }
+      }
+%    \end{macrocode}
+% Is our ending tikzmark on \emph{this} page?
+%    \begin{macrocode}
+      \int_compare:nTF
+      {
+        \tl_use:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#3}}}
+        =
+        \the\value{page}
+      }
+      {
+%    \end{macrocode}
+% It is, so we use the ending tikzmark as our second coordinate.
+%    \begin{macrocode}
+        \tl_put_right:Nx \l__tikzmark_tmpa_tl
+        {
+          {
+            pic~ cs
+            \tl_use:N \c__tikzmark_colon_tl
+            #3
+          }
+        }
+      }
+      {
+%    \end{macrocode}
+% It isn't, so we use the south east corner of the page, and
+% we have to shunt the code to the next page.
+%    \begin{macrocode}
+        \tl_put_right:Nn \l__tikzmark_tmpa_tl
+        {
+          {
+            page.south~ east
+          }
+        }
+        \hook_gput_next_code:nn {#1} {
+          \tikzmark_highlight_or_shunt:nnnn {#1}{#2}{#3}{#4}
+        }
+      }
+%    \end{macrocode}
+% We've built our highlighting code, now's time to execute it.
+%    \begin{macrocode}
+      \tl_use:N \l__tikzmark_tmpa_tl
+    }
+  }
+}
+%    \end{macrocode}
+% 
+%    \begin{macrocode}
+\cs_new_protected_nopar:Npn \tikzmark_process_highlighting:nn #1#2
+{
+  \pgfkeys{/tikz/highlighter/configuration/.activate~ family}
+  \pgfkeysfiltered{/tikz/.cd,highlighter/direction,highlighter/layer,#1}
+
+  \tikzmark_fix_name:Nn \l__tikzmark_start_tl {highlight-start-#2}
+  \tikzmark_fix_name:Nn \l__tikzmark_end_tl {highlight-end-#2}
+  \tl_set:Nx \l__tikzmark_tmpa_tl {\pgfkeysvalueof{/tikz/highlighter/direction}}
+  \tl_clear:N \l__tikzmark_tmpb_tl
+  \tl_clear:N \l__tikzmark_tmpc_tl
+  \tl_if_eq:NnTF \l__tikzmark_tmpa_tl {vertical}
+  {
+    \tl_put_right:Nn \l__tikzmark_tmpb_tl
+    {
+      \vl at draw
+    }
+  }
+  {
+    \tl_if_eq:NnTF \l__tikzmark_tmpa_tl {box}
+    {
+      \tl_put_right:Nn \l__tikzmark_tmpb_tl
+      {
+        \box at draw
+      }
+    }
+    {
+      \tl_put_right:Nn \l__tikzmark_tmpb_tl
+      {
+        \hl at draw
+      }
+    }
+  }
+  
+  \tl_put_right:Nn \l__tikzmark_tmpb_tl
+  {
+    {tikzmark~ clear~ ixes,#1}
+  }
+
+  \tl_set:Nx \l__tikzmark_tmpa_tl {\pgfkeysvalueof{/tikz/highlighter/layer}}
+  \tl_set:Nn \l__tikzmark_tmpc_tl
+  {
+    \tikzmark_highlight_or_shunt:nnnn
+  }
+  \tl_if_eq:NnTF \l__tikzmark_tmpa_tl {foreground}
+  {
+    \tl_put_right:Nn \l__tikzmark_tmpc_tl {{shipout/foreground}}
+  }
+  {
+    \tl_put_right:Nn \l__tikzmark_tmpc_tl {{shipout/background}}
+  }
+
+  \tikzmark_tl_put_right_braced:NV \l__tikzmark_tmpc_tl \l__tikzmark_start_tl
+  \tikzmark_tl_put_right_braced:NV \l__tikzmark_tmpc_tl \l__tikzmark_end_tl
+  \tikzmark_tl_put_right_braced:NV \l__tikzmark_tmpc_tl \l__tikzmark_tmpb_tl
+ 
+  \tl_if_eq:NnTF \l__tikzmark_tmpa_tl {foreground}
+  {
+    \hook_gput_next_code:nV {shipout/foreground} \l__tikzmark_tmpc_tl
+  }
+  {
+    \hook_gput_next_code:nV {shipout/background} \l__tikzmark_tmpc_tl
+  }
+}
+\cs_generate_variant:Nn  \tikzmark_process_highlighting:nn {nV,VV}
+\ExplSyntaxOff
+%    \end{macrocode}
+%
+% The command that draws the horizontal highligher or fader.
+% This fills a shape determined by two coordinates assumed to be (in effect) on the baseline of the start and end of the region to be highlighted.
+%    \begin{macrocode}
+\def\hl at draw#1#2#3{%
+  \pgfkeys{/tikz/highlighter/configuration/.activate family}
+  \pgfkeysfiltered{/tikz/.cd,highlighter/direction,highlighter/layer,#1}
+  \begin{tikzpicture}[
+    remember picture,
+    overlay,
+    highlight picture action,
+    #1,
+  ]%
+%
+  \page at node
+%
+  \tikz at scan@one at point\pgfutil at firstofone(#2)\relax
+  \pgf at ya=\pgf at y
+  \tikz at scan@one at point\pgfutil at firstofone(#3)\relax
+  \pgf at yb=\pgf at y
+%
+  \ifdim\pgf at ya=\pgf at yb
+%
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial offset},
+  \pgfkeysvalueof{/tikz/highlighter/initial height})
+  coordinate (start);
+%
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final depth})
+  coordinate (end);
+%
+  \path[
+    highlight action,
+    #1
+  ] (start) rectangle (end);
+%
+  \else
+%
+  \path (page.east)
+  ++(\pgfkeysvalueof{/tikz/highlighter/right margin},0pt)
+  coordinate (east);
+%
+  \path (page.west)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/left margin},0pt)
+  coordinate (west);
+%
+  \pgfmathsetlength\pgf at x{%
+    \pgfkeysvalueof{/tikz/highlighter/initial height}%
+  }%
+%
+  \advance\pgf at yb by \pgf at x\relax
+%
+  \pgfmathsetlength\pgf at x{%
+    -1*\pgfkeysvalueof{/tikz/highlighter/final depth}%
+  }%
+%
+  \advance\pgf at ya by \pgf at x\relax
+%
+  \ifdim\pgf at yb>\pgf at ya
+%
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial offset},
+  \pgfkeysvalueof{/tikz/highlighter/initial height}) 
+  coordinate (start);
+%
+  \path (#2)
+  ++(0pt,-1*\pgfkeysvalueof{/tikz/highlighter/final depth}) 
+  coordinate (end);
+%
+  \path[
+    highlight action,
+    #1
+  ] (start) rectangle (end -| east);
+%
+  \path (#3)
+  ++(0pt,\pgfkeysvalueof{/tikz/highlighter/initial height}) 
+  coordinate (start);
+%
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final depth}) 
+  coordinate (end);
+%
+  \path[
+    highlight action,
+    #1
+  ] (start -| west) rectangle (end);
+%
+  \else
+%
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial offset},
+  \pgfkeysvalueof{/tikz/highlighter/initial height}) 
+  coordinate (tl);
+%
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/initial depth}) 
+  coordinate (start);
+%
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final depth}) 
+  coordinate (end);
+%
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final offset},
+  \pgfkeysvalueof{/tikz/highlighter/final height}) 
+  coordinate (mr);
+%
+  \path[
+    highlight action,
+    #1
+  ] (start) -- (tl) -- (tl -| east) -- (mr -| east) -- (mr) --
+  (end) -- (end -| west) -- (start -| west) -- cycle;
+%
+  \fi
+  \fi
+  \end{tikzpicture}%
+}
+%    \end{macrocode}
+%
+% This one draws a box.
+%    \begin{macrocode}
+\def\box at draw#1#2#3{%
+  \pgfkeys{/tikz/highlighter/configuration/.activate family}
+  \pgfkeysfiltered{/tikz/.cd,highlighter/direction,highlighter/layer,#1}
+  \begin{tikzpicture}[
+    remember picture,
+    overlay,
+    highlight picture action,
+    #1,
+  ]%
+%
+  \tikz at scan@one at point\pgfutil at firstofone(#2)\relax
+  \pgf at xa=\pgf at x
+  \tikz at scan@one at point\pgfutil at firstofone(#3)\relax
+  \pgf at xb=\pgf at x
+%
+  \def\tkmk at high@bscale{1}%
+  \ifdim\pgf at xa>\pgf at xb
+  \def\tkmk at high@bscale{-1}%
+  \fi
+%
+  \path (#2)
+  ++({\tkmk at high@bscale*(-1)*\pgfkeysvalueof{/tikz/highlighter/initial offset}},
+  \pgfkeysvalueof{/tikz/highlighter/initial height})
+  coordinate (start);
+%
+  \path (#3)
+  ++(\tkmk at high@bscale*\pgfkeysvalueof{/tikz/highlighter/final offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final depth})
+  coordinate (end);
+%
+  \path[
+    highlight action,
+    #1
+  ] (start) rectangle (end);
+  \end{tikzpicture}%
+}
+%    \end{macrocode}
+%
+% In this one the region is defined vertically.
+%    \begin{macrocode}
+\def\vl at draw#1#2#3{%
+  \pgfkeys{/tikz/highlighter/configuration/.activate family}
+  \pgfkeysfiltered{/tikz/.cd,highlighter/direction,highlighter/layer,#1}
+  \begin{tikzpicture}[
+    remember picture,
+    overlay,
+    highlight picture action,
+    #1,
+  ]%
+%
+  \tikz at scan@one at point\pgfutil at firstofone(#2)\relax
+  \pgf at ya=\pgf at y
+  \pgf at xa=\pgf at x
+  \tikz at scan@one at point\pgfutil at firstofone(#3)\relax
+  \pgf at yb=\pgf at y
+  \pgf at xb=\pgf at x
+%
+  \pgfmathsetlength\pgf at y{%
+    \pgfkeysvalueof{/tikz/highlighter/initial offset}%
+  }%
+  \advance\pgf at yb by \pgf at y
+  \pgfmathsetlength\pgf at y{%
+    -1*\pgfkeysvalueof{/tikz/highlighter/final offset}%
+  }%
+  \advance\pgf at ya by \pgf at y
+%
+  \ifdim\pgf at yb>\pgf at ya
+%
+  \ifdim\pgf at xa>\pgf at xb
+%
+  \path (#2)
+  ++(\pgfkeysvalueof{/tikz/highlighter/initial height},
+  \pgfkeysvalueof{/tikz/highlighter/initial offset})
+  coordinate (start);
+%
+  \path (#3)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/final depth},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final offset})
+  coordinate (end);
+%  
+  \else
+%
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial depth},
+  \pgfkeysvalueof{/tikz/highlighter/initial offset})
+  coordinate (start);
+%
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final height},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final offset})
+  coordinate (end);
+%  
+  \fi
+%
+  \path[
+    highlight action,
+    #1
+  ] (start) rectangle (end);
+%
+  \else
+%
+  \path (#2)
+  ++(\pgfkeysvalueof{/tikz/highlighter/initial height},0)
+  coordinate (tr);
+%
+  \path (#2)
+  ++(0,\pgfkeysvalueof{/tikz/highlighter/initial offset})
+  coordinate (start);
+%
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial depth},0)
+  coordinate (tl);
+%
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final height},0)
+  coordinate (br);
+%
+  \path (#3)
+  ++(0,-1*\pgfkeysvalueof{/tikz/highlighter/final offset})
+  coordinate (end);
+%
+  \path (#3)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/final depth},0)
+  coordinate (bl);
+%
+  \tikz at scan@one at point\pgfutil at firstofone(#2)\relax
+  \pgf at xa=\pgf at x
+  \tikz at scan@one at point\pgfutil at firstofone(#3)\relax
+  \pgf at xb=\pgf at x
+%
+  \ifdim\pgf at xa<\pgf at xb
+%
+  \path[
+    highlight action,
+    #1
+  ] (tl) |- (start) -| (tr) -| (br) |- (end) -| (bl) -| cycle;
+%
+  \else
+%
+  \path[
+    highlight action,
+    #1
+  ] (tl) |- (start) -| (tr) |- (br) |- (end) -| (bl) |- cycle;
+%
+  \fi
+%
+  \fi
+  \end{tikzpicture}
+}
+%    \end{macrocode}
+%
+% These set various options.
+%    \begin{macrocode}
+\tikzset{%
+  /tikz/highlighter/.is family,
+  /tikz/highlighter/.unknown/.code={%
+    \let\tk at searchname=\pgfkeyscurrentname%
+    \pgfkeysalso{%
+      /tikz/\tk at searchname=#1
+    }
+  },
+  every highlight path/.style={
+    fill=yellow!50,
+    rounded corners,
+  },
+  every foreground highlight path/.style={
+    fill opacity=.5,
+  },
+  highlight picture action/.style={
+    every highlight picture/.try,
+    every \pgfkeysvalueof{/tikz/highlighter/direction} highlight picture/.try,
+    every \pgfkeysvalueof{/tikz/highlighter/layer} highlight picture/.try,
+  },
+  highlight action/.style={
+    every highlight path/.try,
+    every \pgfkeysvalueof{/tikz/highlighter/direction} highlight path/.try,
+    every \pgfkeysvalueof{/tikz/highlighter/layer} highlight path/.try,
+    highlight path/.try,
+    \pgfkeysvalueof{/tikz/highlighter/direction} highlight path/.try,
+    \pgfkeysvalueof{/tikz/highlighter/layer} highlight path/.try,
+  },
+  /tikz/highlighter/.cd,
+  direction/.initial=horizontal,
+  layer/.initial=background,
+  direction/.default=horizontal,
+  layer/.default=background,
+  initial height/.initial=\baselineskip,
+  initial depth/.initial=.5ex,
+  initial offset/.initial=.5\baselineskip,
+  final height/.initial=\baselineskip,
+  final depth/.initial=.5ex,
+  final offset/.initial=.5\baselineskip,
+  left margin/.initial=.5\baselineskip,
+  right margin/.initial=.5\baselineskip,
+  top margin/.initial=.5\baselineskip,
+  bottom margin/.initial=-.5\baselineskip,
+  height/.style={
+    initial height=#1,
+    final height=#1
+  },
+  depth/.style={
+    initial depth=#1,
+    final depth=#1
+  },
+  offset/.style={
+    initial offset=#1,
+    final offset=#1
+  },
+  margin/.style={
+    left margin=#1,
+    right margin=#1,
+    top margin=#1,
+    bottom margin=#1,
+  },
+  /tikz/highlighter/configuration/.is family,
+  /tikz/highlighter/direction/.belongs to family=/tikz/highlighter/configuration,
+  /tikz/highlighter/layer/.belongs to family=/tikz/highlighter/configuration,
+}
+%    \end{macrocode}
+%
+%
+%    \begin{macrocode}
+\def\page at node{
+  \path (current page.north west)
+  ++(\hoffset + 1in + \oddsidemargin + \leftskip,
+  -\voffset - 1in - \topmargin - \headheight - \headsep)
+  node[
+    minimum width=\textwidth - \leftskip - \rightskip,
+    minimum height=\textheight,
+    anchor=north west,
+    line width=0mm,
+    inner sep=0pt,
+    outer sep=0pt,
+  ] (page) {};
+}
+%    \end{macrocode}
+%
+%
+%
+% \iffalse
+%</highlighting>
+% \fi
+%
 % \Finale
 \endinput

Modified: trunk/Master/texmf-dist/tex/latex/tikzmark/tikzlibrarytikzmark.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/tikzmark/tikzlibrarytikzmark.code.tex	2022-10-26 19:59:14 UTC (rev 64818)
+++ trunk/Master/texmf-dist/tex/latex/tikzmark/tikzlibrarytikzmark.code.tex	2022-10-26 19:59:50 UTC (rev 64819)
@@ -12,9 +12,10 @@
 %% See http://www.latex-project.org/lppl.txt
 %% ----------------------------------------------------------------
 %% 
+
 \ProvidesFile{tikzlibrarytikzmark.code.tex}[%
-  2021/02/16
-  v1.10
+  2022/08/24
+  v1.15
   TikZ library for marking positions in a document]
 \RequirePackage{expl3, l3keys2e, xparse}
 \tikzset{%
@@ -127,6 +128,61 @@
   },
   tikzmark prefix/.initial=,%
   tikzmark suffix/.initial=,%
+  tikzmark clear ixes/.style={
+    tikzmark prefix={},
+    tikzmark suffix={}
+  },
+  scope anchor location/.initial={(0,0)},
+  scope anchor location/.default=@auto,
+  pic anchor/.style={
+    scope anchor location={#1},
+    next pic/.append style={
+      adjust scope position,
+    }
+  },
+  scope anchor/.style={
+    scope anchor location={#1},
+    adjust scope position,
+  },
+  adjust scope position/.code={%
+    \pgfutil at ifundefined{tikz at fig@name}%
+    {\let\tikz at fig@name=\pgfutil at empty}{}%
+    \tikz at resetexpandcount%
+    \tikz at fig@mustbenamed
+    \pgfkeysgetvalue{/tikz/scope anchor location}\tkzmk at anchor
+    \ifx\tkzmk at anchor\tikz at auto@text
+    \tikzset{local bounding box/.expanded=\tikz at fig@name}%
+    \def\tkzmk at anchor{(\tikz at fig@name.\tikz at anchor)}%
+    \fi
+    \tikz at scan@one at point
+    \pgfutil at firstofone(pic cs:\tikz at fig@name-origin)\relax
+    \pgf at xa=\pgf at x
+    \pgf at ya=\pgf at y
+    \tikz at scan@one at point
+    \pgfutil at firstofone(pic cs:\tikz at fig@name-anchor)\relax
+    \advance\pgf at xa by -\pgf at x
+    \advance\pgf at ya by -\pgf at y
+    \tikzset{
+      shift={(\the\pgf at xa,\the\pgf at ya)},
+      execute at end scope={%
+        \tikzmark{\tikz at fig@name-origin}{(0,0)}%
+        \tikzmark{\tikz at fig@name-anchor}{\tkzmk at anchor}%
+      }
+    }
+  },
+  every pic/.append style={
+    next pic/.try,
+    next pic/.style={}
+  },
+  save pic bounding box/.code={
+    \tikz at fig@mustbenamed
+    \tikzset{local bounding box/.expanded=\tikz at fig@name}
+  },
+  surround pic/.style={
+    next pic/.append style={
+      save pic bounding box
+    }
+  },
 }
 \def\tikzmark at pp@name#1{%
   \csname pgfk@/tikz/tikzmark prefix\endcsname%
@@ -141,9 +197,20 @@
 \def\savepicturepage#1#2{%
   \expandafter\gdef\csname save at pg@#1\endcsname{#2}%
 }
+\def\@tikzmarkalias#1#2{%
+  \@ifundefined{save at pt@#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}%
+    \protected at write\pgfutil at auxout{}{%
+      \string\savepointas%
+      {#1}{\csname save at pt@#2\endcsname}%
+      \expandafter\expandafter\expandafter
+      \@gobble\csname save at pt@#2 at offset\endcsname
+    }%
+  }%
+}
 \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}%
+  \@tikzmarkalias{\tikzmark at pp@name{#1}}{\tikzmark at pp@name{#2}}%
 }
 \def\tmk at labeldef#1,#2\@nil{%
   \edef\tmk at label{\tikzmark at pp@name{#1}}%
@@ -157,7 +224,8 @@
     \tmk at labeldef#1,(0pt,0pt)\@nil
   \fi
   \@ifundefined{save at pt@\tmk at label}{%
-    \tikz at scan@one at point\pgfutil at firstofone\tmk at def
+    \expandafter\tikz at scan@one at point
+    \expandafter\pgfutil at firstofone\tmk at def\relax
   }{%
     \pgfsys at getposition{\csname save at pt@\tmk at label\endcsname}%
     \save at orig@pic%
@@ -205,7 +273,9 @@
 }
 \def\tikzmark at inside#1#2{%
   \tikzset{remember picture}%
+  \tikz at resetexpandcount%
   \tikz at scan@one at point\pgfutil at firstofone#2\relax
+  \pgf at pos@transform{\pgf at x}{\pgf at y}%
   \protected at write\pgfutil at auxout{}{%
     \string\savepointas%
     {\tikzmark at pp@name{#1}}{\pgfpictureid}{\the\pgf at x}{\the\pgf at y}}%
@@ -224,18 +294,22 @@
   \tikzmark at next%
 }
 \newcommand\pgfmark[1]{%
-    \bgroup
-    \global\advance\pgf at picture@serial at count by1\relax%
-    \edef\pgfpictureid{pgfid\the\pgf at picture@serial at count}%
-      \pgfsys at markposition{\pgfpictureid}%
-    \edef\pgf at temp{%
-      \noexpand\write\noexpand\pgfutil at auxout{%
-        \string\savepicturepage{\pgfpictureid}{\noexpand\arabic{page}}}}%
-    \pgf at temp
-    \protected at write\pgfutil at auxout{}{%
-      \string\savepointas{\tikzmark at pp@name{#1}}{\pgfpictureid}{0pt}{0pt}}%
-    \egroup
-  }
+  \bgroup
+  \global\advance\pgf at picture@serial at count by1\relax%
+  \edef\pgfpictureid{pgfid\the\pgf at picture@serial at count}%
+  \pgfsys at markposition{\pgfpictureid}%
+  \edef\pgf at temp{%
+    \noexpand\write\noexpand\pgfutil at auxout{%
+      \string\savepicturepage
+      {\pgfpictureid}{\noexpand\arabic{page}}%
+    }%
+  }%
+  \pgf at temp
+  \protected at write\pgfutil at auxout{}{%
+    \string\savepointas
+    {\tikzmark at pp@name{#1}}{\pgfpictureid}{0pt}{0pt}}%
+  \egroup
+}
 \@ifclassloaded{beamer}{
   \renewcommand<>{\tikzmark at outside}[2][]{%
     \only#3{\beameroriginal{\tikzmark at outside}[{#1}]{#2}}%
@@ -272,7 +346,9 @@
   \@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}{%
+    \@ifundefined{save at pg@%
+      \csname save at pt@\tikzmark at pp@name{#1}\endcsname%
+    }{%
       \tikzmark at false
     }{%
       \ifnum\csname save at pg@%
@@ -290,7 +366,9 @@
   \@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}{%
+    \@ifundefined{save at pg@%
+      \csname save at pt@\tikzmark at pp@name{#1}\endcsname%
+    }{%
       \tikzmark at false
     }{%
       \ifnum\csname save at pg@%
@@ -308,8 +386,7 @@
   \begingroup
   \pgfmark{#2}%
   \setbox\pgfnodeparttextbox=\hbox\bgroup #3\egroup
-  \def\tikz at fig@name{#2}%
-  \tikzset{every subnode/.try,#1}%
+  \tikzset{every subnode/.try,#1,name=#2}%
   \pgfpointorigin
   \tikz at scan@one at point\pgfutil at firstofone(pic cs:#2)\relax
   \advance\pgf at x by .5\wd\pgfnodeparttextbox
@@ -329,7 +406,8 @@
       \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{%
+    \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
@@ -336,17 +414,22 @@
     \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}%
+    \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}%
+      \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
+      \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}%
+    \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
@@ -369,31 +452,34 @@
   \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}%
+  \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}%
+  \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}%
+  \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
-  \pgfutil at ifundefined{pgf at sh@ns@#2}{%
-    \pgfnodealias{#2}{#2-t}%
-    \tikzmarkalias{#2}{#2-t}%
+  \pgfutil at ifundefined{pgf at sh@ns@\tikz at pp@name{#2}}{%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-t}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
   }{}%
   \else
-    \pgfnodealias{#2}{#2-d}%
-    \tikzmarkalias{#2}{#2-d}%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-d}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-d}}%
   \fi
   \else
-    \pgfnodealias{#2}{#2-t}%
-    \tikzmarkalias{#2}{#2-t}%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-t}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
   \fi
   \else
-    \pgfnodealias{#2}{#2-s}%
-    \tikzmarkalias{#2}{#2-s}%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-s}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-s}}%
   \fi
   \else
-    \pgfnodealias{#2}{#2-ss}%
-    \tikzmarkalias{#2}{#2-ss}%
+    \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-ss}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-ss}}%
   \fi
   \else
     \subnode@{#1}{#2}{#3}%
@@ -436,56 +522,125 @@
   \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}%
+  \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}%
+  \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}%
+  \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
   \pgfutil at ifundefined{pgf at sh@ns@\tikz at pp@name{#2}}{%
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-t}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
   }{}%
   \else
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-d}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-d}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-d}}%
   \fi
   \else
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-t}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-t}}%
   \fi
   \else
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-s}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-s}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-s}}%
   \fi
   \else
     \pgfnodealias{\tikz at pp@name{#2}}{\tikz at pp@name{#2-ss}}%
-    \tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-ss}}%
+    \@tikzmarkalias{\tikzmark at pp@name{#2}}{\tikzmark at pp@name{#2-ss}}%
   \fi
   \else
     \tikzmarknode@{#1}{#2}{#3}%
   \fi
 }
+\def\tikzmark at box#1#2{%
+  \begingroup
+  \pgfmark{#1}%
+  \let\pgfnodeparttextbox=#2%
+  \edef\pgfpictureid{pgfid\the\pgf at picture@serial at count}%
+  \def\tikz at fig@name{#1}%
+  \pgfpointorigin
+  \advance\pgf at x by .5\wd\pgfnodeparttextbox
+  \advance\pgf at y by .5\ht\pgfnodeparttextbox
+  \advance\pgf at y by -.5\dp\pgfnodeparttextbox
+  \pgftransformshift{}%
+  \setbox\@tempboxa=\hbox\bgroup
+  {%
+    \tikzset{
+      inner sep=0pt,
+      minimum size=0pt,
+      outer sep=0pt,
+      anchor=base
+    }%
+    \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
+  \endgroup
+  \box#2%
+}
 \def\usetikzmarklibrary{%
   \pgfutil at ifnextchar[{\use at tikzmarklibrary}{\use@@tikzmarklibrary}%
   }%}
 \def\use at tikzmarklibrary[#1]{\use@@tikzmarklibrary{#1}}
 \def\use@@tikzmarklibrary#1{%
-  \edef\pgf at list{#1}%
-  \pgfutil at for\pgf at temp:=\pgf at list\do{%
-    \expandafter\pgfkeys at spdef\expandafter\pgf at temp\expandafter{\pgf at temp}%
+    \edef\pgf at list{#1}%
+    \pgfutil at for\pgf at temp:=\pgf at list\do{%
+      \expandafter\pgfkeys at spdef
+      \expandafter\pgf at temp\expandafter{\pgf at temp}%
     \ifx\pgf at temp\pgfutil at empty
     \else
-      \expandafter\ifx\csname tikzmark at library@\pgf at temp @loaded\endcsname\relax%
+      \expandafter\ifx
+      \csname tikzmark at library@\pgf at temp @loaded\endcsname\relax%
       \expandafter\global\expandafter\let%
-      \csname tikzmark at library@\pgf at temp @loaded\endcsname=\pgfutil at empty%
-      \expandafter\edef\csname tikzmark at library@#1 at atcode\endcsname{\the\catcode`\@}
-      \expandafter\edef\csname tikzmark at library@#1 at barcode\endcsname{\the\catcode`\|}
+      \csname tikzmark at library@\pgf at temp @loaded\endcsname
+      =\pgfutil at empty%
+      \expandafter\edef
+      \csname tikzmark at library@#1 at atcode\endcsname{\the\catcode`\@}
+      \expandafter\edef
+      \csname tikzmark at library@#1 at barcode\endcsname{\the\catcode`\|}
       \catcode`\@=11
       \catcode`\|=12
       \pgfutil at InputIfFileExists{tikzmarklibrary\pgf at temp.code.tex}{}{
-          \PackageError{tikzmark}{I did not find the tikzmark extras library '\pgf at temp'.}{}
-        }%
+        \PackageError{tikzmark}{
+          I did not find the tikzmark extras library '\pgf at temp'.}{}
+      }%
       \catcode`\@=\csname tikzmark at library@#1 at atcode\endcsname
       \catcode`\|=\csname tikzmark at library@#1 at barcode\endcsname
       \fi%
@@ -492,8 +647,13 @@
     \fi
   }%
 }
-
 \ExplSyntaxOn
+\cs_new_protected:Nn \tikzmark_tl_put_right_braced:Nn
+ {
+  \tl_put_right:Nn #1 { { #2 } }
+ }
+\cs_generate_variant:Nn \tikzmark_tl_put_right_braced:Nn { NV, cV, cv, Nx, cx }
+\tl_new:N \g__sn_output_tl
 \prop_new:N \g__sn_prop
 \tl_new:N \l__sn_tmpa_tl
 \tl_new:N \l__sn_tmpb_tl
@@ -500,10 +660,15 @@
 \tl_new:N \l__open_bracket_tl
 \tl_set:Nn  \l__open_bracket_tl {[} %]
 \tl_new:N \l__sn_group_tl
-\clist_new:N \l__sn_nodes_clist
+\clist_new:N \g__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
+\bool_gset_true:N \g__sn_preamble_bool
+\keys_define:nn {tikzmark / save nodes}
+{
+  file .bool_set:N = \l__sn_file_bool,
+  group  .tl_set:N = \l__sn_group_tl,
+}
 \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
@@ -556,67 +721,88 @@
 \makeatother
 \cs_generate_variant:Nn \tikz_scan_point:n {V}
 \cs_generate_variant:Nn \tikz_scan_point:NNn {NNV}
-\cs_new_nopar:Npn \save_nodes:Nn #1#2
+\cs_new_nopar:Npn \__sn_process_node:n #1
 {
+  \group_begin:
   \tl_clear:N \l__sn_tmpa_tl
-  \tikz_scan_point:NNn \l__sn_x_dim \l__sn_y_dim {(current~ bounding~ box.center)}
+  \tikz_scan_point:NNn \l__sn_x_dim \l__sn_y_dim
+  {(current~ bounding~ box.center)}
   \dim_set:Nn \l__sn_x_dim {-\l__sn_x_dim}
   \dim_set:Nn \l__sn_y_dim {-\l__sn_y_dim}
   \tl_set:Nx \l__sn_centre_tl {
     {1}{0}{0}{1}{\dim_use:N \l__sn_x_dim}{\dim_use:N \l__sn_y_dim}
   }
-  \clist_map_inline:nn {#2}
+  \tl_if_exist:cT {pgf at sh@ns@#1}
   {
-    \tl_if_exist:cT {pgf at sh@ns@##1}
+    \clist_map_inline:nn {ns,np,ma,pi}
     {
-      \clist_map_inline:nn {ns,np,ma,pi}
+      \tl_put_right:Nn \l__sn_tmpa_tl
       {
-        \tl_put_right:Nn \l__sn_tmpa_tl
-        {
-          \tl_gset:cn {pgf at sh@####1@ \tikz_set_node_name:n{##1} }
+        \tl_gset:cn {pgf at sh@##1@ \tikz_set_node_name:n{#1} }
+      }
+      \tl_if_exist:cTF {pgf at sh@##1@#1}
+      {
+        \tl_put_right:Nx \l__sn_tmpa_tl {
+          {\exp_not:v {pgf at sh@##1@ \tikz_set_node_name:n {#1}}}
         }
-        \tl_if_exist:cTF {pgf at sh@####1@##1}
-        {
-          \tl_put_right:Nx \l__sn_tmpa_tl {
-            {\exp_not:v {pgf at sh@####1@ \tikz_set_node_name:n {##1}}}
-          }
-        }
-        {
-          \tl_put_right:Nx \l__sn_tmpa_tl {{}}
-        }
       }
-      \tl_put_right:Nn \l__sn_tmpa_tl
       {
-        \tl_gset:cn {pgf at sh@nt@ \tikz_set_node_name:n{##1} }
+        \tl_put_right:Nx \l__sn_tmpa_tl {{}}
       }
-      \compose_transformations:NVv \l__sn_tmpb_tl \l__sn_centre_tl {pgf at sh@nt@##1}
-      \tl_put_right:Nx \l__sn_tmpa_tl {{\exp_not:V \l__sn_tmpb_tl}}
-      \tl_put_right:Nn \l__sn_tmpa_tl {
-        \transform_node:Nn \l__sn_transformation_tl {
-          \tikz_set_node_name:n{##1}
-        }
+    }
+    \tl_put_right:Nn \l__sn_tmpa_tl
+    {
+      \tl_gset:cn {pgf at sh@nt@ \tikz_set_node_name:n{#1} }
+    }
+    \compose_transformations:NVv
+    \l__sn_tmpb_tl \l__sn_centre_tl {pgf at sh@nt@#1}
+    \tl_put_right:Nx \l__sn_tmpa_tl {{\exp_not:V \l__sn_tmpb_tl}}
+    \tl_put_right:Nn \l__sn_tmpa_tl {
+      \transform_node:Nn \l__sn_transformation_tl {
+        \tikz_set_node_name:n{#1}
       }
     }
   }
-  \tl_set_eq:NN #1 \l__sn_tmpa_tl
+  \tl_gset_eq:NN \g__sn_output_tl \l__sn_tmpa_tl
+  \group_end:
 }
+\cs_new_protected_nopar:Npn \process_node:Nn #1#2
+{
+  \__sn_process_node:n {#2}
+  \tl_set_eq:NN #1 \g__sn_output_tl
+  \tl_gclear:N \g__sn_output_tl
+}
+\cs_new_protected_nopar:Npn \process_gnode:Nn #1#2
+{
+  \__sn_process_node:n {#2}
+  \tl_gset_eq:NN #1 \g__sn_output_tl
+  \tl_gclear:N \g__sn_output_tl
+}
 \cs_new_nopar:Npn \save_nodes_to_list:nn #1#2
 {
-  \save_nodes:Nn \l__sn_tmpa_tl {#2}
+  \tl_clear:N \l__sn_tmpa_tl
+  \clist_map_inline:nn {#2}
+  {
+    \process_node:Nn \l__sn_tmpb_tl {##1}
+    \tl_put_right:NV \l__sn_tmpa_tl \l__sn_tmpb_tl
+  }
   \prop_gput:NnV \g__sn_prop {#1} \l__sn_tmpa_tl
 }
+\cs_generate_variant:Nn \iow_now:Nn {NV}
 \cs_new_nopar:Npn \save_nodes_to_file:n #1
 {
-  \save_nodes:Nn \l__sn_tmpa_tl {#1}
   \sn_open_stream:
-  \iow_now:Nx \g__sn_stream
+  \clist_map_inline:nn {#1}
   {
-    \iow_newline:
-    \exp_not:V \l__sn_tmpa_tl
-    \iow_newline:
+    \process_node:Nn \l__sn_tmpa_tl {##1}
+    \iow_now:Nx \g__sn_stream
+    {
+      \iow_newline:
+      \exp_not:V \l__sn_tmpa_tl
+    }
   }
 }
-\cs_generate_variant:Nn \save_nodes_to_list:nn {VV}
+\cs_generate_variant:Nn \save_nodes_to_list:nn {VV, Vn}
 \cs_generate_variant:Nn \save_nodes_to_file:n {V}
 \cs_new_nopar:Npn \restore_nodes_from_list:n #1
 {
@@ -638,6 +824,7 @@
     \msg_warning:nnn {tikzmark} {no file} {#1}
   }
 }
+\cs_generate_variant:Nn \restore_nodes_from_file:n {x}
 \AtBeginDocument{\bool_gset_false:N \g__sn_preamble_bool}
 
 \cs_new_nopar:Npn \compose_transformations:Nnn #1#2#3
@@ -698,7 +885,8 @@
     }
   }
 }
-\cs_generate_variant:Nn \compose_transformations:Nnn {cVv,NVv,NVn,NvV,NnV}
+\cs_generate_variant:Nn \compose_transformations:Nnn
+{cVv,NVv,NVn,NvV,NnV}
 \cs_new_nopar:Npn \transform_node:Nn #1#2
 {
   \compose_transformations:cVv {pgf at sh@nt@#2} #1 {pgf at sh@nt@#2}
@@ -708,8 +896,12 @@
   \tl_set_eq:Nc \l__sn_transformation_tl {pgf at sh@nt@#1}
   \tikz_scan_point:NNn \l__sn_x_dim \l__sn_y_dim {(#1.center)}
 
-  \dim_set:Nn \l__sn_x_dim {\l__sn_x_dim - \tl_item:cn {pgf at sh@nt@#1}{5}}
-  \dim_set:Nn \l__sn_y_dim {\l__sn_y_dim - \tl_item:cn {pgf at sh@nt@#1}{6}}
+  \dim_set:Nn \l__sn_x_dim {
+    \l__sn_x_dim - \tl_item:cn {pgf at sh@nt@#1}{5}
+  }
+  \dim_set:Nn \l__sn_y_dim {
+    \l__sn_y_dim - \tl_item:cn {pgf at sh@nt@#1}{6}
+  }
 
   \compose_transformations:NnV  \l__sn_transformation_tl {
     {1}{0}{0}{1}{\dim_use:N \l__sn_x_dim}{\dim_use:N \l__sn_y_dim}
@@ -746,18 +938,25 @@
     }
   },
   save~ node/.code={
-    \tikz_fig_must_be_named:
-    \pgfkeysalso{append~ after~ command={
-        \pgfextra{
-          \clist_gput_right:Nv \l__sn_nodes_clist {tikz at last@fig at name}
+    \tl_if_eq:nnTF {#1} {\pgfkeysnovalue}
+    {
+      \tikz_fig_must_be_named:
+      \pgfkeysalso{
+        append~ after~ command={
+          \pgfextra{
+            \clist_gput_right:Nv \g__sn_nodes_clist {tikz at last@fig at name}
+          }
         }
       }
     }
+    {
+      \clist_gput_right:Nn \g__sn_nodes_clist {#1}
+    }
   },
   restore~ nodes~ from~ file/.code={
     \bool_if:NTF \g__sn_preamble_bool
     {
-      \restore_nodes_from_file:n {#1}
+      \restore_nodes_from_file:x {#1}
     }
     {
       \tikz_fig_must_be_named:
@@ -764,7 +963,7 @@
       \pgfkeysalso{append~ after~ command={
           \pgfextra{
             \scope
-            \split_argument:NNn \tikzset \restore_nodes_from_file:n {#1}
+            \split_argument:NNn \tikzset \restore_nodes_from_file:x {#1}
             \endscope
           }
         }
@@ -803,21 +1002,44 @@
 }
 \cs_new_nopar:Npn \maybe_save_nodes:
 {
-  \clist_if_empty:NF \l__sn_nodes_clist
+  \clist_if_empty:NF \g__sn_nodes_clist
   {
     \bool_if:NTF \l__sn_file_bool
     {
-      \save_nodes_to_file:V \l__sn_nodes_clist
+      \save_nodes_to_file:V \g__sn_nodes_clist
     }
     {
       \tl_if_empty:NF \l__sn_group_tl
       {
-        \save_nodes_to_list:VV \l__sn_group_tl \l__sn_nodes_clist
+        \save_nodes_to_list:VV \l__sn_group_tl \g__sn_nodes_clist
       }
     }
-    \clist_gclear:N \l__sn_nodes_clist
+    \clist_gclear:N \g__sn_nodes_clist
   }
 }
+\DeclareDocumentCommand \SaveNode { o m }
+{
+  \group_begin:
+  \IfNoValueF {#1}
+  {
+    \keys_set:nn {tikzmark / save nodes}
+    {
+      file=false,
+      group=#1
+    }
+  }
+  \bool_if:NTF \l__sn_file_bool
+  {
+    \save_nodes_to_file:n {#2}
+  }
+  {
+    \tl_if_empty:NF \l__sn_group_tl
+    {
+      \save_nodes_to_list:Vn \l__sn_group_tl {#2}
+    }
+  }
+  \group_end:
+}
 \ExplSyntaxOff
 %% 
 %% Copyright (C) 2011-2021 by Andrew Stacey <loopspace at mathforge.org>
@@ -837,6 +1059,8 @@
 %%                                 tikzmark.pdf,
 %%                                 tikzlibrarytikzmark.code.tex, and
 %%                                 tikzmarklibrarylistings.code.tex
+%%                                 tikzmarklibraryhighlighting.code.tex
+%%                                 tikzmarklibraryams.code.tex
 %% 
 %%
 %% End of file `tikzlibrarytikzmark.code.tex'.

Added: trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryams.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryams.code.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryams.code.tex	2022-10-26 19:59:50 UTC (rev 64819)
@@ -0,0 +1,67 @@
+%%
+%% This is file `tikzmarklibraryams.code.tex',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% tikzmark.dtx  (with options: `ams')
+%% ----------------------------------------------------------------
+%% 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
+%% ----------------------------------------------------------------
+%% 
+
+\@ifpackageloaded{amsmath}{%
+  \let\tikzmark at ams@boxz@=\boxz@
+  \newcounter{tikzmarkequation}
+  \def\tikzmark at ams@name{equation}
+  \def\tikzmark at boxz@{%
+    \ifmeasuring@
+    \tikzmark at ams@boxz@
+    \else
+    \stepcounter{tikzmarkequation}%
+    \tikzmark at box{\tikzmark at ams@name-\thetikzmarkequation}{\z@}%
+    \fi
+  }
+  \newenvironment{tikzmarkmath}[1][equation]{%
+    \def\tikzmark at ams@name{#1}%
+    \setcounter{tikzmarkequation}{0}%
+    \let\boxz@=\tikzmark at boxz@
+  }{%
+    \let\boxz@=\tikzmark at ams@boxz@
+    \message{%
+      Tikzmark math environment
+      \tikzmark at ams@name\space had
+      \the\value{tikzmarkequation} nodes in it
+    }%
+  }
+}{%
+  \PackageError{tikzmark AMS}%
+  {The amsmath package has not been loaded.}%
+  {}
+}
+%% 
+%% Copyright (C) 2011-2021 by Andrew Stacey <loopspace at 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
+%%                                 tikzmarklibraryhighlighting.code.tex
+%%                                 tikzmarklibraryams.code.tex
+%% 
+%%
+%% End of file `tikzmarklibraryams.code.tex'.


Property changes on: trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryams.code.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryhighlighting.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryhighlighting.code.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryhighlighting.code.tex	2022-10-26 19:59:50 UTC (rev 64819)
@@ -0,0 +1,558 @@
+%%
+%% This is file `tikzmarklibraryhighlighting.code.tex',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% tikzmark.dtx  (with options: `highlighting')
+%% ----------------------------------------------------------------
+%% 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
+%% ----------------------------------------------------------------
+%% 
+
+\ExplSyntaxOn
+\cs_new_protected_nopar:Npn \tikzmark_fix_name:Nn #1#2
+{
+  \tl_set:Nx #1 {\tikzmark at pp@name{#2}}
+}
+\tl_new:N \g__tikzmark_highlighter_tl
+\tl_set:Nn \g__tikzmark_highlighter_tl {tikzmark~ highlighter~}
+\int_new:N \g__tikzmark_highlighter_int
+\tl_new:N \l__tikzmark_start_tl
+\tl_new:N \l__tikzmark_end_tl
+\tl_new:N \l__tikzmark_highlighter_name_tl
+\tl_new:N \l__tikzmark_tmpa_tl
+\tl_new:N \l__tikzmark_tmpb_tl
+\tl_new:N \l__tikzmark_tmpc_tl
+
+\cs_new_protected_nopar:Npn \tikzmark_bake_highlighter:N #1
+{
+  \tl_clear:N #1
+  \clist_map_inline:nn {direction,layer}
+  {
+    \tl_put_right:Nx #1 {
+      /tikz/highlighter/##1=\pgfkeysvalueof{/tikz/highlighter/##1},
+    }
+  }
+  \clist_map_inline:nn {
+    initial~ height,
+    initial~ depth,
+    initial~ offset,
+    final~ height,
+    final~ depth,
+    final~ offset,
+    left~ margin,
+    right~ margin,
+    top~ margin,
+    bottom~ margin,
+  }
+  {
+    \tl_put_right:Nx #1 {
+      /tikz/highlighter/##1=\dim_eval:n {\pgfkeysvalueof{/tikz/highlighter/##1}},
+    }
+  }
+}
+
+\cs_new_protected_nopar:Npn \tikzmark_start_highlighting:n #1
+{
+  \int_gincr:N \g__tikzmark_highlighter_int
+  \tl_set:Nx \l__tikzmark_highlighter_name_tl
+  {
+    \tl_use:N \g__tikzmark_highlighter_tl
+    \int_use:N \g__tikzmark_highlighter_int
+  }
+  \tl_set:Nn \l__tikzmark_tmpb_tl
+  {
+    every~ highlighter/.try,
+  }
+  \tikzmark_bake_highlighter:N \l__tikzmark_tmpc_tl
+  \tl_put_right:NV \l__tikzmark_tmpb_tl \l__tikzmark_tmpc_tl
+  \tl_put_right:Nn \l__tikzmark_tmpb_tl {#1}
+  \tikzmark_process_highlighting:VV
+  \l__tikzmark_tmpb_tl
+  \l__tikzmark_highlighter_name_tl
+  \tikzmark{highlight-start-\tl_use:N \l__tikzmark_highlighter_name_tl}
+}
+\cs_new_protected_nopar:Npn \tikzmark_end_highlighting:
+{
+  \tl_set:Nx \l__tikzmark_highlighter_name_tl
+  {
+    \tl_use:N \g__tikzmark_highlighter_tl
+    \int_use:N \g__tikzmark_highlighter_int
+  }
+  \tikzmark{highlight-end-\tl_use:N \l__tikzmark_highlighter_name_tl}
+}
+
+\NewDocumentCommand \StartHighlighting {O{}}
+{%
+  \tikzmark_start_highlighting:n {#1}
+}
+\NewDocumentCommand \StopHighlighting {}
+{%
+  \tikzmark_end_highlighting:
+}
+\NewDocumentCommand \Highlight {O{} m}
+{%
+  \tikzmark_start_highlighting:n {#1}
+  #2
+  \tikzmark_end_highlighting:
+}
+\tl_const:Nx \c__tikzmark_colon_tl
+{
+  \char_generate:nn {`:} {12}
+}
+
+\cs_generate_variant:Nn \hook_gput_next_code:nn {nV}
+\cs_new_protected_nopar:Npn \tikzmark_highlight_or_shunt:nnnn #1#2#3#4
+{
+  \bool_lazy_all:nT
+  {
+    {\tl_if_exist_p:c {save at pt@\tikzmark at pp@name{#2}}}
+    {\tl_if_exist_p:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#2}}}}
+    {\tl_if_exist_p:c {save at pt@\tikzmark at pp@name{#3}}}
+    {\tl_if_exist_p:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#3}}}}
+  }
+  {
+    \int_compare:nTF
+    {
+      \tl_use:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#2}}}
+      >
+      \the\value{page}
+    }
+    {
+      \hook_gput_next_code:nn {#1} {
+        \tikzmark_highlight_or_shunt:nnnn {#1}{#2}{#3}{#4}
+      }
+    }
+    {
+      \tl_set:Nn \l__tikzmark_tmpa_tl {#4}
+      \int_compare:nTF
+      {
+        \tl_use:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#2}}}
+        =
+        \the\value{page}
+      }
+      {
+        \tl_put_right:Nx \l__tikzmark_tmpa_tl
+        {
+          {
+            pic~ cs
+            \tl_use:N \c__tikzmark_colon_tl
+            #2
+          }
+        }
+      }
+      {
+        \tl_put_right:Nn \l__tikzmark_tmpa_tl
+        {
+          {
+            page.north~ west
+          }
+        }
+      }
+      \int_compare:nTF
+      {
+        \tl_use:c {save at pg@\tl_use:c{save at pt@\tikzmark at pp@name{#3}}}
+        =
+        \the\value{page}
+      }
+      {
+        \tl_put_right:Nx \l__tikzmark_tmpa_tl
+        {
+          {
+            pic~ cs
+            \tl_use:N \c__tikzmark_colon_tl
+            #3
+          }
+        }
+      }
+      {
+        \tl_put_right:Nn \l__tikzmark_tmpa_tl
+        {
+          {
+            page.south~ east
+          }
+        }
+        \hook_gput_next_code:nn {#1} {
+          \tikzmark_highlight_or_shunt:nnnn {#1}{#2}{#3}{#4}
+        }
+      }
+      \tl_use:N \l__tikzmark_tmpa_tl
+    }
+  }
+}
+\cs_new_protected_nopar:Npn \tikzmark_process_highlighting:nn #1#2
+{
+  \pgfkeys{/tikz/highlighter/configuration/.activate~ family}
+  \pgfkeysfiltered{/tikz/.cd,highlighter/direction,highlighter/layer,#1}
+
+  \tikzmark_fix_name:Nn \l__tikzmark_start_tl {highlight-start-#2}
+  \tikzmark_fix_name:Nn \l__tikzmark_end_tl {highlight-end-#2}
+  \tl_set:Nx \l__tikzmark_tmpa_tl {\pgfkeysvalueof{/tikz/highlighter/direction}}
+  \tl_clear:N \l__tikzmark_tmpb_tl
+  \tl_clear:N \l__tikzmark_tmpc_tl
+  \tl_if_eq:NnTF \l__tikzmark_tmpa_tl {vertical}
+  {
+    \tl_put_right:Nn \l__tikzmark_tmpb_tl
+    {
+      \vl at draw
+    }
+  }
+  {
+    \tl_if_eq:NnTF \l__tikzmark_tmpa_tl {box}
+    {
+      \tl_put_right:Nn \l__tikzmark_tmpb_tl
+      {
+        \box at draw
+      }
+    }
+    {
+      \tl_put_right:Nn \l__tikzmark_tmpb_tl
+      {
+        \hl at draw
+      }
+    }
+  }
+
+  \tl_put_right:Nn \l__tikzmark_tmpb_tl
+  {
+    {tikzmark~ clear~ ixes,#1}
+  }
+
+  \tl_set:Nx \l__tikzmark_tmpa_tl {\pgfkeysvalueof{/tikz/highlighter/layer}}
+  \tl_set:Nn \l__tikzmark_tmpc_tl
+  {
+    \tikzmark_highlight_or_shunt:nnnn
+  }
+  \tl_if_eq:NnTF \l__tikzmark_tmpa_tl {foreground}
+  {
+    \tl_put_right:Nn \l__tikzmark_tmpc_tl {{shipout/foreground}}
+  }
+  {
+    \tl_put_right:Nn \l__tikzmark_tmpc_tl {{shipout/background}}
+  }
+
+  \tikzmark_tl_put_right_braced:NV \l__tikzmark_tmpc_tl \l__tikzmark_start_tl
+  \tikzmark_tl_put_right_braced:NV \l__tikzmark_tmpc_tl \l__tikzmark_end_tl
+  \tikzmark_tl_put_right_braced:NV \l__tikzmark_tmpc_tl \l__tikzmark_tmpb_tl
+
+  \tl_if_eq:NnTF \l__tikzmark_tmpa_tl {foreground}
+  {
+    \hook_gput_next_code:nV {shipout/foreground} \l__tikzmark_tmpc_tl
+  }
+  {
+    \hook_gput_next_code:nV {shipout/background} \l__tikzmark_tmpc_tl
+  }
+}
+\cs_generate_variant:Nn  \tikzmark_process_highlighting:nn {nV,VV}
+\ExplSyntaxOff
+\def\hl at draw#1#2#3{%
+  \pgfkeys{/tikz/highlighter/configuration/.activate family}
+  \pgfkeysfiltered{/tikz/.cd,highlighter/direction,highlighter/layer,#1}
+  \begin{tikzpicture}[
+    remember picture,
+    overlay,
+    highlight picture action,
+    #1,
+  ]%
+  \page at node
+  \tikz at scan@one at point\pgfutil at firstofone(#2)\relax
+  \pgf at ya=\pgf at y
+  \tikz at scan@one at point\pgfutil at firstofone(#3)\relax
+  \pgf at yb=\pgf at y
+  \ifdim\pgf at ya=\pgf at yb
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial offset},
+  \pgfkeysvalueof{/tikz/highlighter/initial height})
+  coordinate (start);
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final depth})
+  coordinate (end);
+  \path[
+    highlight action,
+    #1
+  ] (start) rectangle (end);
+  \else
+  \path (page.east)
+  ++(\pgfkeysvalueof{/tikz/highlighter/right margin},0pt)
+  coordinate (east);
+  \path (page.west)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/left margin},0pt)
+  coordinate (west);
+  \pgfmathsetlength\pgf at x{%
+    \pgfkeysvalueof{/tikz/highlighter/initial height}%
+  }%
+  \advance\pgf at yb by \pgf at x\relax
+  \pgfmathsetlength\pgf at x{%
+    -1*\pgfkeysvalueof{/tikz/highlighter/final depth}%
+  }%
+  \advance\pgf at ya by \pgf at x\relax
+  \ifdim\pgf at yb>\pgf at ya
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial offset},
+  \pgfkeysvalueof{/tikz/highlighter/initial height})
+  coordinate (start);
+  \path (#2)
+  ++(0pt,-1*\pgfkeysvalueof{/tikz/highlighter/final depth})
+  coordinate (end);
+  \path[
+    highlight action,
+    #1
+  ] (start) rectangle (end -| east);
+  \path (#3)
+  ++(0pt,\pgfkeysvalueof{/tikz/highlighter/initial height})
+  coordinate (start);
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final depth})
+  coordinate (end);
+  \path[
+    highlight action,
+    #1
+  ] (start -| west) rectangle (end);
+  \else
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial offset},
+  \pgfkeysvalueof{/tikz/highlighter/initial height})
+  coordinate (tl);
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/initial depth})
+  coordinate (start);
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final depth})
+  coordinate (end);
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final offset},
+  \pgfkeysvalueof{/tikz/highlighter/final height})
+  coordinate (mr);
+  \path[
+    highlight action,
+    #1
+  ] (start) -- (tl) -- (tl -| east) -- (mr -| east) -- (mr) --
+  (end) -- (end -| west) -- (start -| west) -- cycle;
+  \fi
+  \fi
+  \end{tikzpicture}%
+}
+\def\box at draw#1#2#3{%
+  \pgfkeys{/tikz/highlighter/configuration/.activate family}
+  \pgfkeysfiltered{/tikz/.cd,highlighter/direction,highlighter/layer,#1}
+  \begin{tikzpicture}[
+    remember picture,
+    overlay,
+    highlight picture action,
+    #1,
+  ]%
+  \tikz at scan@one at point\pgfutil at firstofone(#2)\relax
+  \pgf at xa=\pgf at x
+  \tikz at scan@one at point\pgfutil at firstofone(#3)\relax
+  \pgf at xb=\pgf at x
+  \def\tkmk at high@bscale{1}%
+  \ifdim\pgf at xa>\pgf at xb
+  \def\tkmk at high@bscale{-1}%
+  \fi
+  \path (#2)
+  ++({\tkmk at high@bscale*(-1)*\pgfkeysvalueof{/tikz/highlighter/initial offset}},
+  \pgfkeysvalueof{/tikz/highlighter/initial height})
+  coordinate (start);
+  \path (#3)
+  ++(\tkmk at high@bscale*\pgfkeysvalueof{/tikz/highlighter/final offset},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final depth})
+  coordinate (end);
+  \path[
+    highlight action,
+    #1
+  ] (start) rectangle (end);
+  \end{tikzpicture}%
+}
+\def\vl at draw#1#2#3{%
+  \pgfkeys{/tikz/highlighter/configuration/.activate family}
+  \pgfkeysfiltered{/tikz/.cd,highlighter/direction,highlighter/layer,#1}
+  \begin{tikzpicture}[
+    remember picture,
+    overlay,
+    highlight picture action,
+    #1,
+  ]%
+  \tikz at scan@one at point\pgfutil at firstofone(#2)\relax
+  \pgf at ya=\pgf at y
+  \pgf at xa=\pgf at x
+  \tikz at scan@one at point\pgfutil at firstofone(#3)\relax
+  \pgf at yb=\pgf at y
+  \pgf at xb=\pgf at x
+  \pgfmathsetlength\pgf at y{%
+    \pgfkeysvalueof{/tikz/highlighter/initial offset}%
+  }%
+  \advance\pgf at yb by \pgf at y
+  \pgfmathsetlength\pgf at y{%
+    -1*\pgfkeysvalueof{/tikz/highlighter/final offset}%
+  }%
+  \advance\pgf at ya by \pgf at y
+  \ifdim\pgf at yb>\pgf at ya
+  \ifdim\pgf at xa>\pgf at xb
+  \path (#2)
+  ++(\pgfkeysvalueof{/tikz/highlighter/initial height},
+  \pgfkeysvalueof{/tikz/highlighter/initial offset})
+  coordinate (start);
+  \path (#3)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/final depth},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final offset})
+  coordinate (end);
+  \else
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial depth},
+  \pgfkeysvalueof{/tikz/highlighter/initial offset})
+  coordinate (start);
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final height},
+  -1*\pgfkeysvalueof{/tikz/highlighter/final offset})
+  coordinate (end);
+  \fi
+  \path[
+    highlight action,
+    #1
+  ] (start) rectangle (end);
+  \else
+  \path (#2)
+  ++(\pgfkeysvalueof{/tikz/highlighter/initial height},0)
+  coordinate (tr);
+  \path (#2)
+  ++(0,\pgfkeysvalueof{/tikz/highlighter/initial offset})
+  coordinate (start);
+  \path (#2)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/initial depth},0)
+  coordinate (tl);
+  \path (#3)
+  ++(\pgfkeysvalueof{/tikz/highlighter/final height},0)
+  coordinate (br);
+  \path (#3)
+  ++(0,-1*\pgfkeysvalueof{/tikz/highlighter/final offset})
+  coordinate (end);
+  \path (#3)
+  ++(-1*\pgfkeysvalueof{/tikz/highlighter/final depth},0)
+  coordinate (bl);
+  \tikz at scan@one at point\pgfutil at firstofone(#2)\relax
+  \pgf at xa=\pgf at x
+  \tikz at scan@one at point\pgfutil at firstofone(#3)\relax
+  \pgf at xb=\pgf at x
+  \ifdim\pgf at xa<\pgf at xb
+  \path[
+    highlight action,
+    #1
+  ] (tl) |- (start) -| (tr) -| (br) |- (end) -| (bl) -| cycle;
+  \else
+  \path[
+    highlight action,
+    #1
+  ] (tl) |- (start) -| (tr) |- (br) |- (end) -| (bl) |- cycle;
+  \fi
+  \fi
+  \end{tikzpicture}
+}
+\tikzset{%
+  /tikz/highlighter/.is family,
+  /tikz/highlighter/.unknown/.code={%
+    \let\tk at searchname=\pgfkeyscurrentname%
+    \pgfkeysalso{%
+      /tikz/\tk at searchname=#1
+    }
+  },
+  every highlight path/.style={
+    fill=yellow!50,
+    rounded corners,
+  },
+  every foreground highlight path/.style={
+    fill opacity=.5,
+  },
+  highlight picture action/.style={
+    every highlight picture/.try,
+    every \pgfkeysvalueof{/tikz/highlighter/direction} highlight picture/.try,
+    every \pgfkeysvalueof{/tikz/highlighter/layer} highlight picture/.try,
+  },
+  highlight action/.style={
+    every highlight path/.try,
+    every \pgfkeysvalueof{/tikz/highlighter/direction} highlight path/.try,
+    every \pgfkeysvalueof{/tikz/highlighter/layer} highlight path/.try,
+    highlight path/.try,
+    \pgfkeysvalueof{/tikz/highlighter/direction} highlight path/.try,
+    \pgfkeysvalueof{/tikz/highlighter/layer} highlight path/.try,
+  },
+  /tikz/highlighter/.cd,
+  direction/.initial=horizontal,
+  layer/.initial=background,
+  direction/.default=horizontal,
+  layer/.default=background,
+  initial height/.initial=\baselineskip,
+  initial depth/.initial=.5ex,
+  initial offset/.initial=.5\baselineskip,
+  final height/.initial=\baselineskip,
+  final depth/.initial=.5ex,
+  final offset/.initial=.5\baselineskip,
+  left margin/.initial=.5\baselineskip,
+  right margin/.initial=.5\baselineskip,
+  top margin/.initial=.5\baselineskip,
+  bottom margin/.initial=-.5\baselineskip,
+  height/.style={
+    initial height=#1,
+    final height=#1
+  },
+  depth/.style={
+    initial depth=#1,
+    final depth=#1
+  },
+  offset/.style={
+    initial offset=#1,
+    final offset=#1
+  },
+  margin/.style={
+    left margin=#1,
+    right margin=#1,
+    top margin=#1,
+    bottom margin=#1,
+  },
+  /tikz/highlighter/configuration/.is family,
+  /tikz/highlighter/direction/.belongs to family=/tikz/highlighter/configuration,
+  /tikz/highlighter/layer/.belongs to family=/tikz/highlighter/configuration,
+}
+\def\page at node{
+  \path (current page.north west)
+  ++(\hoffset + 1in + \oddsidemargin + \leftskip,
+  -\voffset - 1in - \topmargin - \headheight - \headsep)
+  node[
+    minimum width=\textwidth - \leftskip - \rightskip,
+    minimum height=\textheight,
+    anchor=north west,
+    line width=0mm,
+    inner sep=0pt,
+    outer sep=0pt,
+  ] (page) {};
+}
+%% 
+%% Copyright (C) 2011-2021 by Andrew Stacey <loopspace at 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
+%%                                 tikzmarklibraryhighlighting.code.tex
+%%                                 tikzmarklibraryams.code.tex
+%% 
+%%
+%% End of file `tikzmarklibraryhighlighting.code.tex'.


Property changes on: trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibraryhighlighting.code.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibrarylistings.code.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibrarylistings.code.tex	2022-10-26 19:59:14 UTC (rev 64818)
+++ trunk/Master/texmf-dist/tex/latex/tikzmark/tikzmarklibrarylistings.code.tex	2022-10-26 19:59:50 UTC (rev 64819)
@@ -12,6 +12,7 @@
 %% See http://www.latex-project.org/lppl.txt
 %% ----------------------------------------------------------------
 %% 
+
 \@ifpackageloaded{listings}{%
   \newif\iflst at linemark
   \lst at linemarktrue
@@ -45,7 +46,8 @@
   \pgfmark{line-\lst at name-\tkzmk at lst@start-start}%
 }
 }{%
-    \PackageError{tikzmark listings}{The listings package has not been loaded.}{}
+  \PackageError{tikzmark listings}%
+  {The listings package has not been loaded.}{}
 }
 %% 
 %% Copyright (C) 2011-2021 by Andrew Stacey <loopspace at mathforge.org>
@@ -65,6 +67,8 @@
 %%                                 tikzmark.pdf,
 %%                                 tikzlibrarytikzmark.code.tex, and
 %%                                 tikzmarklibrarylistings.code.tex
+%%                                 tikzmarklibraryhighlighting.code.tex
+%%                                 tikzmarklibraryams.code.tex
 %% 
 %%
 %% End of file `tikzmarklibrarylistings.code.tex'.



More information about the tex-live-commits mailing list.