When using the external TikZ library to externalize an image in a pdflscape landscape environment, the resulting image is rotated by 90 degrees. This does not happen when including "normal" images. How can I avoid this? Or is there another way to have a single landscape page in a PDF that is also displayed in landscape mode in the viewer?
I want the document to look the same, whether \tikzexternalize is active or not, so just wrapping the tikzpicture in \rotatebox{90} is, unfortunately, not an option.
In my real document, only one page is in landscape mode, so unfortunately I can't just use the landscape option of the documentclass. Also, I'm using memoir for my actual document, in case that makes a difference for the solution.
MWE:
\documentclass{article}
\usepackage{pdflscape}
\usepackage{mwe} % For the example image
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize % Without externalization, the orientation is correct
\tikzset{external/force remake}
\begin{document}
\lipsum[1-5]
\begin{landscape}
\includegraphics[width=4cm]{example-image-a}
\begin{tikzpicture}
\node [scale=5] {A};
\end{tikzpicture}
\end{landscape}
\end{document}
Output with \tikzexternalize commented out: Everything's fine

With \tikzexternalize uncommented: The TikZ A is rotated incorrectly:

\rotateboxdepending on whether\tikzexternalize@hasbeencalledis defined and equals1. I was however not successful in patchingtikzpicturein a way that makes everything work correctly. – Caramdir Jun 26 '12 at 20:28trim leftandtrim rightfunctionality (another thing I didn't mention, sorry!).rotateboxdoesn't rotate thetrimdirection, unfortunately. – Jake Jun 26 '12 at 20:37