4

When writing in a minipage environment, unsplittable math formulas never spill into the right margin. Instead, spacing is introduced in the current line and the formula is moved to the next line.

However, doing the same in free flowing "top level" text results in a visually most unappealing overflow, see example below.

I had a look at the manual penalties, but nothing seems to fit. How do I reproduce the minipage overflow behaviour everywhere else?

\documentclass[a4paper]{letter}    
\begin{document}    
\begin{minipage}{12cm}
This is an example paragraph inside a \textit{minipage} showing how text 
    should flow, notice how nothing is pushed onto the margins:

\textbf{Lorem} ipsum dolor sit amet, consectetur adipisicing elit, sed do 
 tempor incididunt ut  et dolore magna aliqua. Ut enim ad minim veniam
 quodque $P, Q , R , S ,T \ldots, X, Y, Z$, quis nostrud exercitation ullamco.
\end{minipage}  
\vspace{2em}

This is an example paragraph without any sections inside the main document,
  and here the math environment overflows into the margin:

\textbf{Lorem} ipsum dolor sit amet, consectetur adipisicing elit, sed do 
 tempor incididunt ut  et dolore magna aliqua. Ut enim ad minim veniam
 quodque $P, Q , R , S ,T \ldots, X, Y, Z$, quis nostrud exercitation ullamco.  
\end{document}

Example

3
  • \sloppy will fix this case. – Steven B. Segletes Feb 11 '14 at 14:01
  • 1
    @StevenB.Segletes Usage of \sloppy is the last option (like usage of minipage, by the way). You can allow breaks at any place of the math (except inside groups) by \allowbreak command. The spaces in the first example are so huge! – yo' Feb 11 '14 at 14:44
  • @tohecz Maybe "fix" wasn't the right word to use. What I meant was that \sloppy would cause the top-level text to mimic the minipage. But you are right, the minipage is not appealing to look at. In fact, it is quite... sloppy. – Steven B. Segletes Feb 11 '14 at 14:47
3

Firstly you should compare like with like. If you use \showthe\linewidth on the main part of you document you will see that its value is 345.0pt which is slightly more than 12cm = 341.43306pt. The easiest way to make a genuine test is to write

\begin{minipage}{\linewidth}
 ...
\end{minipage}

Anyway, given that, you still get a similar difference in output. This is mostly caused by the fact that minipage calls \sloppy when it starts.

Going the opposite way to what you ask, you can undo that particular setting globally by

\makeatletter
\def\@minipagerestore{\fussy}
\makeatother

With these two changes

\documentclass[a4paper]{letter}    

\makeatletter
\def\@minipagerestore{\fussy}
\makeatother
\begin{document}    

\begin{minipage}{\linewidth}
This is an example paragraph inside a \textit{minipage} showing how text 
    should flow, notice how nothing is pushed onto the margins:

\textbf{Lorem} ipsum dolor sit amet, consectetur adipisicing elit, sed do 
 tempor incididunt ut  et dolore magna aliqua. Ut enim ad minim veniam
 quodque $P, Q , R , S ,T \ldots, X, Y, Z$, quis nostrud exercitation ullamco.
\end{minipage}  
\vspace{2em}

This is an example paragraph without any sections inside the main document,
  and here the math environment overflows into the margin:

\textbf{Lorem} ipsum dolor sit amet, consectetur adipisicing elit, sed do 
 tempor incididunt ut  et dolore magna aliqua. Ut enim ad minim veniam
 quodque $P, Q , R , S ,T \ldots, X, Y, Z$, quis nostrud exercitation
 ullamco.  

\end{document}

you get

Sample output

Notice that there is no space between the paragraphs in the minipage. This is because minipage sets \parskip to 0pt, but in letter class it is otherwise set to 6.99997pt.

A list of parameters that minipage sets as standard can be found in the source2e documentation. There you can read that it also sets to 0pt the following parameters

\parindent
\@totalleftmargin
\leftskip
\rightskip
\@rightskip

Additionally, it sets

\parfillskip = 0pt plus 1fil
\lineskip = \normallineskip
\baselineskip = \normalbaselineskip

\@listdepth = \@mplistdepth

the latter is initially 0, and @minipage is set to true: quite a number of commands check this last value during their operation and so behave differently in a minipage.

Anyway, the simplest way to get minipages linebreaking is to issue \sloppy, as Steven Segletes says. Of coures, now you are throwing away many of LaTeX's attempts to do good line breaking. In general it is better to fix the bad break. In this case, you should allow breaks at the commas in your mathematics expression:

\documentclass[a4paper]{letter}    

\begin{document}

\textbf{Lorem} ipsum dolor sit amet, consectetur adipisicing elit, sed
do tempor incididunt ut et dolore magna aliqua. Ut enim ad minim
veniam quodque $P,\allowbreak Q ,\allowbreak R ,\allowbreak S
,\allowbreak T,\allowbreak \ldots,\allowbreak X,\allowbreak
Y,\allowbreak Z$, quis nostrud exercitation ullamco.

\end{document}

Sample with breaking commas

To do this automatically see Allowing line break at ',' in inline math mode? and Break an inline math formula.

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.