I do not like it when my maths spills over onto a second line. For example, what I am currently doing spits out stuff like,

...just some talking then we have some maths Aut(G)
< H/K and lo! it has spilled onto another line...

However, I feel that the following is much neater,

...just some talking then we have some maths
Aut(G) < H/K and lo! it has not spilled onto another

Is there anyway of getting LaTeX to do this for me? I thought the command \mbox would work, or putting \relpenalty=10000' and\binoppenalty=10000' in the preamble, but these are `dumb' and do not think - they will spit out,

...just some talking then we have some maths Aut(G) < H/K
and lo! it has spilled onto another line, and has
gone into the margin...

and we get the overspill into the margin. This is also true of the other fixes I have seen when I've been searching. I was wondering if there was some sort of `intelligent' thing, a package I could use or something I could put in the preamble, which makes math mode stick to the margins but keeps a block of maths on the same line.

Thanks in advance!

(There are two other `obvious' fixes:

  1. I could use double dollar signs or square brackets to put my maths on a line of its own. However, I do use this for longer strings of maths, but for short things like Aut(G) < H/K this is just overkill and is distracting when you are reading it.

  2. I could go through my document and look at every instance of this problem and either add words or take away words earlier in the paragraph to make the maths sit on one line. However, I am trying to write something which will render nicely using different class files, and this fix is very much dependent on the class file I will be using ('cause of font sizes, etc.))

  • Related (duplicate?) How can I prevent LaTeX from breaking inline formulas globally?
    – cmhughes
    Apr 19, 2012 at 11:15
  • @cmhughes: The fixes in that question will result in overfull hbox-es, and replacing 10000 with 9999 isn't strong enough...(I had a `test' string, which it didn't split...)
    – user1729
    Apr 19, 2012 at 11:20
  • 2
    You could adjust \relpenalty and \binoppenalty as you did, plus \raggedright. Of course, this will give you a ragged right margin, but you can't have everything, I guess. It may work better with some classes than others, you could try tufte-book, for instance.
    – Koji
    Apr 19, 2012 at 11:21
  • 2
    The problem is not specific to math. The same would happen for a sequence of fffffffffffffffffff or any other non-hyphenable text. The problem is simply that there is no acceptable line break before your formula. This effect is especially prominent in the first line of text, so you would see a much better result by writing longer paragraphs with a lot of explaining text in the beginning ;-) You could try setting \relpenalty=9999 and \binoppenalty=9999 and \tolerance=9999, this way formulas would only be broken in a real emergency. Apr 19, 2012 at 11:23
  • @Koji: I am working with class files given to me, so I cannot choose them. However, I shall try \raggedright. Thanks!
    – user1729
    Apr 19, 2012 at 11:23

2 Answers 2


It is hard to give specific advice as you have not supplied a working example, but in general if you prevent breaking within the math then you have a large unbreakable unit in the paragraph. tex will not stick this in the margin unless all its line breaking options are infinitely bad.

So... if you want to stop it doing that you need to make one of its other options be less bad, for example you may find \sloppy allows the inter-word spacing to stretch enough to find a position for the mathematics that does not stick in to the margin.


A first fix is to write math as math:

...just some talking then we have some maths
$\Aut(G) < H/K$ and it won't easily split across

Remember to put


in your preamble. If a particular formula is still split across lines, then

$\Aut(G) < \nobreak H/K$

will prevent it (but the paragraph may end being set improperly).

  • What I put in my post is the output, not the input. Also, the \nobreak fix ends up with overfull hboxes, which is precisely what I don't want.
    – user1729
    Apr 23, 2012 at 9:57
  • @user1729 That's what the remark in parentheses says. Adjust the wording or accept the break. There are other ways for getting a paragraph without overfull boxes (look in this site for \emergencystretch), but the best remedy is, in the majority of cases, rewording.
    – egreg
    Apr 23, 2012 at 11:08
  • As I said in my post, rewording isn't an option - my document is a good 50 pages long, and needs to work in a number of different font sizes...
    – user1729
    Apr 23, 2012 at 12:03
  • @user1729 So this is a different problem than you stated and my answer was to the present question. It's quite difficult to have a document that typesets well under different line widths or font sizes.
    – egreg
    Apr 23, 2012 at 12:38
  • 1
    I don't see how this is a different problem. I haven't edited my question from when I originally posted it.
    – user1729
    Apr 24, 2012 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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