TikZ: anchors of special node “current page” seem to be incorrect in landscape

I'm a bit hesitant about calling this a bug in pdflatex, but from my not-very-extensive investigations, it would appear that the position returned by the primitive \pdfsavepos is offset when in landscape mode and producing dvi. One way to explain the behaviour (though I've no idea how accurate this picture is) is that it is as if when \pdfsavepos runs then it actually computes the coordinates relative to the bottom left of the page. But TeX wants the coordinates relative to the top left so then pdflatex has to compute (0,paperheight) - (saved x, saved y) and return that via \pdfsavepos. However (still conjecturing) it's as if pdflatex when running in dvi mode does not know the actual page size of the shipped out page. So when it computes paperheight then it uses its "standard" paper height. This is based on the fact that the difference in the recorded positions in the aux file between a run with latex and a run with pdflatex is precisely \paperheight-\paperwidth:

pdflatex produces: \pgfsyspdfmark {pgfid1}{10467319}{17617993}

latex produces: \pgfsyspdfmark {pgfid1}{10467319}{29458709}

The difference is 11840716 (the units are sp).

And (in landscape mode) we can compare that with the paper dimensions via:

\newdimen\stuff
\stuff=11840716sp
\showthe\stuff

\stuff=\paperwidth
\advance\stuff by -\paperheight
\showthe\stuff

then this produces:

> 180.67499pt.
l.9 \showthe\stuff

? 
> 180.67499pt.
l.13 \showthe\stuff

This explanation can't be completely right because although I get a similar story (in that there is a consistent y-shift) when I try \usepackage[a5paper]{geometry} then the numbers don't add up in the same way.

For situations where one is going between two tikzpicture environments then this offset doesn't matter because it is consistent, and therefore the relative separation of the pictures is the same. It only matters for the current page node as that is "absolutely" positioned. To fix the current page, it suffices to fix where pgf thinks the page origin lies. This is held in the macro \pgf@sys@pdf@mark@pos@pgfpageorigin so we need to redefine that.

Ideally, we should redefine it to be aware of the current page size and geometry but as my experiments with a5paper showed me, I don't fully understand the computation involved. So here's the fix for landscape a4paper when set using the geometry package. If doing a mixed document, you could make the macro itself contain the conditional. By surrounding it in \ifpdf ... \fi we get a system that works for both latex and pdflatex.

\makeatletter
\ifpdf
\else
\ifGm@landscape
\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{0sp}{11840716sp}}
\fi
\fi
\makeatother

In an adaptation of your MWE:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/91105/86}
\usepackage[landscape]{geometry}
\usepackage{tikz}
\usepackage{lipsum}

\makeatletter
\ifpdf
\else
\ifGm@landscape
\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{0sp}{11840716sp}}
\fi
\fi
\makeatother

\begin{document}

\lipsum[1-4]

\begin{tikzpicture}[remember picture,overlay]
\foreach \anchor in {north west,north east,south west,south east} {
    \node[anchor=\anchor] at (current page.\anchor) {some stuff at \anchor};
}
\end{tikzpicture}
\end{document}

With pdflatex this produces:

landscape absolute positioning with pdflatex

With latex; latex; dvips; pstopdf (note the double run of latex) this produces:

landscape absolute positioning with latex


pdflatex (and also lualatex) relies on the value of \pdfpageheight to calculate the position, but geometry doesn't set this value if the dvi-mode is used. If you adjust the lengths the nodes are placed correctly:

\RequirePackage[T1]{fontenc} %for dvilualatex
\RequirePackage{luatex85}     % for current lualatex
\documentclass{article}
\usepackage[margin=0.5in,landscape]{geometry}
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth %not sure if needed but can't harm
\usepackage{tikz}
\usepackage{lipsum}
\begin{document}

\lipsum[1-4] 

\begin{tikzpicture}[remember picture,overlay]
    \node at (current page.south west) [text width=5cm,fill=red!20,above right] { This material is in the south west corner of the page };
\end{tikzpicture}

\end{document}