Comments (3)
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.
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.
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)
- Special characters treated as macros HOT 1
- Parsing commands containing "@" HOT 4
- parse LaTeX, replace $$ HOT 4
- Support for Python 3.7+
- various upgrades HOT 1
- how to instantiate LatexMacroNode? HOT 3
- suggestion for simpler/more correct MacroArgs
- nodelist_to_latex() doesn't respect node.environmentname HOT 1
- how to parse `\vrule height 2pt depth -1.6pt width 23pt` HOT 1
- how to parse `\def\enorm#1{\|#1\|_2}` HOT 1
- how to parse `\lstinline|code|` HOT 1
- macroname='SS' incorrectly translated HOT 1
- parse issue with `\newcommand{\be}{\begin{equation}}` HOT 3
- adapt LatexWalker context while walking HOT 1
- Input and output differs when converting a nodelist back into latex HOT 1
- Incorrect (?) parsing of content in `lstlisting` environment HOT 3
- Deprecation warning upon installation via pip HOT 1
- Any ideas to skip specific element in LatexWalker? HOT 1
- pylatexenc import latexpp NCArgsParser doesn't work HOT 1
- Exception when parsing macro definitions with multiple arguments HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylatexenc.