[Tex/LaTex] Should I prefer {pdflscape} over [pdftex]{lscape}


I came across a problem with pdflscape and TikZ' external library where externalized tikzpictures in a landscape environment were rotated incorrectly ( Using tikzexternalize with pdflscape results in rotated image). Apparently, this is a known bug (added to the pgfplots "to-do" list in 2009).

In my case, it turns out that everything works fine if I use \usepackage[pdftex]{lscape} instead of \usepackage{pdflscape}: The landscape page is correctly rotated and displayed in the PDF viewer, and the externalized image is oriented correctly.

Is there a reason why I should not use [pdftex]{lscape} instead of the {pdflscape} package? It seems that both do the same thing (make sure that landscape pages are displayed in landscape mode in the viewer). However, on the lscape CTAN page it says:

Note that the package makes no special provision for PDF output, where
in principle a single page can be shown at full landscape width; such
an effect may be achieved using the pdflscape package instead.

Why does the lscape package recommend using pdflscape instead of its own pdftex switch?

Best Answer

Answering the various points "why does lscape package recommend a different package" well it doesn't really. The ctan catalog package descriptions are not (in general) by the package authors but a third party review of the package.

There are three places that "rotation" can occur when considering a page in a pdf file. lscape only considers one of them [* see note at end about [pdftex] option] and pdflscape considers two.

To make a page landscape you need to:

  • first switch round \textheight and \textwidth (and a few other associated lengths). That much you can do in pure TeX.

  • Then you need to rotate the text box on to the page (since lscape doesn't move the page numbers) This is done by using \rotatebox from the graphics package and so needs driver dependent code specified by a package option or defaulted from graphics.cfg.

  • For printing, that's all you need, but for viewing you might want to rotate the "entire page" the other way so that on-screen the main text is vertical and the effect is that the page outline is rotated to landscape. pdflscape inserts additional code to rotate the view in the viewer.

  • But ... some pdf viewers use heuristics to determine the orientation of the "main" text on a page and rotate the page view even when not explicitly specified.

As far as I know you can't reliably rotate the page view in ways that work for all configurations of all viewers. If as in the original lscape you ignore the issue the page will look fine if using a viewer that auto-rotates and the page has sufficient text that it can tell which way is up (It's harder to tell which is up for images). If you force the view to rotate as in pdflscape then (I think) if the viewer auto-rotates the it gets rotated twice so ends up the wrong way up. It would be nice to be able to say "this way up" but I don't think that's possible (and it isn't what either package does) you can only say "rotate the view" from a default that might change depending on the viewer.

At least I think that's the situation, I never actually used pdflscape but I had a quick look at its code while writing this:-)

Ah. As noted above I checked the code for the "other" package but didn't check the code of "my" package. ...

So apparently back in 1999 I accepted a 3rd party diff so that lscape also affects the pdf page view attributes if used with [pdftex] . Sorry the version in my head was the original:

% \changes{v3.01}{1999/06/22}{Added better pdfTeX support
%    by Scott Pakin, from graphics/3063}
%    \begin{macrocode}
%    \end{macrocode}
%  Here is what Scott Pakin wrote about the pdftex option:
% \begin{quote}
%    I've made a minor improvement to lscape.dtx that I'd like to share 
% with the world.  My addition makes lscape rotate the PDF "paper" --
% not just the text on the page -- when given the "pdftex" option.
% (Naturally, this works only with pdfLaTeX.)  The result is that the
% text is viewable online without the reader having to rotate his/her
% head 90 degrees.  The document still prints normally.
% \end{quote}

    \pdfpageattr{/Rotate 90}

So I think that there effectively isn't any difference for pdftex but pdflscape adds equivalent code for many other driver back ends such as dvips or dvipdfm. Sorry about the confusion.

This also explains why you need to use [pdftex] explicitly lscape handles that itself to add the code shown above. It would probably be better if instead it just let graphics handle the options and then make an internal check to see which driver backend graphics ended up using. That way it would also work if the graphics driver were defaulted from graphics.cfg (as is usually the case with graphics package options).