8

I have read carefully the etex manual to understand the syntax of dimexpr and numexpr but my limited comprehension remains limited... The expression "\dimexpr" appears only 3 times in the mentioned manual and nowhere is a formal definition (I mean: that answers my question).

So, in the detail, one can find this macro on the net:

\newcommand\dimtomm[1]{%
\strip@pt\dimexpr 0.352777778\dimexpr#1\relax\relax
}

to convert a dimension in mm. The thing is that it doesn't seem to take into account the initial unit of #1... ? Indeed, I use this newcommand with a position issued from zsavepos which is in sp, and it works as if I had given the newcommand a dimension in pt!

There is so a more general question about dimensions, for which I can't find answer among the litteracy (source book, ...) and internet: when a variable is defined to contain a dimension, is there a unit attached to it, or is just a number but with a label "dimension"? I guess... no! because of the \strip@pt, but this is in contradiction with the behavior of \dimtomm above (according to me, of course).

Who could make a clear topo about dimension, about coordinate (zsavepos...), about how add a zsavepos in sp with a dimension in pt, about the dimexpr functioning, and so on?

EDIT To be more precise about my questioning, in order the answers not to be too general: I get the zsavepos of a point and I can access to x and y which are lenghts in sp. Then I want to draw locate an object in a draw using something like:

$(current page.north west) + (0cm,\xcoordtodim{\zposy{pointA}})$

So I face two problems of different types:

1) I want \xcoordtodim returns a dim, and apparently, I can't do that with my current knowledge...

2) \xcoordtodim adds the zposy of a point (in sp) with a given length generally expressed in pt: this is the question of "mixing" units linked to \dimtomm and \dimexpr...

3
  • The formal syntax for 〈dimen expr〉 is on p. 18 of the e-TeX manual, and on p. 17 it is explained how it fits in the definition of an 〈internal dimen〉. “About the \dimexpr behavior”, what do you want to know? If you are wondering about the double \dimexpr, I guess that the author of the macro did so in order to make a call like \dimtomm{.5\baselineskip} work too.
    – GuM
    Apr 29, 2017 at 19:51
  • 1
    @GustavoMezzetti: yes, the expression "dimexpr" appears 3 times in the manual. Twice in §3.5 (p.8), which of one is inline for presentation, and the other in a very complicated example mixing dimexpr and numexpr. And the last in §5.1. (p.17 for the version I own), which reads: \dimexpr<dimen expr><optional spaces and \relax>. Which is hard to see as an explanation of what is dimexpr and how to use it, unless you already know all other materials... About dimexpr behavior, for instance, who could explain please the functionning and the syntax of the dimtomm macro above?
    – biblio
    Apr 29, 2017 at 20:38
  • Admittedly, you must have already mastered the contents of The TeXbook, especially of Chapter 24, in order to understand the syntax diagrams in the e-TeX manual. In any case, the production rule you quote merely says that \dimexpr starts a 〈dimen expr〉 that is optionally closed with a \relax; the real explanations are given in the production for 〈dimen expr〉, and those it invokes, which you can find, as I said in my other comment, on p. 18.
    – GuM
    Apr 30, 2017 at 22:09

1 Answer 1

7

dimensions are not stored with a unit (actually they are always stored as an integer, in sp units). Whatever unit is used when setting the length (if a unit is used at all) \the will show the length using pt units.

Settings that don't use any explicit unit include things like

\setbox0\hbox{abc}  \dimen0=\wd0
3
  • OK, thanks for the precision. So, it means a dimen must be given with the unit. When it is not, I suppose tex takes it to be pt by default, right? (That's the "no unit inserted, I suppose pt" or like message when compiling...) But what about the dimexpr behavior?
    – biblio
    Apr 29, 2017 at 14:21
  • @biblio I am confident that the answer to your question is yes. Jan 9, 2018 at 15:51
  • 1
    @biblio dimexpr is the same syntax as a classic dim assignment, the unit is mandatory or you get an error (with recovery being to assume pt) Jan 9, 2018 at 17:11

You must log in to answer this question.

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