# Put long formulas on new line/pgf tikz?

Sometimes I have to work with long formulas that can (or I want) not be split over two lines. I'm trying to write a macro that sent the formula at the new line if the formula would go over the margin. For example, with lines of twenty characters, and calling \Foo this macro: a text like

12345678901234567890
aaaaa aaaa aaaaaa \$bbbbbb\$
aaaaa aaaa

is formatted as

12345678901234567890
aaaaa aaaa aaaaaa bbbbbb
aaaaa aaaa

while

12345678901234567890
aaaaa aaaa aaaaaa \Foo{\$bbbbbb\$}
aaaaa aaaa

is formatted as

12345678901234567890
aaaaa aaaa aaaaaa
bbbbbb aaaaa aaaa

Since this require to verify if such macro is over the limit after printing, I suppose is something requiring multiple step of compilation. The only way I know to retrieve coordinates of a point is using a tikz coordinate, but so a "pseudocode" draft of what I'm trying to do is:

\newcommand{\Foo}[1]{%
\myCount=\myCount+1
\if\NameConcat\FooVar\myCount>\pageLength\endline\else\relax
#1%
\coordinate\NameConcat\FooVar\myCount%
}

(at the start \myCount and all \FooVars have to be "zero", and \NameConcat concatenate the FooVar name and the counter creating as many counter as needed)

So, what is the best way to implement this in LaTeX?

-