Giter VIP home page Giter VIP logo

Comments (3)

dlaidig avatar dlaidig commented on July 29, 2024 1

Thanks! I have tested the master branch and can confirm that the parsing error is gone. :)

I also noticed that now (and also with my proposed workaround) the resulting node representation is kind of screwed up and subsequent latex code is still regarded as belonging to the \newenvironment command. Do to coincidence, this does not bother me in my special use case, so I am happy as soon as I can parse the file without exceptions.

I guess in general it is still desirable to be able to parse \newenvironment properly and represent \begin and \end commands in the arguments in some reasonable way.

FYI: My use case is a LaTeX to text script that supports all the special macros I usually use and can handle includes with the standalone package. That includes some hacks to throw away the preambles from imported documents and lots of special formatters for custom commands. So in this case, I do not want \newcommand definitions to be parsed and applied like latexpp does, but I am perfectly happy with having a parsed node list that I can transform as needed.

from pylatexenc.

phfaist avatar phfaist commented on July 29, 2024

Hi and thanks for the report. There are two points to unpack here.

First, you're seeing an error mainly because pylatexenc does not really support the \newcommand/\newenvironment family of commands (see my comment in issue 48). It attempts to parse the arguments to \newenvironment like LaTeX blocks of text; it doesn't record in any way the new command or new environment for future parsing. In most cases you might not see any errors in tolerant parsing mode, but what really happens is that the \newcommand/\newenvironment instruction gets ignored (it gets parsed as a simple macro node and then converted to empty text), and then later in the document custom macros are handled using the default behavior for unknown macros or environments (which might or might not give you the desired behavior). I have plans for better support of \newcommand/\newenvironment commands, but they haven't been fully implemented yet. I've written some (experimental) code in my other project latexpp that expands some commands defined by \newcommand/\newenvironment. Depending on your use case, you might be able to reuse some code from https://github.com/phfaist/latexpp/blob/master/latexpp/fixes/newcommand.py for your purposes.

On the other hand, the additional exception you're seeing ("AttributeError: 'LatexWalkerEndOfStream' object has no attribute 'open_contexts'") is a bug and I'll look to fix it. Thanks for reporting.

from pylatexenc.

phfaist avatar phfaist commented on July 29, 2024

My latest commit should fix the weird chained exception that you reported. I'm leaving the issue open as an enhancement to enable \newenvironment wrapping another environment. This should be support once I get the \newcommand family of friends supported. (See also #48.) Thanks for reporting!

from pylatexenc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.