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)

$ 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
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|""")

pip install -e .
parse_log_pytest
requirements.txt
pytest coverage coveralls
apt-get update apt-get install -y gcc
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi==2025.1.31
charset-normalizer==3.4.1
coverage==3.7.1
coveralls==1.1
docopt==0.6.2
exceptiongroup==1.2.2
idna==3.10
iniconfig==2.1.0
packaging==24.2
pluggy==1.5.0
pytest==8.3.5
requests==2.32.3
-e git+https://github.com/alvinwan/TexSoup.git@b95820ac9f507916ce0a777cfcefe003ceb10c20#egg=TexSoup
tomli==2.2.1
urllib3==2.3.0

name: TexSoup
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - coverage==3.7.1
      - coveralls==1.1
      - docopt==0.6.2
      - exceptiongroup==1.2.2
      - idna==3.10
      - iniconfig==2.1.0
      - packaging==24.2
      - pluggy==1.5.0
      - pytest==8.3.5
      - requests==2.32.3
      - tomli==2.2.1
      - urllib3==2.3.0
prefix: /opt/conda/envs/TexSoup

tests/test_parser.py::test_math_environment_escape
TexSoup/__init__.py::TexSoup.TexSoup TexSoup/data.py::TexSoup.data.TexArgs TexSoup/data.py::TexSoup.data.TexArgs.__repr__ TexSoup/data.py::TexSoup.data.TexArgs.__str__ TexSoup/data.py::TexSoup.data.TexCmd TexSoup/data.py::TexSoup.data.TexEnv TexSoup/data.py::TexSoup.data.TexNode.__match__ TexSoup/reader.py::TexSoup.reader.next_token TexSoup/reader.py::TexSoup.reader.tokenize TexSoup/reader.py::TexSoup.reader.tokenize_math TexSoup/reader.py::TexSoup.reader.tokenize_string TexSoup/utils.py::TexSoup.utils.Buffer TexSoup/utils.py::TexSoup.utils.Buffer.__getitem__ TexSoup/utils.py::TexSoup.utils.Buffer.backward TexSoup/utils.py::TexSoup.utils.Buffer.forward TexSoup/utils.py::TexSoup.utils.to_buffer tests/test_parser.py::test_commands_only tests/test_parser.py::test_commands_envs_only tests/test_parser.py::test_commands_envs_text tests/test_parser.py::test_text_preserved tests/test_parser.py::test_command_name_parse tests/test_parser.py::test_commands_without_arguments tests/test_parser.py::test_unlabeled_environment tests/test_parser.py::test_ignore_environment tests/test_parser.py::test_inline_math tests/test_parser.py::test_escaped_characters tests/test_parser.py::test_basic_whitespace tests/test_parser.py::test_whitespace_in_command tests/test_parser.py::test_math_environment_whitespace tests/test_parser.py::test_punctuation_command_structure tests/test_parser.py::test_unclosed_environments tests/test_parser.py::test_unclosed_math_environments tests/test_parser.py::test_arg_parse
TexSoup/reader.py
TexSoup/reader.py