# Tikzmarks being placed arbitrarily when shifting tikzpicture

I wanted to center my tikzpicture canvas for all my slides so that can consistently position objects. For some reason, when I added shift=(current page.center) to all my tikzpicture picture environments, the tikzmark's I used positioned their marks extremely arbitrarily. I've tried to distill a MWE below which replicates this strange behaviour.

\documentclass[xcolor={svgnames}]{beamer}

\usetheme{boxes}
\useoutertheme{infolines}

\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

% I tried this, but it didn't work.
%\tikzset{%
%  every picture/.append style={%
%        shift=(current page.center)
%        }}

\begin{frame}
\begin{itemize}
\item \tikzmark{a} abcd
\item abcd
\item abcd
\end{itemize}
% Including shift in the options causes the tikzmark to move arbitrarily.
\begin{tikzpicture}[remember picture,overlay]%,shift=(current page.center)]
\node at (current page.center) {o};
\node at (pic cs:a) {tikz-a};
\end{tikzpicture}

\end{frame}

\end{document}


Here is what it looks like when I don't shift the tikzpicture.

And now when I do.

I get the same behaviour if I append the shift to tikzpicture; I did so with the intention that it would appropriately shift tikzmark's coordinates too.

I also find it funny that the page centers (marked with an 'o') are the same in both cases; this is not usually true with the slides I'm trying to make though.

Finally, I am using the 1.0 version of tikzmark from CTAN.

-
shifting is not centering. You are adding the coordinate of the page center to the picture objects that are given with explicit coordinates, e.g., (2,3) would do but (a.west) won't) and that's the intended behavior. Nodes do not get affected from these transformations unless transform shape is used. That's why the current page node is unaffected. In your slides probably they are not nodes. Long story short there is no extreme arbitrariness –  percusse Jun 13 '13 at 7:02
@percusse: But the question is if the coordinate system of the tikzmark should be affected by such transformations. I would have expected it stay put -- similar to a node beside the tikzmark added with \tikz[overlay,remember picture]\node (b){B}; which can be used in the tikzpicture and is not affected by the shift. –  Ulrike Fischer Jun 13 '13 at 7:35
@percusse Hmm... I got the shift trick from tex.stackexchange.com/questions/21359/…. My intention is that I'd like the origin to always be at the center of the page. I'm not using any relative coordinates here either, but I presume you are talking about what's going on inside tikzmark? –  arunchaganty Jun 13 '13 at 8:45
percusse is correct: the apparent shift of the tikzmark is an actual shift of the coordinate returned by the pic cs coordinate system. Perhaps this should be node-like in that it isn't affected by transformations. I'll take a look to see if that behaviour is easy to switch off. –  Loop Space Jun 13 '13 at 10:38
@UlrikeFischer A feature request from you is like a command from anyone else! As you can see from my answer, it's simple to fix and as you say, it would be the "obvious" behaviour for it not to move. I have a few bug fixes now for tikzmark so I'll upload it to CTAN soon. –  Loop Space Jun 13 '13 at 13:38

percusse is correct: the apparent shift of the tikzmark is an actual shift of the coordinate returned by the pic cs coordinate system. Node coordinates get round this by explicitly inverting the matrix and applying it to the coordinate before returning it to the parser.

Here's a modified version of the pic coordinate system that is transform-invariant.

\documentclass[xcolor={svgnames}]{beamer}

\usetheme{boxes}
\useoutertheme{infolines}

\usepackage{tikz}
\usetikzlibrary{tikzmark}

\makeatletter
\tikzdeclarecoordinatesystem{pic}{%
\pgfutil@in@,{#1}%
\ifpgfutil@in@%
\tmk@labeldef#1\@nil
\else
\tmk@labeldef#1,(0pt,0pt)\@nil
\fi
\@ifundefined{save@pt@\tmk@label}{%
\tikz@scan@one@point\pgfutil@firstofone\tmk@def
}{%
\pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
\pgfsys@getposition{\pgfpictureid}\save@this@pic%
\pgf@process{\pgfpointorigin\save@this@pic}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\pgf@process{\pgfpointorigin\save@orig@pic}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\@ifundefined{save@pg@\csname save@pt@\tmk@label\endcsname}{}{%
\@ifundefined{save@pg@\pgfpictureid}{}{%
\pgfkeysvalueof{/tikz/next page vector}%
\advance \pgf@xa by \csname save@pg@\csname save@pt@\tmk@label\endcsname\endcsname\pgf@x\relax
\advance \pgf@ya by \csname save@pg@\csname save@pt@\tmk@label\endcsname\endcsname\pgf@y\relax
}%
}%
\pgf@x=\pgf@xa
\pgf@y=\pgf@ya
\pgftransforminvert%
\pgf@pos@transform{\pgf@x}{\pgf@y}%
}%
}
\makeatother

\begin{document}

% I tried this, but it didn't work.
\tikzset{%
every picture/.append style={%
shift=(current page.center),
scale=.5
}}

\begin{frame}
\begin{itemize}
\item \tikzmark[\coordinate(mark)]{a}abcd
\item abcd
\item abcd
\end{itemize}
% Including shift in the options causes the tikzmark to move arbitrarily.
\begin{tikzpicture}[remember picture,overlay]%,shift=(current page.center)]
\node (p) at (0,0) {O};
\node (q) at (0pt,0pt) {Q};
\node at (current page.center) {o};
\begin{scope}[xshift=1cm]
\node at (pic cs:a) {tikz-a};
\end{scope}
\node at (mark) {mark};
\end{tikzpicture}

\tikzset{every picture/.style = {}}
\begin{tikzpicture}[remember picture,overlay]
\draw[->] (0,0) -- (p);
\draw[->] (0,0) -- (pic cs:a);
\end{tikzpicture}

\end{frame}

\end{document}


-
Just in case the screenshot doesn't make it plain, I'd like to point out that this answer was done completely on an iPad. –  Loop Space Jun 15 '13 at 19:26