[tex-eplain] boxed formulas

Oleg Katsitadze olegkat at gmail.com
Tue Sep 12 15:43:42 CEST 2006


On Tue, Sep 12, 2006 at 01:35:11PM +0200, Juan Mari Alberdi wrote:
> Now I've been trying to get a vertically
> centered equation number to the right of the frame with \eqno or
> \eqdef{label}, but it doesn't seem to be easy either.

Well, getting a _centered_ number is easy:

  \def\dboxit#1{\boxit{\hbox{$\displaystyle #1$}}}%

  $$\vcenter{\dboxit{\sum_{i=1}^n a_i = {n(a_1+a_n)\over2}}}\eqdef{}$$

(Note that I changed \dboxit a little.)

However, you may instead want a number aligned on the
baseline, as with this example adapted from The TeXbook:

  $$a_0+{1\over\displaystyle a_1+
          {\strut 1\over\displaystyle a_2+
            {\strut 1\over\displaystyle a_3+
              {\strut 1\over a_4}}}}
  \eqdef{}$$

Compare this with what you get with a box:

  $$\vcenter{\dboxit{
    a_0+{1\over\displaystyle a_1+
          {\strut 1\over\displaystyle a_2+
            {\strut 1\over\displaystyle a_3+
              {\strut 1\over a_4}}}}
  }}\eqdef{}$$

I can't think of an easier way to deal with this than to
calculate the height of the formula and then force a \vbox
with that height:

  \def\dboxit#1{%
    \setbox0=\hbox{$\displaystyle #1$}%
    \dimen255=\ht0
    % Add box space, and height and depth of the rule.
    \advance\dimen255 by\boxitspace
    \advance\dimen255 by\hruledefaultheight
    \advance\dimen255 by\hruledefaultdepth
    \vbox to\dimen255{\boxit{\box0}\vss}%
  }%

  $$\dboxit{
    a_0+{1\over\displaystyle a_1+
          {\strut 1\over\displaystyle a_2+
            {\strut 1\over\displaystyle a_3+
              {\strut 1\over a_4}}}}
  }\eqdef{}$$

An academic side note:  \dboxit could be made a little more
efficient -- \boxit already creates a \vbox, so you can
avoid one layer of \vbox if you substitute \boxit's
definition.

HTH,
Oleg


More information about the tex-eplain mailing list