# How to start equation environment inside a custom environment?

Definition of env

\newenvironment{env}{
\setlength{\parindent}{0pt}%
\obeylines}


When I try to insert a equation it gives me an error.

\begin{env}
\begin{equation*}
\sin{x}
\end{equation*}
\end{env}


! Missing $inserted.$ l.68 \begin{equation*}

? ! Display math should end with $$. ^^M l.68 \begin{equation*} ? ! Missing  inserted.  l.69 \sin {dwa} ? ! Missing  inserted.  l.69 \sin{dwa} ? ! LaTeX Error: Bad math environment delimiter. See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ... l.70 \end{equation*} ? ! Missing  inserted.  l.70 \end{equation*} ? ! Display math should end with$$. \endgroup l.70 \end{equation*}

?

If I begin{equtation} outside of the env environment it doesn't give me and error. If I am unable to use env what can I do to achieve the same result?

edit

1.1    Definitions
reward = r_t at timestep t
behaviour policy =π=P(a|s)
observation = s
set of legal game actions =A={1,...,K}
action = a
optimal action-value function = ~~


I'm not writing sentences therefore I need to \linebreak.

• Perhaps some additional context would help here. What is env supposed to do in terms of your output? Why not just use equation* as-is outside of env?
– Werner
Nov 15, 2019 at 0:27
• the environment definition is unrelated to the error you would get the same error if you just had \obeylines before the equation in the main document. Nov 15, 2019 at 0:46

\obeylines makes every line an end of paragraph and you can not end a paragraph in math mode, what would you want \obeylines to do in display math?

The error is unrelated to the env environment, you get the same error from

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\obeylines
\begin{equation*}
\sin{x}
\end{equation*}
\end{document}


You could remove the \obeylines (and add back the missing end environment code)

\newenvironment{env}{
\setlength{\parindent}{0pt}%
}
{}


But display math should never be at the start of the paragraph (TeX adds a spurious blank initial line in that case) so this environment could not be used in many contexts.

• If i can't use \obeylines should I just use \\  for the entire document? Nov 18, 2019 at 2:48
• @Neptune you haven't said what you are trying to do so I can't say. It is incredibly rare to use either construct. Automatic linebreaking is one of the most important and distinctive functions of a typesetting system and you are asking whether to disable it with \obeylines or \\  unless you are typesetting poetry and the line breaks are part of the creative input and must be set manually, why do you want to do this at all? Nov 18, 2019 at 7:42
• I'm not writing sentences. I'm enumerating through definitions and equations so I think I need to \linebreak. Nov 18, 2019 at 10:55
• @Neptune I see no reason why you would use \linebreak, each definition would normally be a paragraph so you just need a blank line, let tex do the linebreaking if the text of a definition is longer than a line, But as you have shown no example document it is hard to say. Nov 18, 2019 at 10:57