# Combine code and math mode

So i want to insert some line of codes in a formula like in the picture below. What is the best way to do this properly?

• Will this be in an equation? Will it be part of a code segment? What is the main/underlying structure? My guess is its the latter (like an lstlisting). – Werner Dec 2 '18 at 16:58
• This should be an equation.I have tried something like \text{some code} in the mathmode but then the code is not structured well. – Nils Dec 2 '18 at 17:05
• Can you show us the used minimal working example (MWE) to produce this? – Skillmon Dec 2 '18 at 17:46

## 1 Answer

Here is a replication of the display inside an equation:

\documentclass{article}

\usepackage{amsmath,array}
\newcommand{\var}{\texttt}
\newcommand{\AND}{\wedge}

\newcommand{\curlylbrace}{\texttt{\symbol{123}}} % \{
\newcommand{\curlyrbrace}{\texttt{\symbol{125}}} % \}

\begin{document}

$\begin{array}{ l } \bigl( \var{max} \doteq 0 \AND \var{i} \doteq 0 \AND \var{i} < \var{a.length} \rightarrow \begin{array}[t]{ @{} l } [ \curlylbrace \begin{tabular}[t]{ >{\ttfamily}l } if(a[i] > max) max = a[i]; \\ i++; \\ while(i < a.length) \curlylbrace \\ \quad if(a[i] > max) max = a[i]; \\ \quad i++; \\ \curlyrbrace \end{tabular} \\ \curlyrbrace ] \psi_0) \end{array} \\ {} \AND (\var{max} \doteq 0 \AND \var{i} \doteq 0 \AND \var{i} \geq \var{a.length} \rightarrow [ \curlylbrace \curlyrbrace ] \psi_0 \bigr) \end{array}$

\end{document}