pylatexenc icon indicating copy to clipboard operation
pylatexenc copied to clipboard

missing spec for \href{}{} in latexwalker

Open gamboz opened this issue 4 years ago • 4 comments

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))

gamboz avatar Mar 09 '21 11:03 gamboz

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.

phfaist avatar Mar 11 '21 09:03 phfaist

[ 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}}).

gamboz avatar Mar 15 '21 08:03 gamboz

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

phfaist avatar Mar 15 '21 08:03 phfaist