2

How do I define a variable that can be used in commands? If it is even possible?

I want to assign a length to a variable and use it in \addvspace, like:

\newcommand{\xxx}{1em}
\addvspace{\xxx}

Or:

\newlength{\xxx}
\setlength{\xxx}{1em}
\addvspace{\xxx}

But it doesn't work. Since there is no way to add automatic vertical space in paragraphs (without messing up everything, like \parskip), I thought it would be nice to have a variable then so all spaces can be adjusted without changing 5000 hardcoded spaces in the document each time.

K.C.
  • 71

1 Answers1

2

Use a length register:

\newlength{\xxx}
\setlength{\xxx}{1em}
\vspace{\xxx}, \addvspace{\xxx}, \rule{\xxx}{\xxx}

I.e. \xxx can be used everywhere where a length value is expected.

Unfortunately when using relative units, they are converted to an absolute value according to the active font settings, when calling \setlength.

But if you want to have a par skip, wha don’t you set \parskip, or better use the parskip package (or parskip option in KOMA-SCript)?

JPi
  • 13,595
Tobi
  • 56,353
  • Because parskip adds space everywhere, everywhere. Could wrap all text clumps in \parskip to avoid it, but the same problem would emerge. Still need a variable to define them all. But ok, so \addvspace doesn't work but \vspace does. Seems logic – K.C. Aug 15 '16 at 15:27
  • No … \addvspace should work too. The difference ist that you use a length instead of a macro ;-) – Tobi Aug 15 '16 at 19:50
  • @K.C.: If my answer answers you question, pleas mark it as accepted ;-) otherwise, what is missing? – Tobi Aug 30 '16 at 14:09