Skip to content

unexpected result with \geometry in the preamble (but not with \newgeometry) #3

@komascript

Description

@komascript

I've already reported this to Hideo Umeki without any reaction. So once again:

It seems that geometry for \geometry prioritizes textwidth and textheight settings over total setting, but does not do so for \newgeometry in the document body. Look at this example:

\documentclass{article}
\usepackage[%
  includehead=false,% default
  includefoot=false,% default
  includemp=false,% default
  textwidth=400pt,
  textheight=500pt,
]{geometry}
%\usepackage{xpatch}
%\xapptocmd{\geometry}{\newgeometry{#1}}{}{}
\geometry{a4paper,total={500pt,600pt}}
\begin{document}
\raggedright
first set: 400pt, 500pt\\
second:    500pt, 600pt\\
expect:    500pt, 600pt\\
got: \the\textwidth, \the\textheight

\newgeometry{total={500pt,600pt}}
After \verb|\newgeometry| inside document body:\\
expected: 500pt, 600pt\\
got: \the\textwidth, \the\textheight
\end{document}

It results in:

first set: 400pt, 500pt
second: 500pt, 600pt
expect: 500pt, 600pt
got: 400.0pt, 500.0pt

After \newgeometry inside document body:
expected: 500pt, 600pt
got: 500.0pt, 600.0pt

Output after \newgeometry is as expected. But the initial \geometry{a4paper,total={500pt,600pt}} does not change \textwidth and \textheight (only \paperwidth and \paperheight) as expected.

If you activate the two deactivated patch lines, you'll get the expected result:

first set: 400pt, 500pt
second: 500pt, 600pt
expect: 500pt, 600pt
got: 500.0pt, 600.0pt

After \newgeometry inside document body:
expected: 500pt, 600pt
got: 500.0pt, 600.0pt

but an additional warning because of usage of a4paper in \newgeometry. Same, if you replace \geometry by \newgeometry.

Note: The example is only for simplification. In true life the problem is due to default settings in a package that cannot be overwritten by the user using \geometry{total={…}}. I know, the user could use:

\geometry{a4paper,textwidth=500pt,textheight=600pt}

or

\geometry{a4paper}
\newgeometry{total={500pt,600pt}}

and each of them would work. But the user should know this.

I would not call this is a bug. But can you at least document it, e.g., in the "Known Problems" section?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions