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
Improve LaTeXing of strings #11498
Comments
comment:1
Attachment: String_LaTeXing_--_Sage.pdf.gz I still need to work on these failures:
|
This comment has been minimized.
This comment has been minimized.
comment:3
By the way, the issue of this ticket was discussed here: http://groups.google.com/group/sage-devel/browse_thread/thread/9aee79aaa40c8390/e5d55c0b800775b1 So John is cc-ed due to his explicit request, hint-hint ;-) |
comment:4
Overall, this looks pretty good, but it could use some work. Here are some comments.
@@ -239,7 +239,7 @@ def str_function(x):
If ``x`` contains only digits with, possibly, a single decimal point and/or
a sign in front, it is considered to be its own representation. Otherwise
each line of ``x`` is wrapped in a ``\verb`` command and these lines are
- assembled in a left-justified array. This gives to complicated string the
+ assembled in a left-justified array. This gives to complicated strings the
closest look to their "terminal representation".
.. warning:: Such wrappers **cannot** be used as arguments of LaTeX
@@ -289,7 +289,7 @@ def str_function(x):
# There is a bug in verb-space treatment in jsMath...
spacer = "\\phantom{%s}"
# \phantom{\verb!%s!} is more accurate and it works, but it is not a valid
- # LaTeX and may cause problems, so let's live with the above variant untill
+ # LaTeX and may cause problems, so let's live with the above variant until
# spaces are properly treated in jsMath/MathJax and we don't need to worry.
lines = []
for line in x.split("\n"):
@@ -334,12 +334,10 @@ def dict_function(x):
\left[\sin\left(z^{2}\right), \frac{1}{2} \, y\right]\right\}
"""
return "".join([r"\left\{",
- ", ".join(r"%s :\: %s" % (latex(key), latex(value))
+ ", ".join(r"%s : %s" % (latex(key), latex(value))
for key, value in x.iteritems()),
r"\right\}"])
@@ -1680,11 +1681,7 @@ class JSMath:
sage: JSMath().eval(type(3), mode='inline')
<html>...\verb|<type|\phantom{x}\verb|'sage.rings.integer.Integer'>|</span></html>
"""
- # If x is already a LaTeX expression, i.e. the output of latex(blah),
- # we will treat it as a string, so that we can see the code itself.
- if isinstance(x, LatexExpr):
- x = str(x)
- # Now get a regular LaTeX representation of x...
+ # Get a regular LaTeX representation of x...
looks like bad latex: the "<" inside of the \verb environment shouldn't be typeset correctly, but it actually seems to work. I wonder why... When we switch to MathJax (#9774), we'll have to redo some of this. |
comment:5
Thanks for the comments! I don't know why there are differences for different modes, this is the first time I am working with these modules. I agree that the fewer are differences the better and will also remove the extra space. Here is the reason for extra string conversion:
As I understand, the idea is that when user types Regarding |
Updated version. |
comment:6
Attachment: trac_11498_improve_string_LaTeXing.patch.gz I'm mostly happy with this. Here's a slightly different version (a full patch plus a patch showing the difference between the old one and the new one); I think this does a better job of preserving the original behavior with respect to combinatorial free modules. If you're happy with my changes, feel free to mark this as "positive review". |
Reviewer: John Palmieri |
Attachment: trac_11498_LaTeX.patch.gz new version; apply only this patch |
Attachment: trac_11498_delta.patch.gz for reference only; difference between old patch and new one |
comment:7
Hi John, would you mind explaining to me how does your code work? I am not very familiar with regular expressions. Also, how did you notice the new patch? It kind of annoys me that trac does not send messages when there are new patches attached to the tickets, so I usually leave some comment to trigger it. This time I was waiting since I didn't yet run tests on the whole library to see if anything got broke ;-) |
comment:8
I happened to take a look at the ticket, so I saw the new patch; mine is based on that one. The documentation for regular expressions in Python is here. In the code
the second and third lines are the ones involving regular expressions. Line 3 is a search-and-replace command: it searches the argument s for a pattern There is one subtlety in this: the standard way to refer to any string of characters is
if we used
|
comment:9
Thank you! All tests pass, positive review! |
This comment has been minimized.
This comment has been minimized.
Merged: sage-4.7.2.alpha0 |
comment:14
See #12156 for a related ticket. |
See the attached PDF for an example of a class that has no
_latex_
. All commands are repeated twice, one with Sage-4.7 and the second one with the patch applied. In both cases typeset checkbox on the top of the worksheet was tuned on.Also, I invite you to try
in the notebook with typeset mode on before and after the patch - such situations are precisely the ones that I wanted to solve (they are so bad, that printout does not reflect them accurately).
It is possible that user classes will not have customized latex method and there are some standard classes that use their string representation. If this representation includes multiple lines, the result in most cases is not very good and sometimes quite horrible, making it unpleasant to use the notebook in typeset mode. The patch aims to fix this situation and clean up latex module along the way.
The major change is in
sage.latex.str_function
. Alsosage.latex.JSMath.eval
is simplified a bit and does not alter the code almost at all anymore. The rest are mostly doctest adjustments and some code clean-up and simplifications which happened while I was going through it to understand how it works.Apply:
CC: @kcrisman @jhpalmieri
Component: user interface
Keywords: sd31
Author: Andrey Novoseltsev
Reviewer: John Palmieri
Merged: sage-4.7.2.alpha0
Issue created by migration from https://trac.sagemath.org/ticket/11498
The text was updated successfully, but these errors were encountered: