# How to typeset a multiline text in math environment?

I am using lhs2TeX to render Haskell code in LaTeX. It preprocesses the code into complex LaTeX code which is rendered (in one mode of operation) in math environment. Now, I have in this code also comments which are longer than one line. And would like to render them in a way that LaTeX wraps correctly lines as they get to the edge of the page.

So my question is, how can I insert a multiline text in math environment at a given current place (not just at the beginning of the line, but also indented, for example) so that it spans to the edge of the page automatically. minipage environment works nicely, but I have to manually specify its width. I would like to see this done automatically, based on the current location of the beginning of the minipage, to the edge of the page. Is this possible? How can I get current position on the page so that I could calculate needed height?

-
Hi Mitar, welcome to TeX.SE. Can you give some examples of the automatically generated code that you have and what you would rather have? It's hard to answer this question otherwise. –  Matthew Leingang Apr 5 '11 at 17:17

the amsmath package has a command \allowdisplaybreaks that, if specified in the preamble, will allow any (unboxed) multi-line display structure defined in amsmath to break at the end of a page.

although this command is best used immediately before the \\ where the "optimum" break would be, that requires manual intervention, and since your code is generated by an automatic procedure, that's not convenient.

information given in this question is also relevant.

-
Yes, but the first question is which environment should I use to even get a multi-line text. For example, by default, lhs2TeX is using mbox. –  Mitar Apr 5 '11 at 17:44

In the next example code I defined, with the help of a \parbox, a command \MyText with one optional argument (the indentation of the text, with a default value of 0pt) and with one mandatory argument (the text to be used); the width of the \parbox is automatically calculated as \textwidth minus the indentation used in the optional argument The idea is to use this command inside the \intertext command provided by the amsmath package.

\documentclass[a4paper]{article}
\usepackage{amsmath}

\newlength\myindent
\newlength\mycolwid

% syntax \MyText[<length>]{<text>} (default value for the optional argument: 0pt)
\newcommand\MyText[2][0pt]{%
\setlength\parindent{0pt}%
\setlength\myindent{#1}\setlength\mycolwid{\textwidth}%
\setlength\mycolwid{\dimexpr\textwidth-\myindent}%
\hspace*{\myindent}\parbox{\mycolwid}{#2}%
}

% a command to generate filler text for the example
\newcommand\test{text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text}
\begin{document}

\begin{align}
a &= b \\
\intertext{\MyText{\test}}
&=c
\intertext{\MyText[1in]{\test}}
&= d
\intertext{\MyText[2in]{\test}}
&= e.
\end{align}

\end{document}


-
Is it somehow possible to get current indent/position in text layout automatically? So that if I would already be positioned (for example with some other text/code) somewhere on the page, that I can say now at this place inserts a box which is as width as it is possible to the right and that text is wrapped as necessary. –  Mitar Apr 5 '11 at 20:39