Lengths – Adding Lengths with Plus and Minus Syntax in LaTeX

lengths

Is it possible to add macro lengths
with manually coded numbers or with other macros
in a length input,
(as opposed to needing to use \addlength)?

MWE:

See \setlength{\xfootskip}{\xfootheight plus 0.25in}

[Please do not focus on use of KOMA with geometry ; j ]

\documentclass{scrreprt}

% Page size, margin, and header/footer settings:

% Enable "showframe" when editing margins
 \usepackage{showframe}                                     % Uncomment this to display header/footer/margins outlines.
 \usepackage{geometry}

% General margin settings:
 \newlength{\xhmargin   } \setlength{\xhmargin   }{1.000in}
 \newlength{\xlmargin   } \setlength{\xlmargin   }{1.500in}
 \newlength{\xrmargin   } \setlength{\xrmargin   }{\xhmargin}

 \newlength{\xtmargin   } \setlength{\xtmargin   }{1.000in} % Actual tmargin = [\xtmargin - \xheadheight]
 \newlength{\xbmargin   } \setlength{\xbmargin   }{1.000in} % Actual bmargin = [\xbmargin - \xfootskip  ]

% Header  margin settings:
 \newlength{\xheadheight} \setlength{\xheadheight}{0.500in}
 \newlength{\xheadsep   } \setlength{\xheadsep   }{1.000em}

% Footer  margin settings:
 \newlength{\xfootheight} \setlength{\xfootheight}{0.500in}
 \newlength{\xfootskip  } \setlength{\xfootskip  }{\xfootheight plus 0.25in} % [Set = Footheight + desired Footsep]



\KOMAoptions{fontsize   = 10pt,
             parskip    = half-,
             headings   = small,
             headheight = \xheadheight,
             footheight = \xfootheight,
             DIV        = current}

\geometry{letterpaper,
          tmargin       = \xtmargin,
          bmargin       = \xbmargin,
          lmargin       = \xlmargin,
          rmargin       = \xrmargin,
          headsep       = \xheadsep,
          footskip      = \xfootskip}


\begin{document}
A
\end{document}

Best Answer

The syntax

\setlength{\xfootskip}{\xfootheight plus 0.25in}

tells TeX that \xfootskip has natural width equal to \xfootheight and a stretchability of 0.25in.

Note that this works just because \xfootheight has no stretchability and shrinkability, otherwise you'd get an error message.

If you want to add the value, do

\setlength{\xfootskip}{1\xfootheight}
\addtolength{\xfootskip}{0.25in}

or

\setlength{\xfootskip}{\dimexpr\xfootheight+0.25in\relax}

The factor 1 is used to kill possible stretchability or shrinkability. In case you want to do arithmetic with rubber length (skips), you can use \glueexpr.

Related Question