I'm looking for a command (say \foo{}) or pair of commands (say \foos, \fooe) that behave like:

equation environment if there is no \\ nor &

multline if there is a single \\

align if there are both & and \\

Also, automatically switches between the * variants if there is no \label command.

The commands should be compatible with usual packages (amsmath etc), and should support the usual \tag, \label, \ref commands. Just to be clear, using it should not slow down compilation by any perceptible amount.

Bonus gratitude if you also give me a command to switch the behavior of \[ \] from the usual one to the above one, back-and-forth in a paper.

I am constantly switching between the three environments and it is really annoying. Thanks!

Note: I am telling LaTeX where to break the equation. All I want is LaTeX to be smart enough to use the appropriate environment!

  • I meant double back-slash, but it didn't show.
    – Manu
    Commented Nov 27, 2011 at 22:22
  • A tip: you can enclose TeX code in back quotes as I've done in my edit.
    – egreg
    Commented Nov 27, 2011 at 22:27
  • 2
    It should be possible to define a custom environment that parses its contents to determine which one is appropriate based on the algorithm you describe and then pass the environment \BODY to the appropriate environment, at least for simple cases. But that is beyond my skill set. Commented Dec 2, 2011 at 1:01

1 Answer 1


No, there isn't such a "do-it-all" environment. Each one of equation, multline, align and gather (you forgot about this one) solves a different problem caused by different sets of math mode material to display.

Breaking math mode material requires judgment that a machine can't have.

There are packages such as nath and breqn that try to automatize this process, but my opinion is that there's no easy algorithm to do breaking properly, because it requires to look at the result.

However, here it is a working doitall environment:




Now no numbers


I can understand your desire of a do-it-all environment; but you're losing information.

If you want to use \[ and \] as delimiters, just say


in the preamble. Switching the meaning of \[...\] back and forth is completely useless, of course.


You can't use aligned or gathered environments inside the doitall environment, as these have & and \\ inside them. It's of course impossible to use also the split environment.

  • Thanks (grazie) for the pointers. However you are misinterpreting my question. I am telling LaTeX where to break the equation. All I want is LaTeX to be smart enough to use the appropriate environment! One can write e.g. a Perl script that does the job. Can't it be done automatically by LaTeX?
    – Manu
    Commented Nov 28, 2011 at 13:54
  • 5
    @EmanueleViola I've asked the moderator to remove the $100 offer, which is quite inappropriate here. The solution is actually rather easy; but it's not something I would use.
    – egreg
    Commented Dec 5, 2011 at 13:55
  • THANK YOU! You just made my day. And of course I stand by my previous $100 offer. I am really glad to see this solved and that the solution isn't complicated.
    – Manu
    Commented Dec 5, 2011 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .