pylatexenc
pylatexenc copied to clipboard
missing spec for \href{}{} in latexwalker
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))
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.
[ 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}}).
Yes, I'm planning to improve the parsing of \newcommand instructions, too :)