2

I want to break the line in the following code. I have tried two versions: version 1 has math mode for the whole term, and version 2 has math mode only at the necessary parts. I was expecting version 2 to break the line because it is just like a normal long word, but neither of them can break automatically. Other than adding a line breaker manually, how to achieve line breaking? Thanks.

\documentclass[review]{elsarticle}
\usepackage{geometry}
\geometry{margin=3cm}
\begin{document}
Version 1:

The sublattice model of $\beta$-MnCr$_2$O$_4$ spinel phase for the current work is assumed to be $(\textrm{Mn}^{2+})_1(\textrm{Cr}^{3+},\textrm{Fe}^{3+},\textrm{Mn}^{3+},\textrm{Va})_2(\textrm{Va})_2(\textrm{O}^{2-})_4$.

Version2:

The sublattice model of $\beta$-MnCr$_2$O$_4$ spinel phase for the current work is assumed to be (Mn$^{2+}$)$_1$(Cr$^{3+}$,Fe$^{3+}$,Mn$^{3+}$,Va)$_2$(Va)$_2$(O$^{2-}$)$_4$.
\end{document}
2
  • 4
    First you should probably look for some package to typeset chemical formula tex.stackexchange.com/questions/145838/…. It might already support the feature
    – user202729
    Commented Jun 14, 2022 at 15:15
  • @user202729 I just tried the typeset chemical formula on the long term, and it still did not break the line. But oh boy, I might have to correct every single chemical formula now using the typeset throughout my 40 pages document. This is the moment when I wish I never knew about the typeset... hehe
    – Jen
    Commented Jun 14, 2022 at 15:29

1 Answer 1

3

TeX only breaks inline formulas at binary or relational symbols and these do not occur in you chemical stuff, so the whole part

(Mn$^{2+}$)$_1$(Cr$^{3+}$,Fe$^{3+}$,Mn$^{3+}$,Va)$_2$(Va)$_2$(O$^{2-}$)$_4$

is a single unbreakable unit.

It doesn't help that you mix math and text here because that doesn't create breakpoints either.

  • there are no spaces
  • hyphenation of words is only done (by default) for words of length 5 (3+2) and anyway probably not wanted
  • hyphenation is also not done if the word is directly followed or preceded by something like math (without a space).

Line breaking is also restricted by \tolerance which tells TeX how "bad" a line is allowed to get. That is by default quite restricted with the idea that you look and fix bad breaks manually. Default values is 200, if stretching out the spacing more than that TeX will not consider that as a possible solution.

So your options are

  • fix bad lines manually when they happen (by adding \allowbreak in suitable places)
  • enlarge \tolerance to give TeX more options without manual intervention (depending on what level of bad solutions you are allowing, but always stay below 10000!)
  • or both in combination
  • or use \sloppy which should make LaTeX linebreak basically always, but than it can be very sloppy, hence the name.

In your particular example, what you need is \tolerance=1000 (in fact 722) and you get this:

enter image description here

which is not great, but ... (you get the same with \sloppyin this case as TeX will not choose worse solution just because it is allowed to, but in other cases it might, so take your pick) ... if you care about good typography than 1000 is already pretty bad --- I would only accept it in an emergency, but you might think differently.

Aside

I don't speak chem, so I have no idea is, for example a break after the commas in the formula would be generally acceptable, but if they are or if they usually are, then a simple solution is to do something like this (choose your own command name as you like)

\newcommand\bcomma{,\penalty100\relax}

and replace the commas where a break is allowed with that. You can choose a higher or a lower number as the penalty depending on how much you prefer to avoid a break. This gives you then:

enter image description here

without manual intervention (after a simple or not so simple query replace of relevant commas).

It a break should happen only before the ( a similar strategy could be used.

You could even go further and make , or ( active in math and expand to such a definition but I would probably advice against that as it can be fairly fragile if not done correctly.

1
  • I ended up using \allowbreak locally because I do not want to change the overall format anywhere else. Thanks for your input.
    – Jen
    Commented Jun 16, 2022 at 15:28

You must log in to answer this question.

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