phfaist / pylatexenc

Simple LaTeX parser providing latex-to-unicode and unicode-to-latex conversion
https://pylatexenc.readthedocs.io
MIT License
283 stars 35 forks source link

IndexError: list index out of range #99

Open turian opened 11 months ago

turian commented 11 months ago

I found some hideous latex unfortunately.

 % latex2text index.html.pd.tex
Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/bin/latex2text", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__main__.py", line 214, in main
    print(ln2t.nodelist_to_text(nodelist), **print_kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.py", line 1056, in nodelist_to_text
    s += self.node_to_text(node, textcol=textcol)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.py", line 1089, in node_to_text
    return self.environment_node_to_text(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.py", line 1207, in environment_node_to_text
    return self.nodelist_to_text(node.nodelist)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.py", line 1056, in nodelist_to_text
    s += self.node_to_text(node, textcol=textcol)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.py", line 1086, in node_to_text
    return self.macro_node_to_text(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.py", line 1185, in macro_node_to_text
    macrostr = get_macro_str_repl(node, macroname, mac)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.py", line 1176, in get_macro_str_repl
    return self.apply_simplify_repl(node, mac.simplify_repl,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/__init__.py", line 1346, in apply_simplify_repl
    r = simplify_repl(node, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/lib/python3.11/site-packages/pylatexenc/latex2text/_defaultspecs.py", line 194, in <lambda>
    '{} <{}>'.format(l2tobj.nodelist_to_text([n.nodeargd.argnlist[1]]),
                                              ~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
(base)
(base) joseph@JosephsacStudio arxiv-vanity % latex2text --version
pylatexenc 3.0alpha000018
turian commented 11 months ago

You can try yourself with this gnarly latex:

wget https://gist.githubusercontent.com/turian/17f006e25e0b5d6ea2adce7ac90c889f/raw/24704ef27fdf8b4361647d08f50d86d0d2fae0f2/gistfile1.txt
latex2text gistfile1.txt
user202729 commented 3 months ago

Duplicate of https://github.com/phfaist/pylatexenc/issues/58