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 '16 at 21:03

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. – MaestroGlanz May 30 '16 at 21:32
  • @MaestroGlanz \the is redundant – egreg May 30 '16 at 21:35
  • In my, lets say guess, I put the dimexpr in front of the wrong value of both. No wonder.... – MaestroGlanz May 30 '16 at 21:44

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.