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

LatexWalker.get_latex_nodes returns wrong "len" (sometimes) #49

Closed
gamboz opened this issue Nov 19, 2020 · 1 comment
Closed

LatexWalker.get_latex_nodes returns wrong "len" (sometimes) #49

gamboz opened this issue Nov 19, 2020 · 1 comment

Comments

@gamboz
Copy link

gamboz commented Nov 19, 2020

Working on the function that you proposed on #48, I came across a strange behavior: sometimes the len returned by the get_latex_nodes function is not the same as the len of the parsed node.
In the MWE below, the first node is a MacroNode and the pos and len reported by the function are the same as the attributes of the node itself, but for the second node (a CharsNode, the newline char), the function reports a len different from that of the node.

import pylatexenc.latexwalker

doc_content = r"""\emph{A}
\emph{B}"""
print(f"DOC: {doc_content}")

lw = pylatexenc.latexwalker.LatexWalker(
    doc_content,
    tolerant_parsing=False,
)

pos = 0
(tmp_list, npos, nlen) = lw.get_latex_nodes(pos, read_max_nodes=1)
node = tmp_list[0]
print(f"Node at pos {pos}: node len {node.len} == returned len {nlen}; OK")

pos = 8
(tmp_list, npos, nlen) = lw.get_latex_nodes(pos, read_max_nodes=1)
node = tmp_list[0]
print(f"Node at pos {pos}: node len {node.len} != returned len {nlen}; BAD")

By the way, with some minor tweaks, the function you proposed in #48 works well, thanks again 👍

@phfaist
Copy link
Owner

phfaist commented Nov 19, 2020

Wow, nice catch. I found the omission, fixed. The fix will be included in the next release. Thanks for reporting!

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