Description
I would like to add code to the preamble of a document such that I am able to identify and store the vertical position of an environment without modifying the layout.
That is to say I require the rendered document to be identical whether my code is present or not.
What I have tried
MWE
\documentclass{article}
\usepackage{amsmath}
\usepackage{zref-savepos}
\usepackage{etoolbox}
\newcounter{i}
\BeforeBeginEnvironment{equation}{
\stepcounter{i}%
\zsaveposy{start-\thei}%
}%
\begin{document}
\begin{equation}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
\end{equation}
\begin{equation}
e = mc^2
\end{equation}
\begin{align}
y &= mx + b \\
a &= \frac{y - b}{x}
\end{align}
\end{document}
Issue
Using \zsaveposy{}
, \pdfsavepos{}
, \tikzmark{}
, and \tikzmarknode{}
all change the layout when they are used prior to beginning an equation environment.
Illustration of the issue:
An overlay of the rendered document, with and without the use of the \zsaveposy{}
command, demonstrating the resulting change to the layout:
Desired result
The ability to store the y-position in the document at the start and end of every environment to be used during shipout, without altering the original page layout.