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


        x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
        e = mc^2
        y &= mx + b \\
        a &= \frac{y - b}{x}


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: Overlay of the rendered document with and without \zsaveposy{}

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.

  • 1
    What do you want to do with the information during shipout exactly?
    – cfr
    Sep 27 at 3:47
  • You have a spurious space at the start, but I don't think that's relevant. How did you generate the image exactly? Because I can't see any difference in the positioning with or without your code.
    – cfr
    Sep 27 at 3:58

1 Answer 1


The problem is that the second \pdfsavepos (before $$e=mc^2$$) is inserted in horizontal mode just after the first equation. The horizontal mode is opened by internal \noindent. If the \pdfsavepos isn't here then the following equation closes this horizontal mode immediately without any material in the horizontal list, so the paragraph line before $$e=mc^2$$ isn't created. But if the \pdfsavepos is here then the paragraph line is created here, so there is one more \hbox in the main vertical list.

I suggest to close horizontal mode, then insert \pdfsavepos and then open horizontal mode again with \noindent if we are in the horizontal mode. But this will not work correctly when there is a long sentence just before the equation, because display mode gets incorrect value of \predisplaysize and \above/below/displayshortskip is used instead correct \above/below/dipslayskip. But it depends on what cases you want to use this. Maybe you don't want to have any sentences just before equations.

    \ifhmode \par \zsaveposy{start-\thei}\noindent
    \else \zsaveposy{start-\thei}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .