2

I'd like to pass a measure of length in form of a string, i.e.

\setlength{string}

or

\setlength{'string'}

instead of

\setlength{2.5cm}

I seem to remember seeing something like that somewhere in LaTeX, but can't find it. Appreciate your input!

Zubo
  • 582
  • 4
    Are you looking for \settowidth{\somelength}{string}? – egreg Jan 27 '16 at 22:23
  • 6
  • 1 minute. I love StackExchange. @egreg Wonderful, thanks a lot! I'd mark it as the answer, but I can't do that with a comment. Werner - it's not the exact same issue, though I see your point. – Zubo Jan 27 '16 at 22:28
  • @Zubo: Questions are phrased differently, but they use the same principles. The other is actually a little more comprehensive than this request, making this one a subset of the linked post (in my opinion). I'm voting to close as a duplicate. – Werner Jan 27 '16 at 23:41

1 Answers1

4

The LaTeX kernel provides

\settowidth
\settoheight
\settodepth

and you probably want the first one:

\newlength{\somelength}

\settowidth{\somelength}{some text}

Note that it's better to set lengths to a text dependent width after \begin{document}. So, if you need \somelength for a macro definition in the preamble, you should do

\newcommand{\foo}{...depending on \somelenght...}

\AtBeginDocument{\settowidth{\somelength}{some text}}
egreg
  • 1,121,712