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

missing spec for \href{}{} in latexwalker #58

Open gamboz opened 3 years ago

gamboz commented 3 years ago

I think the spec for the macro \href might be missing from pylatexenc/latexwalker/_defaultspecs.py The following code gives error: it expects a node with two arguments, but gets a node with empty argnlist.

from pylatexenc.latex2text import LatexNodes2Text
latex = r"\href{a}{b}"
print(LatexNodes2Text().latex_to_text(latex))
phfaist commented 3 years ago

Thanks for reporting this. In LaTeX, the URL-related commands (like \href, \url, and \email) parse their URL argument in a special fashion to deactivate any special characters (such as $, _ or ^). So to implement them in pylatexenc requires a little more work to ensure that the URL argument is always parsed verbatim. I'm pretty busy at the moment but I'll try to find some time soon to implement them.

gamboz commented 3 years ago

[ suggestion, please feel free to ignore :) ] If you can change the parsing procedure based on the macro name, it might be a good idea also to ignore the second argument of \newcommands & co. As you know, these macro sometimes include the beginning or end of an environment, and the parser gets confused (as in \newcommand{\beq}{\begin{equation}}).

phfaist commented 3 years ago

Yes, I'm planning to improve the parsing of \newcommand instructions, too :)

xsank commented 3 months ago

Yes, I'm planning to improve the parsing of \newcommand instructions, too :)

looking forward to this...