1

I use \left and \right in an inline equation in LaTeX. However, I see the inline equation can't be broken.

My code:

\documentclass{article}
\usepackage{mhchem}
\usepackage{amsmath}
\usepackage{lipsum}
\begin{document}

fsadjlllllllllllllllllllllllllllllllllllllllllllsafddddddddddddddddddddddddlllllll $\left.(\ce{Mg^2+}-\ce{PO4^2-})\right/\ce{HNO3-}$\par \lipsum{1-2}

\end{document}

The result is: enter image description here

What can I do so the equation can be broken?

Ingmar
  • 6,690
  • 5
  • 26
  • 47
Y. zeng
  • 1,885
  • 1
    The \left and \right instruction had to be in one line (ii) your equation you can write as $(\ce{Mg^2+}-\ce{PO4^2-})\big/\ce{HNO3-}$\par – Zarko May 18 '22 at 04:07
  • @Zarko But even use \big/, there is a - out of line. How to resolve this problem? – Y. zeng May 18 '22 at 04:27
  • 1
    @Zarko I think it is better to use \middle instead of \big here, as middle would increase the height as it needs. – Y. zeng May 18 '22 at 04:51
  • The - is out of the line: you give no maneuverability to the typesetting machine: there is only one srtetchable/shrinkable space just before math. If this math is moved to the second line then this single space must be removed and the first line is underfull. The first breakpoint in the math is after the minus operator, but the line is overfull in such case. There is no third possibility. – wipet May 18 '22 at 05:34
  • @wipet Okay. It is a liitle imperfect. – Y. zeng May 18 '22 at 05:36
  • @wipet - The microtype package opens some additional possibilities. – Mico May 18 '22 at 05:54
  • 1
    simply remove left and right which do nothing useful here and prevent the space being flexible and prevent line breaking https://tex.stackexchange.com/a/173740/1090 – David Carlisle May 18 '22 at 07:09
  • @DavidCarlisle If I remove the \left and \right, the slash is too short. – Y. zeng May 18 '22 at 07:32

1 Answers1

1

The main problem, as far as TeX's approach to typesetting is concerned, is that the contents of the \left...\right chunk form a "mathinner" math atom that can never be line-broken.

The first order of business, is to replace

$\left.(\ce{Mg^2+}-\ce{PO4^2-})\right/\ce{HNO3-}$

with either

$\bigl(\ce{Mg^2+}-\ce{PO4^2-}\bigr)\big/\ce{HNO3-}$

or, even more simply,

$(\ce{Mg^2+}-\ce{PO4^2-})/\ce{HNO3-}$

in order to avoid creating a mathinner atom.

The second issue is that TeX, by default, won't allow line breaks at arbitary locations inside an inline-math expression. In particular, TeX won't allow line breaks immediately before - and + tokens. This can be adressed by inserting an \allowbreak directly immediately before -\ce{PO4^2-}.

enter image description here

However, this still isn't great, as the \ce{Mg^2+} term protrudes noticeably into the right-hand margin. This issue is most easily fixed -- unless you employ XeLaTeX -- by loading the microtype package, can adjust the inter-word spacing of characters as needed. I added "unless you employ XeLaTeX" because microtype works best under pdfLaTeX and LuaLaTeX.

enter image description here


\documentclass{article}
\usepackage{mhchem}
\usepackage{lipsum}

%\usepackage{microtype} % uncomment as needed

\begin{document}

fsadjlllllllllllllllllllllllllllllllllllllllllllsafddddddddddddddddddddddddlllllll $\left.(\ce{Mg^2+}-\ce{PO4^2-})\right/\ce{HNO3-}$ Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus.

fsadjlllllllllllllllllllllllllllllllllllllllllllsafddddddddddddddddddddddddlllllll $(\ce{Mg^2+}-\ce{PO4^2-})/\ce{HNO3-}$ Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus.

fsadjlllllllllllllllllllllllllllllllllllllllllllsafddddddddddddddddddddddddlllllll $(\ce{Mg^2+}\allowbreak-\ce{PO4^2-})/\ce{HNO3-}$ Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus.

\end{document}

Mico
  • 506,678
  • Hello. Do you find that if use \right/, there is too wide blank between the / and the next charcter? And is there a way to make / increase to higher as the left or the right of it become higher? – Y. zeng May 18 '22 at 06:17