Sometimes I want to write mathematics (like \in - is an element of).
While the element-sign is shown, LaTeX shows errors when compiling saying:
Missing $ inserted.
Extra }, or forgotten $.
Missing } inserted.
When then surrounding any \in with \[ and \] it adds a blank line before and after the line containing \in. I only want to have the simple sign, not the additional space.
This is my code without \[...\] around the \in:
\documentclass[11pt, a4paper]{article}
\usepackage[portrait, margin=1in]{geometry}
\usepackage{amsmath}
\usepackage[linesnumbered,ruled]{algorithm2e}
\begin{document}
\begin{algorithm}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\underline{function myAlgo} $(G)$\;
\Input{A Graph $G = (V, E)$ with v in V}
\Output{nothing yet}
\tcp{does it for ever v in V}
doSth()\;
return $G$\;
\caption{Does sth for every vertex v \in V}
\end{algorithm}
\end{document}
$v \in V$. the\inmust be in math mode (the part inside$...$as you have already used correctly for$G = (V, E)$). since\inis recognized as math, tex will switch into math mode if it isn't already there, and will therefore report a missing$when it encounters something that can't be math. – barbara beeton Apr 21 '16 at 18:06