Calculation in a TeX function. How to do it?

I don't know anything of `TeX` but would like to improve a function.

Here is the initial function:

``````\newcommand{\setnewvsize}[1]{%
\global\paperheight\dimexpr#1+\initialVerticalInset\relax%
\global\pdfpageheight\paperheight%
\global\textheight\paperheight%
\global\@colht\textheight \global\@colroom\textheight \global\vsize\textheight%
\global\initialVerticalInset=0pt
}
``````

Here is what I would like to do:

``````\newlength{\bottomMargin}
\setlength{\bottomMargin}{3mm}

\newcommand{\setnewvsize}[1]{%
\global\paperheight\dimexpr#1+\initialVerticalInset\relax%
\global\pdfpageheight\paperheight%
\global\textheight\paperheight - \bottomMargin%
\global\@colht\textheight \global\@colroom\textheight \global\vsize\textheight%
\global\initialVerticalInset=0pt
}
``````

I want to set `\textheight` to `\paperheight - \bottomMargin`.

I don't know if this has a sense since I don't know `TeX`.

How could I perform this calculation in the function?

• `\global\setlength\textheight{\dimexpr\paperheight-\bottomMargin}` or your more plain solution `\global\textheight\dimexpr\paperheight-bottomMargin\relax`. Just use `\dimexpr .. \relax` when you need to perform inline operations with dimens. By the way, why not using `geometry` package for instance? – Manuel Sep 17 '15 at 22:44
• @Manuel tex.stackexchange.com/q/213750/8323 That's why :p – Colas Sep 17 '15 at 22:51
• @Manuel if you want, you can make it an answer! – Colas Sep 18 '15 at 12:10

You just need to use `\dimexpr .. \relax` where you want inline opertions with dimensions.

The more LaTeX-y way would be using

`````` \global\setlength\textheight{\dimexpr\paperheight-\bottomMargin}
``````

and the mor plain version would be

``````\global\textheight\dimexpr\paperheight-bottomMargin\relax
``````

(if you understand the assignment better you can use an equal after the dimen that you are setting `\global\textheight=\dimexpr⟨whatever⟩\relax`).