To prevent this, try not to use BBCodes. Use equivalent latex commands instead. For example, to get the same effect as $$ or $$, use \textbf{} and \textit{} commands, resp. Example:
$\color{green}{\text{\textbf}}\text{{Bold}}\;\Longrightarrow\;\textbf{Bold}$
$\color{green}{\text{\textit}}\text{{Italic}}\;\Longrightarrow\;\textit{Italic}$
$\color{green}{\text{\color}}\text{{red}}\{\color{green}{\text{\text}}\text{{Red Text}}\}\;\Longrightarrow\;\color{red}{\text{Red Text}}$ $\color{green}{\text{\href}}\text{{http://www.example.com/}}\{\color{green ... {Hyperlink}}$
*BBCodes: The codes you use in different forums to format your message, i. e. $\text{, , , [quote], [url],