Here is my code:


\def\Printdimen#1#2{\strip@pt \dimexpr #2 *65526 /\number\dimexpr 1#1}


\Printdimen{mm}{\hsize} mm
  • 4
    all your questions seem to be about this one line of code? – David Carlisle Apr 28 '15 at 15:57
  • @DavidCarlisle Yeah , because i am confused about that – enadul shaheen Apr 28 '15 at 16:00
  • @egreg but after / i used \dimexpr 1#1 – enadul shaheen Apr 28 '15 at 16:04
  • 3
    But just asking the same question repeatedly in multiple question sand in chat gives the impression that you ignore the answers. – David Carlisle Apr 28 '15 at 16:22
  • 3
    @enadulshaheen We've already pointed out that this is not really the sort of code that one reads to learn LaTeX. Even if you aim to learn to program plain TeX you should pick up some basics first. – Joseph Wright Apr 28 '15 at 16:55

The macro \strip@pt wants after it a dimension register; it will remove the final pt after the extracted value.

In e-TeX, \dimexpr behaves as an “unnamed” dimension register, so it's good after \strip@pt. According to the syntax rules of \dimexpr, a dimension (implicit or explicit) inside it can be followed by * or / to denote multiplication or (rounded) division. However the multiplier/divisor must be an integer.

So \dimexpr 3pt/2 is valid, but \dimexpr3pt/1.5 is not.

A dimension register appearing in a context where TeX expects an integer will be coerced to it using the value in scaled points; 65536 scaled points are 1pt, which is the reason for the 65536 multiplier.

Thus \number is not really necessary and

\def\Printdimen#1#2{\strip@pt\dimexpr (#2) * 65536 / \dimexpr 1#1\relax\relax}

is good as well. It's better to add the two \relax that end the \dimexpr expression.

| improve this answer | |
  • perfect answer man . I got it what i need. Thanks – enadul shaheen Apr 28 '15 at 16:14
  • I would add parentheses around #2, then this argument can be any expression understood by \dimexpr without invalidating the multiplication. – Heiko Oberdiek Apr 28 '15 at 17:39
  • @HeikoOberdiek Good idea! – egreg Apr 28 '15 at 17:40

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.