#11498: Improve LaTeXing of strings
---------------------------+------------------------------------------------
Reporter: novoselt | Owner: jason, mpatel, was
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-4.7.1
Component: notebook | Keywords: sd31
Work_issues: | Upstream: N/A
Reviewer: | Author: Andrey Novoseltsev
Merged: | Dependencies:
---------------------------+------------------------------------------------
Comment(by jhpalmieri):
Overall, this looks pretty good, but it could use some work. Here are
some comments.
- in html.py, the comments "We work around a limitation of jsmath (it
can't typeset '\texttt')::" should be deleted, since those doctests don't
involve texttt anymore. (Do we even need to do the replacement
{{{s.replace('\\texttt','\\hbox')}}} now, or can that code be deleted?)
- in latex.py, for bool_function and None_function, "\mathrm{%s}" is
preferable to "{\rm %s}". Actually, I think we can just return
"\mathrm{%s}" always, regardless of notebook vs. command line
distinctions. Do you know why we had two versions for bool_function
before? It looks okay to me without the mbox...
- a few typos and rewordings:
{{{
#!diff
@@ -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"):
}}}
- another comment about the old code: I think that the output from
dict_function looks better with no extra space after the colon, so I would
suggest the following, but take a look yourself and see what you think:
{{{
#!diff
@@ -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\}"])
}}}
- Also, in JSMath().eval, if x is already a LaTeX expression, then
x=str(x) doesn't do anything, and neither does x=latex(x), so I think we
can simplify it more:
{{{
#!diff
@@ -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...
}}}
- Finally, the output in one of the doctests,
{{{
<html>...\verb|<type|\phantom{x}\verb|'sage.rings.integer.Integer'>|</span></html>
}}}
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.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11498#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.