1

I'm trying to replicate the space above the equation environment. Currently, I have to manually alternate between

\vspace{\abovedisplayskip}

and

\vspace{\abovedisplayshortskip}

depending on the length of the line above. (If it's long enough, I use the first one. If it's short enough, I use the second one.)

How can I automate this into one simple command?

lockstep
  • 250,273
  • In what situations are you using those spacings? And why not using displaymath? – egreg Aug 07 '12 at 13:28
  • @egreg See Werner's solution to my other question: http://tex.stackexchange.com/questions/66152/pushing-qed-to-the-right-within-a-displayed-formula His solution is great, expect for this little part. (And I find the other solutions, that suggest ntheorem and adding stuff into the preamble, just mess up everything I already have in place and is otherwise working fine.) – MayGodBlessKnuth Aug 07 '12 at 13:36

1 Answers1

3

I would use $$ to get the automatic spacing, but just adjust the display. So in plain TeX:

enter image description here

\tracingoutput1
\showboxbreadth\maxdimen

\def\foo#1{%
$$%
\setbox0\hbox{$\displaystyle#1$ QED}%
\dimen0\predisplaysize
\advance\dimen0\wd0
\ifdim\dimen0>\hsize
\hbox to \hsize{\hfill\box0}%
\fi
\rlap{\kern-.5\hsize\hbox to \hsize{\hfill\box0}}%
$$}

aaaaa
\foo{f(x)=ax^2+bx+c}
bbbbbb



aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa 
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa 
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa 
aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa 
aaaaa aaaaa aaaaa aaaaa
\foo{f(x)=ax^2+bx+c}
bbbbbb bbbbbbbbbbbb bbbbbbbbbbbb bbbbbbbbbbbb bbbbbb
bbbbbb bbbbbbbbbbbb bbbbbbbbbbbb bbbbbbbbbbbb bbbbbb


\bye

Checking the log shows the short skips were used in the first example and the long in the second:

$ grep display.*skip dd.log
..\glue(\abovedisplayshortskip) 0.0 plus 3.0
..\glue(\belowdisplayshortskip) 7.0 plus 3.0 minus 4.0
..\glue(\abovedisplayskip) 12.0 plus 3.0 minus 9.0
..\glue(\belowdisplayskip) 12.0 plus 3.0 minus 9.0
David Carlisle
  • 757,742