# New environment error (question)

I'm trying to make a "custom" environment for my document, here's what i got

\documentclass[12pt]{article}
\usepackage{color}
\definecolor{01}{RGB}{0,95,200}
\newenvironment{custom}[2]{{\medskip\noindent\bf\color{01} #1}\\{\it #2 }}{}

\begin{document}

\begin{custom}{Observation}
$x\in Z(G)$ si y solo si $xy=yx$, para todo $y\in G$ si y solo si $N(x)=G$, si y solo si $\frac{o(G)}{o(N(x))}=1=|[x]|.$
\end{custom}

\end{document}


which had no problems, but in this case, since the text starts with a "$" symbol, i get an error, Extra }, or forgotten$. [$] Missing } inserted. [\end{custom}] Which i can avoid by putting everything on {} like \begin{custom}{a} {b} \end{custom}  But I was wondering if there is a way I can modify the \newenvironment to make it work without having to make any changes, thanks in advance. • \bf and \it are outdated commands, but that's not the cause of your problem: You define with 2 arguments but provide only one, the second tries to read $, getting you into troubles – user31729 Jan 25 '18 at 8:10
• what is the optimal or more up to date command for bold letters? – Zigisfredo Jan 25 '18 at 8:12
• and how do i fix the arguments? i'm quite lost there, i think it was fine in the arguments – Zigisfredo Jan 25 '18 at 8:13
• I've posted a possible answer, but I think you should use a theorem like environment rather than a \newenvironment here – user31729 Jan 25 '18 at 8:17
• oh, i wanted to, but i'll try to make some similar ones but with boxes, so i think this was the way to go. – Zigisfredo Jan 25 '18 at 8:31

As far as I understand, the environment body text should be typeset with \it (of course better with \itshape), so it is not the second argument #2 here, which is not needed.
In the given example of the O.P., there is no 2nd argument given, so LaTeX tries to read the $ from the body leading into errors. Use \bfseries instead of \bf and \textcolor{01}{#1} rather than \color{01} #1. \documentclass[12pt]{article} \usepackage{color} \definecolor{01}{RGB}{0,95,200} \newenvironment{custom}[1]{{\medskip\noindent\bfseries\textcolor{01}{#1}}% \itshape }{%End code -- empty here } \begin{document} \begin{custom}{Observation}$x\in Z(G)$si y solo si$xy=yx$, para todo$y\in G$si y solo si$N(x)=G\$, si y solo si $\frac{o(G)}{o(N(x))}=1=|[x]|.$