# Using tikzexternalize with pdflscape results in rotated image

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:

• You could add a \rotatebox depending on whether \tikzexternalize@hasbeencalled is defined and equals 1. I was however not successful in patching tikzpicture in a way that makes everything work correctly. – Caramdir Jun 26 '12 at 20:28
• @Caramdir: That's a good idea, but that doesn't work with the trim left and trim right functionality (another thing I didn't mention, sorry!). rotatebox doesn't rotate the trim direction, unfortunately. – Jake Jun 26 '12 at 20:37