Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back-to-back math environments are parsed incorrectly #142

Open
masonproffitt opened this issue Feb 24, 2023 · 1 comment
Open

Back-to-back math environments are parsed incorrectly #142

masonproffitt opened this issue Feb 24, 2023 · 1 comment

Comments

@masonproffitt
Copy link
Contributor

For example:

>>> import TexSoup
>>> TexSoup.TexSoup(r'$1$$2$')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/__init__.py", line 87, in TexSoup
    parsed, src = read(tex_code, skip_envs=skip_envs, tolerance=tolerance)
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/tex.py", line 22, in read
    return TexEnv('[tex]', begin='', end='', contents=buf), tex
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/data.py", line 892, in __init__
    super().__init__(name, contents, args, preserve_whitespace, position)
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/data.py", line 641, in __init__
    self._contents = list(contents) or []
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/reader.py", line 52, in read_tex
    yield read_expr(buf,
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/reader.py", line 96, in read_expr
    return read_math_env(src, expr, tolerance=tolerance)
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/reader.py", line 213, in read_math_env
    contents.append(read_expr(src, tolerance=tolerance, mode=MODE_MATH))
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/reader.py", line 96, in read_expr
    return read_math_env(src, expr, tolerance=tolerance)
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/reader.py", line 213, in read_math_env
    contents.append(read_expr(src, tolerance=tolerance, mode=MODE_MATH))
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/reader.py", line 96, in read_expr
    return read_math_env(src, expr, tolerance=tolerance)
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/reader.py", line 215, in read_math_env
    unclosed_env_handler(src, expr, src.peek())
  File "/home/user/atlas/physics-office/src/TexSoup/TexSoup/reader.py", line 189, in unclosed_env_handler
    raise EOFError('[Line: %d, Offset: %d] "%s" env expecting %s. %s' % (
EOFError: [Line: 0, Offset: 5] "$" env expecting $. Reached end of file.
@JCGoran
Copy link

JCGoran commented Oct 20, 2023

I've narrowed down the issue to this piece of code:
https://github.com/alvinwan/TexSoup/blob/c91a14a0019ff7df197e71c906bc0403eddf80dc/TexSoup/tokens.py#L176C1-L181

The problem is that it checks for $$ first, but it isn't aware that it's already in (single-line) math mode, so it erroneously thinks it's entering display math mode instead. Not exactly sure how to fix this since it requires knowledge of state, which isn't passed to the function currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants