# Word wrap in \text{} in math mode

I'm trying to type formula, which requires some textual comments. I perform this using \text{} command in math mode. However, word wrap doesn't work. What should I do? Code sample:

$P^1_{r,s}=\sum\limits_{i=r}^n{P(i\text{ applicant is selected and is the best})}=\sum\limits_{i=r}^n{P(i\text{ applicant is the best})*P(i\text{ is selected | is the best})}.$.


As you can see on the screenshot, no word wrap is used and the line is cut. Thanks in advance.

-
Try using a parbox around the \text command –  Christian Hupfer Apr 13 at 19:33

I would type the formula as displayed:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\noindent Text before.
\begin{align*}
P_{r, s}^{1}
&= \sum_{i = r}^{n} P(\text{$i$ applicant is selected and is the best})\\
&= \sum_{i = r}^{n} P(\text{$i$ applicant is the best}) \cdot P(\text{$i$ is selected $\mid$ is the best})
\end{align*}
Text after.

\end{document}


If you want to left-align the equations, you can do the following:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\noindent Text before.
\begin{flalign*}
P_{r, s}^{1}
&= \sum_{i = r}^{n} P(\text{$i$ applicant is selected and is the best}) &\\
&= \sum_{i = r}^{n} P(\text{$i$ applicant is the best}) \cdot P(\text{$i$ is selected $\mid$ is the best})
\end{flalign*}
Text after.

\end{document}


-
Thanks, your answer is also helpful. Sorry, cannot upvote now, my rating is lower than 15. –  Kirill Smirnov Apr 13 at 19:52

TeX inserts breakpoints after binary and relational operators with penalties \binoppenalty and \relpenalty. However, subformulas cannot be broken across lines. A pair of curly braces create a subformula as in the example of the question. Therefore the * does not create a breakpoint.

If you want breakpoints inside the text part of the formula, then the text can be given outside math.

The following example forces line breaks at the breakpoints by putting the examples into a too narrow minipage:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\begin{document}

\begin{minipage}{1mm}
$P^1_{r,s}=\sum\limits_{i=r}^n{P(i\text{ applicant is selected and is the best})}=\sum\limits_{i=r}^n{P(i\text{ applicant is the best})*P(i\text{ is selected | is the best})}$.
\end{minipage}

\smallskip\hrule\smallskip

% Remove subformula
\begin{minipage}{1mm}
$P^1_{r,s}=\sum\limits_{i=r}^n{P(i\text{ applicant is selected and is the best})}=\sum\limits_{i=r}^n{P(i\text{ applicant is the best})}*{P(i\text{ is selected | is the best})}$.
\end{minipage}

\smallskip\hrule\smallskip

% Text outside math
\begin{minipage}{1mm}
$P^1_{r,s}=\sum\limits_{i=r}^n P(i$ applicant is selected and is
the best$)=\sum\limits_{i=r}^n P(i$  applicant is the best$) * P(i$
is selected | is the best$)$.
\end{minipage}

\end{document}


-
Thanks for detailed answer! –  Kirill Smirnov Apr 13 at 19:51