1

I have declared several lengths in my document: \bottomMargin \topMargin and \initialPaperHeight.

Right now, I am doing this

\AtEndDocument{%
\global\paperheight\dimexpr\pagetotal + \bottomMargin + \topMargin \relax
}

But, instead of setting \paperheight to \pagetotal + \bottomMargin + \topMargin, I would like to set \paperheight to the minimum of this value and of \initialPaperHeight. In pseudo-code, I would like to do

\paperheight = min(\initialPaperHeight, \pagetotal + \bottomMargin + \topMargin)

So, my question is: How should I do?

1
\AtEndDocument{%
  \ifdim\dimexpr \pagetotal + \bottomMargin + \topMargin < \initialPaperHeight \relax
    \global\paperheight\dimexpr \pagetotal + \bottomMargin + \topMargin
  \else
    \global\paperheight\initialPaperHeight
  \fi
}

However, to me it seems that you are trying to do something complicated here which you shouldn't need.

1

LaTeX3 has also a function for this:

\usepackage{expl3}

\ExplSyntaxOn

\global \paperheight = \dim_min:nn { \initialPaperHeight } { \pagetotal + \bottomMargin + \topMargin }

\ExplSyntaxOff

(untest because you gave no MWE …)

  • you should then switch to full expl3 and use something like \dim_gset – yo' Dec 21 '15 at 13:11
  • @yo' I know … :-) – Tobi Dec 21 '15 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.