# Line Breaks in Text Mode not Working

This is a follow up from my previous question

I am writing a large document in LaTeX, part of which is giving me much grief.

Specifically, I have described an algorithm in several numbered steps. I have then given the pseudo code for this algorithm, in which I would like to reference these steps.

Sometimes, multiple lines of the pseudo code refer to one step in the algorithm description. As such, I would like to draw a big right brace (}) enclosing those lines, and label it with the step number.

From what I have learned from the LaTeX documentation, I have the following (relevant) snippets of code:

\documentclass[a4paper,11pt]{article}
\usepackage[pdftex]{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{verbatim}
\newcommand{\HRule}{\rule{\linewidth}{0.2mm}}
\begin{document}
\title{Single Source Multi-Commodity Network Flow}
\date{December 18, 2011}
\author{Ashwin Panchapakesan \\
University of Ottawa \\
Student Number: 6588301 \\
apanc006@uottawa.ca}
\maketitle

\section{Pseudo-code}
.

function getNeighbor(V,E, paths, dist)

\indent \indent extern A

\indent \indent u $\leftarrow$ NULL

\indent \indent n $\leftarrow$ NULL

\indent \indent while (u = NULL) DO

$\left. \text{ us \leftarrow \{ v \in V | \exists t \in T \cap v, \newline \} (\exists e \in E | v \in e, c(e) = \infty), \linebreak \linebreak \indent \indent \indent \indent routable(u, paths) if \exists u \in V | (u,v) \in E else routable(u, paths) \linebreak \indent \indent \indent \indent where (v,u) \in E, w(e) \leq dist \} \indent \indent \indent \indent where (v,u) \in E, w(e) \leq dist \} } \right\rbrace step \ref{getListofNodes}$

\indent \indent \indent // step \ref{getListofNodes}

\indent \indent \indent $us \leftarrow \{ v \in V | \exists t \in T \cap v,$

\indent \indent \indent \indent ($\exists e \in E | v \in e, c(e) = \infty$),

\indent \indent \indent \indent routable(u, paths) if $\exists u \in V | (u,v) \in E else$ routable(u, paths)

\indent \indent \indent \indent where (v,u) $\in E, w(e) \leq dist \}$

\indent \indent \indent U $\leftarrow$ max$_{\sum_{e \in paths.values} w(e)}$ \{ paths \} // step \ref{setU}

\indent \indent \indent  // step \ref{setU} begins

\indent \indent \indent if (U $\in$ us) then

\indent \indent \indent \indent u $\leftarrow$ U

\indent \indent \indent else

\indent \indent \indent \indent u $\leftarrow$ randomChoice(us)

\indent \indent \indent // step \ref{setU} ends

\indent \indent // step \ref{setN} begins

\indent \indent while (n = NULL) do

\indent \indent \indent ns $\leftarrow \{ v \in V | u \neq v,$ \linebreak
\indent \indent \indent \indent $(\exists e \in E | e=(u,v) \text{ or } e=(v,u), c(e) = \infty),$ \linebreak
\indent \indent \indent \indent $min_{w(e)} {e \in E | e=(u,v) \text{ or } e=(v,u)} \leq dist\}$

\indent \indent n $\leftarrow$ randomChoice(ns)

\indent \indent // step \ref{setN} ends

\indent \indent // step \ref{setR} begins

\indent \indent ress $\leftarrow$ \{$a_i \in A | t_i \in n$ \}

\indent \indent r $\leftarrow$ randomChoice(ress)

\indent \indent // step \ref{setR} ends

\indent \indent r $\leftarrow a_i$ for some $a_i \in A$

\indent \indent // step \ref{changeTerminal} begins

\indent \indent $t_i \leftarrow n$

\indent \indent $\forall e \in$ paths[r] do

\indent \indent \indent f(e) $\leftarrow$ f(e) - 1

\indent \indent // step \ref{changeTerminal} ends

\indent \indent // step \ref{changePath} beings \linebreak
\indent \indent p = min$_{\sum_{path}w(e)}$ \{ path $|$ path = paths[r], $\exists a_i \in A | r = a_i, t_i \in n$, \linebreak
\indent \indent \indent $\forall e \in paths[r] c(e)-f(e)>0$ \}

\indent \indent $\forall e \in p$ do

\indent \indent \indent \indent f(e) $\leftarrow$ f(e) + 1

\indent \indent paths[r] $\leftarrow$ paths[r] + min$_{w(e)}$ \{$e \in E |e=(u,n) or e=(n,u)$ \}

\indent \indent // step \ref{changePath} ends

\end{document}

My problem is that the \newlines and \linebreaks are not displayed in the output document - they do not produce a line break. Instead all the intended multiple lines are displayed on one line and are truncated at the page margins.

Also, I know that between \text{ and } is the text environment, just like between $and$ is the math environment. Could anyone please clarify the name of the environment within $and$?

I'd appreciate any help on how I can fix this.

Thank you

-

\newline and \linebreak have no effect inside \text. You should consider the tabbing environment. Here's the first part of your pseudo-code, that can be completed in the same way:

\documentclass[a4paper,11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{verbatim}
\newcommand{\HRule}{\rule{\linewidth}{0.2mm}}
\begin{document}
\title{Single Source Multi-Commodity Network Flow}
\date{December 18, 2011}
\author{Ashwin Panchapakesan \\
University of Ottawa \\
Student Number: 6588301 \\
apanc006@uottawa.ca}
\newcommand{\vv}[1]{\mathit{#1}}
\maketitle

\section{Pseudo-code}

\begin{tabbing}
\hspace*{20pt}\=\hspace*{20pt}\=\hspace*{20pt}\=\kill
function $\vv{getNeighbor}(V, E, \vv{paths}, \vv{dist})$ \\
\> extern $A$ \\
\> $u\leftarrow \mathrm{NULL}$ \\
\> $n$ $\leftarrow \mathrm{NULL}$ \\
\> while ($u = \mathrm{NULL}$) DO \\
$\left.\kern-\nulldelimiterspace \begin{minipage}{\textwidth} \begin{tabbing} \hspace*{20pt}\=\hspace*{20pt}\=\hspace*{20pt}\=\kill \>\>$\vv{us}\leftarrow \{ v \in V \mid \exists t \in T \cap v$\\ \>\>\> ($\exists e\in E \mid v \in e, c(e) = \infty$), \\ \>\>\>$\vv{routable}(u, \vv{paths})$if$\exists u \in V \mid (u,v) \in E$else$\vv{routable}(u,\vv{paths}$) \\ \>\>\> where$(v,u) \in E$,$w(e) \leq \vv{dist}$\\ \>\>\> where$(v,u) \in E$,$w(e) \leq \vv{dist}\}$\end{tabbing} \end{minipage} \right\rbrace\text{step \ref{getListofNodes}}$ \\
\>\> // step \ref{getListofNodes} \\

\>\> $\vv{us}\leftarrow \{ v \in V \mid \exists t \in T \cap v,$ \\
\>\>\> ($\exists e \in E \mid v \in e, c(e) = \infty$), \\
\>\>\> $\vv{routable}(u, \vv{paths})$ if $\exists u \in V \mid (u,v) \in E$ else $\vv{routable}(u,\vv{paths})$ \\
\>\>\> where $(v,u)\in E$, $w(e) \leq dist \}$\\
\>\> $U\leftarrow\max_{\sum_{e \in \vv{paths.values}} w(e)} \{ \vv{paths} \}$ // step \ref{setU} \\
\>\> // step \ref{setU} begins \\
\>\> if ($U \in \vv{us}$) then \\
\>\>\> $u\leftarrow U$ \\
\>\> else \\
\>\>\> $u\leftarrow \vv{randomChoice}(\vv{us})$ \\
\>\> // step \ref{setU} ends \\

[...]

\end{tabbing}
\end{document}

The wide brace is a bit tricky: it uses a nested tabbing environment in a minipage, exploiting the fact that a minipage that contains only a tabbing is as wide as necessary.

-
I've always been a fan of the tabbing environment. –  Marc van Dongen Feb 22 '12 at 0:58