[OS X TeX] landscape

Bruno Voisin bvoisin at icloud.com
Sat Apr 8 08:02:22 EDT 2017


> Le 8 avr. 2017 à 10:17, Doris Behrendt <doris.behrendt at me.com> a écrit :
> 
> when I typeset this
> 
> \documentclass[landscape,ngerman]{article}
> \parindent=0cm
> \usepackage{babel}
> \usepackage[utf8]{inputenc}
> \begin{document}
> Hallöchen Welt!
> \end{document}
> 
> with TeXShop and look at it, I don't get a paper in landscape view.
> I didn't follow all the possible solutions of this problem in the last years. I would be glad if someone could tell me the way to do it right now in 2017, perhaps without using the geometry package, because I am searching for an absolute minimal example with as view packages as possible.

This is because the landscape option acts on parameters \paperheight and \paperwidth, which define the "logical" page size used by LaTeX to compose text. LaTeX subtracts the margins, header and footer to get the \textheight and \textwidth; these define the size of the page body, telling LaTeX where to introduce line and page breaks.

The "physical" page size, namely the size of the PDF output page, is defined by separate parameters which depend on the driver:

- For dvips, a \special{papersize=width,height}.

- For pdfTeX and LuaTeX up to version 0.84, two parameters \pdfpagewidth and \pdfpageheight. 

- For LuaTeX version 0.85 and above, two parameters \pagewidth and \pageheight.

- XeTeX understands both the papersize \special from dvips, and the \pdfpagewidth and \pdfpageheight parameters of pdfTeX.

Standard LaTeX packages like graphics, hyperref and geometry take care of this mess, and set the relevant parameters equal to \paperheight and \paperwidth, so that the logical and physical page sizes match.

But otherwise, these remain separate. In particular, the physical page size remains whatever was set up at the time MacTeX was installed (A4 or US Letter, most likely, both portrait).

Adding in the preamble the following code should take care of this:

\usepackage{ifpdf}
\ifpdf
  \ifx\pdfpagewidth\undefined
    % LuaTeX >= 0.85
    \setlength{\pagewidth}{\paperwidth}
    \setlength{\pageheight}{\paperheight}
  \else
    % pdfTeX and LuaTeX < 0.85
    \setlength{\pdfpagewidth}{\paperwidth}
    \setlength{\pdfpageheight}{\paperheight}
  \fi
\else
  % XeTeX, dvips and dviLuaTeX
  \special{papersize=\the\paperwidth,\the\paperheight}
\fi

This can be shortened in two ways, using that (i) \pdfpagewidth and \pagewidth are defined even when using dvips (see the PS below) and (ii) it seems to do no harm to introduce the \special even for drivers -- pdfTeX and LuaTeX -- that don't understand it:

- A most compact version requiring the compatibility package luatex85, which makes the new LuaTeX understand the syntax of the old LuaTeX:

\usepackage{luatex85}
% pdfTeX, XeTeX and LuaTeX
\setlength{\pdfpagewidth}{\paperwidth}
\setlength{\pdfpageheight}{\paperheight}
% dvips, XeTeX and dviLuaTeX
\special{papersize=\the\paperwidth,\the\paperheight}

- A slightly less compact version requiring no package:

\ifx\pdfpagewidth\undefined
  % LuaTeX >= 0.85
  \setlength{\pagewidth}{\paperwidth}
  \setlength{\pageheight}{\paperheight}
\else
  % pdfTeX, XeTeX and LuaTeX < 0.85
  \setlength{\pdfpagewidth}{\paperwidth}
  \setlength{\pdfpageheight}{\paperheight}
\fi
% dvips, XeTeX and dviLuaTeX
\special{papersize=\the\paperwidth,\the\paperheight}

Bruno 

PS In an earlier test for the third version, I had used

\ifx\pdfpagewidth\undefined
  % LuaTeX >= 0.85
  \setlength{\pagewidth}{\paperwidth}
  \setlength{\pageheight}{\paperheight}
\else
  % pdfTeX, XeTeX and LuaTeX < 0.85
  \setlength{\pdfpagewidth}{\paperwidth}
  \setlength{\pdfpageheight}{\paperheight}
  % dvips, XeTeX and dviLuaTeX
  \special{papersize=\the\paperwidth,\the\paperheight}
\fi

It's quite odd that \ifx\pdfpagewidth\undefined yields false for dvips, much to my surprise. It seems to be because this is not actual tex, but pdftex in DVI mode, and the behavior in that respect changed at some point. Says /texmf-dist/tex/latex/latexconfig/latex.ini:

% We're building the latex format with the pdfetex engine (started 2004).
\input pdftexconfig
\pdfoutput=0
%
% pdfTeX related primitives are no longer hidden by default
% (started 2005). Uncomment and recreate the format files by running
% "fmtutil --all" resp.  "fmtutil-sys --all" to revert to the old
% (2004) behaviour.
% \input pdftex-dvi.tex

This last file texmf-dist/tex/generic/config/pdftex-dvi.tex provides a detailed explanation of the matter in its comments, should you be interested.

So \pdfoutput and \pdfpagewidth etc. are defined, even when using dvips. You need to use the ifpdf package to test, nothing else. How confusing! (As if the above was not confusing enough already…)




More information about the MacOSX-TeX mailing list