[Tex/LaTex] Text crossing the page margin in math environment

line-breakingmath-mode

I have some long text (a single sentence) which I want to put inside a math environment. But my text just goes accros the page margin and ignores the textwidth specification given in the preamble.
Here is a toy example:

\documentclass[12pt]{article}

\setlength{\textwidth}{500pt}
\setlength{\parindent}{0pt}
\setlength{\textheight}{8in}
\usepackage{latexsym,amssymb}
\usepackage{amsmath,array}
\usepackage[margin=1in,headsep=2.5cm]{geometry}

\begin{document}

\begin{math}
2+1=3\\
2+2=4\\ 
{\text{This is some very very very very very very very very very very very 
very very very very very very very very long text in math environment.}} 
\end{math}

\end{document}

Obviously I could just break the line manually but there should be some better way of Latex doing that automatically?

Best Answer

The math environment is for inline math, I would not use it for multiline math. Also, I would not force multiline text into a math environment. I would leave the math environment, print the text, start a math environment again. A math environment is not the best place for long text.

Your example can be fixed using \parbox, such as

\begin{math}
2+1=3\\
2+2=4\\ 
\parbox{\textwidth}{This is some very ... very long text in math environment.}
\end{math}

This way there would be line breaks with full justification.

But I would either end math mode or use a displayed math environment. You are already using amsmath. In this case I recommend to

  • use an align environment or alike,

  • use \intertext to temporarily escape the math environment for long text,

  • use \text just for short text within math.