-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Powers #36
Comments
Hi, thanks for the issue. I've been thinking a bit about how to handle powers and subscripts but there are some edge cases I want to make sure that I can polish before providing support for these out of the box. Here is a simple solution you can use in the meantime: from pylatexenc import macrospec, latexwalker, latex2text
# define ^/_ for the parser as accepting a mandatory argument
lwc = latexwalker.get_default_latex_context_db()
lwc.add_context_category('powers', specials=[
macrospec.SpecialsSpec('^', args_parser=macrospec.MacroStandardArgsParser('{')),
macrospec.SpecialsSpec('_', args_parser=macrospec.MacroStandardArgsParser('{')),
])
# define the replacement string for ^
l2tc = latex2text.get_default_latex_context_db()
l2tc.add_context_category('powers', specials=[
latex2text.SpecialsTextSpec('^', simplify_repl='^(%s)'),
latex2text.SpecialsTextSpec('_', simplify_repl='_(%s)'),
])
latex_text = r'e^{x_1}'
lw = latexwalker.LatexWalker(latex_text, latex_context=lwc)
l2t = latex2text.LatexNodes2Text(latex_context=l2tc)
print(l2t.nodelist_to_text(lw.get_latex_nodes()[0]))
# e^(x_(1)) The above code has the following caveats:
I'm currently thinking about some ideas for ways to avoid these caveats, in order to support |
Thank you! |
Hi @nemeer, I think your issue is an inherent limitation of Unicode—as far as I know, there is no way to represent |
Thanks a lot for the update. |
Could this special subset then be replaced? |
+1! Having θᵢ would be nice |
Thanks for the pointer to the list of unicode sub/superscripts. For the reasons that were mentioned above, it isn't straightforward to implement this. I'm thinking about some upgrades to how LaTeX gets converted to unicode text, and I'll try to integrate unicode super/subscripts as much as possible. (Plus, there would be additional design decisions, e.g., what should happen to subscripts where not all characters have a unicode subscript variant, such as |
How i can get
e^(2x)
?Thanks.
The text was updated successfully, but these errors were encountered: