8

I'm trying to define a \newcommand with three arguments. I'd like to:

  • compare the height of these arguments
  • choose the largest height to create frames (with that height) around the arguments.

Question

How can I compare these three arguments to choose the tallest?


First Update

Following the advise by David Calister, I defined a command which insert all the arguments in a box and return the height of the box, and also defined a new lenght (called MyLen).

The following code,

\documentclass{minimal}
\usepackage{calc}
\newcommand\zz[3]{\sbox0{\ensuremath{#1#2#3}}\the\ht0}
\newlength{\MyLen}

\begin{document}
\zz{1}{2}{\frac{3}{4}}
\zz{1}{2}{3}
\end{document}

results into

enter image description here

Well Done so far!

Then, I'd like to set MyLen to be such result, using

\documentclass{minimal}
\usepackage{calc}
\newcommand\zz[3]{\sbox0{\ensuremath{#1#2#3}}\the\ht0}
\newlength{\MyLen}

\begin{document}
\zz{1}{2}{\frac{3}{4}}

\zz{1}{2}{3}

\settoheight\MyLen{\zz{1}{2}{\frac{3}{4}}}
\the\MyLen
\end{document}

but the result is wrong (the last value should be equal to the first one)

enter image description here

What is happening? Where is my mistake?

3
  • :-) you worried me for a bit there:-) \settoheight\MyLen{\zz{1}{2}{\frac{3}{4}}} measures the height of the output of \zz which is the string 8.44843pt and that has height 6.44444 same as 123 ;-) Commented Oct 4, 2013 at 17:55
  • so you can of course not use \zz and use \settoheight\MyLen{$1 2 \frac{3}{4}$} as \zz and \settoheight have essentially the same definition except one uses box 0 and one uses \@tempboxa for measuring Commented Oct 4, 2013 at 18:01
  • @DavidCarlisle Yes Sir! you're right again! Cheers
    – Dox
    Commented Oct 4, 2013 at 18:04

1 Answer 1

5
\newcommand\zz[3]{%
\sbox0{#1#2#3}%
\showthe\ht0
}
3
  • 3
    To whovever downvoted, would you care to say why? This does exactly what is asked in the question \ht0 is the maximum height of the renderings of the three arguments. Commented Oct 4, 2013 at 16:21
  • Thank you for the idea, I found your code very helpful, and a small tweak is almost working... I've updated the question. (Note that I change \showthe\ht0 by \the\ht0, because your suggestion gave me compilation problems). :-)
    – Dox
    Commented Oct 4, 2013 at 17:46
  • 2
    @Dox \showthe is a debugging command like \show it stops with a fake error at that point and shows the value on the terminal, hit return and it continues, it is not intended for production code Commented Oct 4, 2013 at 18:03

You must log in to answer this question.

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