Decide what to do about automatic translation of text to latex
Split from #88
Currently, when using the latex printer, code like the following gets promoted to LaTeX, via the _texify function, and some post-processing in printer.tex looking for the LHS of equals signs:
print('grad | a =', grad | a)
print((grad | a).Fmt(title='grad | a ='))
Right now, this post-processing does not apply to Jupyter notebooks.
In his branch, @abrombo removed support for this. From slack:
Eric Wieser Yesterday at 11:57 AM @Brombo, was it your intent to remove the texification support from the printer? (edited) 9 replies
Eric Wieser 1 day ago Namely, the current behavior of translating
a | grad ^ grad * btoa \cdot \boldsymbol{\nabla} \W \boldsymbol{\nabla} b(edited)Eric Wieser 1 day ago I ask because all of your attempts at a "new printer" appear to remove it, and I wanted to check this was a deliberate decision
Brombo 23 hours ago I think you are referring to my removing the using of special symbols for standard latex macros that is
^instead of\wedgeetc. Since we can have a set of latex macros I would rather have all annotation in pure latex and define latex macros to make annotation easier rather than having a special post processor for the 'latex' annotations so that the user would use\Winstead of^to represent\wedgeand all the other special symbols that I had defined for latex annotations. Let latex do all the processing and simplify the code.Eric Wieser 23 hours ago I think we're talking about the same thing, yes. The advantage of the old style is that you get nice plaintext output too, when
print("grad | a = ", g)really is just a regular print statement (edited)Brombo 23 hours ago I forgot about plain text since I am so enamored of latex. Which symbols if any in plain text would have to be escaped to print correctly? I forget. Is the point to have the plain tex annotation look as much like the latex annotation as possible? They would only be the same for very simple annotations.
Brombo 22 hours ago I though my post processing code for the annotations was really ugly and I don't know how robust it was. Could you suggest a better way. Do you know how the use the regular expression parser (are you a grepmeister) to accomplish what my ugly code did in both plain text and latex. (edited)
Eric Wieser 21 hours ago
Is the point to have the plain tex annotation look as much like the latex annotation as possible?
The point is to have one piece of code produce either LaTeX or plaintext output, without having to change anything
Eric Wieser 21 hours ago
I though my post processing code for the annotations was really ugly and I don't know how robust it was. Could you suggest a better way?
Yes, i rewrote that a few days ago. Have a look at the
_texifyfunction in master. It's still a little fragile, but I fixed the obvious robustness issues (edited)Eric Wieser 21 hours ago The source for
_texifyis here: https://github.com/pygae/galgebra/blob/master/galgebra/printer.py#L772-L794
We should either:
- Commit to removing it entirely
- Add support to it in jupyter too, by adding a class like:
class MaybeTex:
def __init__(self, value):
self.value = value
def _latex(self, printer):
return _texify(self.value)
def __str__(self):
return self.value
The point is to have one piece of code produce either LaTeX or plaintext output, without having to change anything
Yes, I strongly agree that this is the core reason for us to keep this functionality. I'm OK with the MaybeTex idea.