Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
In what situations are you using those spacings? And why not using displaymath? –  egreg Aug 7 '12 at 13:28
    
@egreg See Werner's solution to my other question: tex.stackexchange.com/questions/66152/… 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 7 '12 at 13:36

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.