# 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?

-

I wouldn't do it so complicated. You can just put the formula or any other text in a `\mbox{...}` to prevent it from being broken across lines:
``````12345678901234567890
@macro: That's not always the case but depends on the line content. You can influence this by modifying some penalties. You can also put `\linebreak[3]` in front of `\mbox`, best as part of a macro, to pursue LaTeX to break the line there if required. – Martin Scharrer Apr 29 '11 at 10:11