Repository: alvinwan/TexSoup

Issue:
$ and $$ math is not parsed
To reproduce:
```python
In [4]: list(TexSoup.read('$\lambda$').children)
Out[4]: [TexCmd('lambda$')]
```
Expected:
`$` and `$$` should be treated as paired delimiters and result in a correct environment.
TexSoup version:
0.0.3

Discussion:

Patch:
diff --git a/TexSoup/reader.py b/TexSoup/reader.py
index 6125322..c6012fa 100644
--- a/TexSoup/reader.py
+++ b/TexSoup/reader.py
@@ -136,11 +136,19 @@ def tokenize_math(text):
     >>> tokenize_math(b)
     '$$\\min_x$$'
     """
+
+    def escaped_dollar():
+        return text.peek() == '$' and result[-1] == '\\'
+
+    def end_detected():
+        return (text.peek((0, len(starter))) == starter
+                and not escaped_dollar())
+
     result = TokenWithPosition('', text.position)
     if text.startswith('$'):
         starter = '$$' if text.startswith('$$') else '$'
         result += text.forward(len(starter))
-        while text.hasNext() and text.peek((0, len(starter))) != starter:
+        while text.hasNext() and not end_detected():
             result += next(text)
         if not text.startswith(starter):
             raise EOFError('Expecting %s. Instead got %s' % (
@@ -267,4 +275,4 @@ def read_arg(src, c):
             content.append(read_tex(src))
         else:
             content.append(next(src))
-    return Arg.parse(content)
\ No newline at end of file
+    return Arg.parse(content)


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index de08b65..232daf0 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -216,6 +216,13 @@ def test_math_environment_whitespace():
     assert '\$' in contents[1], 'Dollar sign not escaped!'
 
 
+def test_math_environment_escape():
+    """Tests $ escapes in math environment."""
+    soup = TexSoup("$ \$ $")
+    contents = list(soup.contents)
+    assert '\$' in contents[0][0], 'Dollar sign not escaped!'
+
+
 def test_punctuation_command_structure():
     """Tests that commands for punctuation work."""
     soup = TexSoup(r"""\right. \right[ \right( \right|""")