pylatexenc
pylatexenc copied to clipboard
how to instantiate LatexMacroNode?
I'm trying to change
{\it text}
to
\textit{text}
with pylatexenc. To this end, I need create a LatexMacroNode
from a LatexGroupNode
. I tried
new_node = LatexMacroNode("textit", nodeargd=groupnode.nodelist[1:])
print()
print("xx", new_node)
print(nodelist_to_latex([new_node]))
but this fails with
AttributeError: 'list' object has no attribute 'argspec'
I'n not sure how to properly instantiate LatexMacroNode
Okay, I've gotten to
new_node = LatexMacroNode(
macroname="textit",
nodeargd=ParsedMacroArgs(
argspec="{",
argnlist=node.nodelist[1:],
),
)
nodelist_to_latex
will print
\textitipsum dolor
so there are {}
missing. Not sure if I need to add delimiters
or instead of node.nodelist[1:]
somehow provide a LatexGroupNode
.
I think I got it:
new_node = LatexMacroNode(
macroname="textit",
nodeargd=ParsedMacroArgs(
argspec="{",
argnlist=[LatexGroupNode(nodelist=node.nodelist[1:])],
),
)
The function nodelist_to_latex()
should not be relied upon. See my comment in #89. I'm hoping to add the ability to regenerate latex code from a node's properties in the future. In the meantime, my sister project latexpp might provide an alternative.