I want to decrease a length by a number (count). I tried some variations with \newlength{\temp} and \addtolength but I got problems there with the minus. I also tried variants with \dimexpr.

The following example is an absolute MWE. temp must be possibly negative. The mathematical operation must be a subtraction. Originally I had some \expandafters in there, but they are probably wrong and mess up the readability.




\def\haha#1{xyz \hspace{\advance\strip@pt#1 by -\temp pt} abc}



The output should be


  • This is as simple as \hspace{\dimexpr#1+\temp pt}.
    – Werner
    May 30, 2016 at 21:03

1 Answer 1


The following achieves what you're after:

enter image description here




\newcommand{\haha}[1]{xyz-\hspace{\dimexpr#1+\value{temp} pt}-abc}


xyz-\hspace{60pt}-abc% verification


I've used the LaTeX2e interface for counters, together with \value{<cntr>} to return a number of the counter <cntr>.

  • Aaaah. I just found out (inspired by yours), that this works also: \def\haha#1{xyz \hspace{\dimexpr#1-\the\temp pt} abc} This is a hybrid of two of my approaches. And basically the same as yours. May 30, 2016 at 21:32
  • @MaestroGlanz \the is redundant
    – egreg
    May 30, 2016 at 21:35
  • In my, lets say guess, I put the dimexpr in front of the wrong value of both. No wonder.... May 30, 2016 at 21:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .