TransWikia.com

How to automatically linebreak an inline math formula?

TeX - LaTeX Asked by lhk on October 2, 2021

Here is an example of a parbox that produces both an underfull and an overfull warning:

parbox{100pt}{A set of comparison triplets (T = { (i,j,l) | z_i ;is; more; similar; to; z_j; than; z_l}) is given.}

When rendered to pdf, it looks like this:

rendered formula

Apparently, parts of the formula can’t be broken up across multiple lines.
I would like to allow Latex to linebreak the text within the curly braces and to position it like the other text in the parbox. Is that possible?

I have searched for similar questions:

allowbreak works for me as well. I can define specific points at which the equation may be broken up. But how can I avoid sprinkling allowbreak everywhere in my math typesetting?
The following code works (well it still produces an underfull warning, but that’s my text content and has nothing to do with the inline formula) but is horrible to read and edit:

parbox{100pt}{A set of comparison triplets (T = { (i,j,l) | allowbreak z_i ; allowbreak is;  allowbreak more;  allowbreak similar;  allowbreak to;  allowbreak z_j; allowbreak than; allowbreak z_l}) is given.}

3 Answers

The general recommendation I give is to avoid long textual set builder notation: readers will be very tired when looking at the text and they'll have a hard time in isolating the closing brace.

A set $T$ consisting of comparison triplets $(i,j,l)$ such that $z_i$ 
is more similar to $z_j$ than $z_l$ is given.

However, if you use the set builder notation, it is not a set, but the set:

The set $T$ consisting of all comparison triplets $(i,j,l)$ such that $z_i$ 
is more similar to $z_j$ than $z_l$ is given.

If you insist in using the set builder notation, go back and forth in and out of math mode:

The set of comparison triplets $T={(i,j,l)mid z_i$ 
is more similar to $z_j$ than $z_l}$ is given.

enter image description here

I used twocolumn in order to emulate your problem. Note mid and not the simple | that has wrong spacing around it.

Alternative way: define a symbol.

documentclass[twocolumn]{article}

newcommand{MST}{mathrm{MST}}

begin{document}

Define the ternary relation ``is more similar to than'' on the positive integers
by stipulating that $MST(i,j,l)$ holds if and only if $z_i$ is more similar
to $z_j$ than $z_l$ and set
[
T={(i,j,l)mid MST(i,j,l)}
]

end{document}

enter image description here

Correct answer by egreg on October 2, 2021

You can just put text in textmode.

documentclass[12pt,a4paper]{article}
usepackage{amsmath}
begin{document}

parbox{100pt}{A set of comparison triplets $T={(i,j,l) | z_i$ is more similar to $z_j$ than $z_l}$ is given.}

end{document}

enter image description here

Answered by AboAmmar on October 2, 2021

Personally I think the set builder notation is appropriate, but stylistically, I would say this (or really anything this long) should be a displayed equation, simply because it's much easier to read that way than as an inline equation.

enter image description here

parbox{100pt}{
    A set of comparison triplets 
    [
        T = { (i,j,l) mid text{$z_i$ is more similar to $z_j$  than $z_l$}}
    ]
    is given.
}

(Note that I also changed it to use text for the text part of the equation, which requires including the amsmath package. Additionally, using mid instead of | puts the correct spacing around the vertical bar.)

That doesn't solve the overful/underfull hbox issue by itself, but by using the multline environment, also provided by amsmath, you can add line breaks yourself:

enter image description here

documentclass{article}
usepackage{amsmath}

begin{document}

parbox{100pt}{
    A set of comparison triplets 
    begin{multline*}
        T = { (i,j,l) mid text{$z_i$ is} 
        text{more similar to $z_j$} 
        text{than $z_l$}}
    end{multline*}
    is given.
}

end{document}

Admittedly, this still looks a little bit silly, but I'm hoping the 100pt column is just for the sake of the example and you actually have at least a little bit more space than that.

You can use to insert line breaks in the multline environment, but they have to be outside of any command, which is why I've had to put several separate text commands.

You can remove the * from multline* to give it an equation number. (I recommend always numbering displayed equations.) Also note that, for some reason, it's "multline" with one 'i', and not "multiline" as you might expect.

Answered by Nathaniel on October 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP