#7051: [with patch, needs review] latex issues
------------------------+---------------------------------------------------
 Reporter:  jhpalmieri  |       Owner:  jhpalmieri
     Type:  defect      |      Status:  new       
 Priority:  minor       |   Milestone:  sage-4.1.3
Component:  misc        |    Keywords:            
 Reviewer:              |      Author:            
   Merged:              |  
------------------------+---------------------------------------------------

Old description:

> Here are several LaTeX issues:
>
>  - because of how Python works (I think), if you set {{{T =
> type(identity_matrix(3))}}}, then T has all of the methods of an identity
> matrix.  In particular, if you run {{{latex(T)}}}, the code calls
> {{{hasattr(T, '_latex_')}}}, and this returns True because
> {{{hasattr(identity_matrix(3), '_latex_')}}} is True.  But then
> {{{T._latex_()}}} produces a {{{TypeError}}}.  This is the cause of the
> error reported [http://groups.google.com/group/sage-
> support/browse_frm/thread/498eb1dae179fc3f here].
>
> Solution: catch {{{TypeError}}}s when calling {{{T._latex_()}}} in this
> sort of situation.
>
>  - In the notebook, try
> {{{
> %latex
> $\sage{type(35)}$
> }}}
> In this case, Sage typesets the string {{{<type
> 'sage.rings.integer.Integer'>}}}, but the < and > signs get converted
> into an upside-down exclamation point and question mark.
>
> Solution: typeset strings differently, using {{{\textttt}}} instead of
> {{{\text}}}.
>
>  - Click the "Typeset" button and try
> {{{
> type(35)
> }}}
> In this case, jsMath kicks in and tries to typeset {{{\text{<type
> 'sage.rings.integer.Integer'>}}}}, but the symbols < and > confuse jsMath
> -- it thinks they're part of an html command.  As a result, there is *no*
> output at all.
>
> Solution: for typesetting strings in jsMath, replace {{{\texttt}}} with
> {{{\hbox}}}.
>
>  - This comes from a Sage doctest:
> {{{
> sage: R.<x,y>=QQbar[]
> sage: latex(-x^2-y+1)
> -x^{2} - y + \text{1}
> }}}
> The {{{\text{1}}}} should not be there.
>
> Solution: The {{{\text{1}}}}  appears because the element 1 in R has no
> {{{_latex_}}} method, so it gets converted to a string, when then gets
> typeset by enclosing it in {{{\text}}}.  So test strings: if they consist
> only of digits, just return the string.  If it contains anything else,
> enclose in {{{\textttt}}}, as mentioned above.
>
> A patch will follow soon.

New description:

 Here are several LaTeX issues:

  - because of how Python works (I think), if you set {{{T =
 type(identity_matrix(3))}}}, then T has all of the methods of an identity
 matrix.  In particular, if you run {{{latex(T)}}}, the code calls
 {{{hasattr(T, '_latex_')}}}, and this returns True because
 {{{hasattr(identity_matrix(3), '_latex_')}}} is True.  But then
 {{{T._latex_()}}} produces a {{{TypeError}}}.  This is the cause of the
 error reported [http://groups.google.com/group/sage-
 support/browse_frm/thread/498eb1dae179fc3f here].

 Solution: catch {{{TypeError}}}s when calling {{{T._latex_()}}} in this
 sort of situation.

  - In the notebook, try
 {{{
 %latex
 $\sage{type(35)}$
 }}}
 In this case, Sage typesets the string {{{<type
 'sage.rings.integer.Integer'>}}}, but the < and > signs get converted into
 an upside-down exclamation point and question mark.

 Solution: typeset strings differently, using {{{\texttt}}} instead of
 {{{\text}}}.

  - Click the "Typeset" button and try
 {{{
 type(35)
 }}}
 In this case, jsMath kicks in and tries to typeset {{{\text{<type
 'sage.rings.integer.Integer'>}}}}, but the symbols < and > confuse jsMath
 -- it thinks they're part of an html command.  As a result, there is *no*
 output at all.

 Solution: for typesetting strings in jsMath, replace {{{\texttt}}} with
 {{{\hbox}}}.

  - This comes from a Sage doctest:
 {{{
 sage: R.<x,y>=QQbar[]
 sage: latex(-x^2-y+1)
 -x^{2} - y + \text{1}
 }}}
 The {{{\text{1}}}} should not be there.

 Solution: The {{{\text{1}}}}  appears because the element 1 in R has no
 {{{_latex_}}} method, so it gets converted to a string, when then gets
 typeset by enclosing it in {{{\text}}}.  So test strings: if they consist
 only of digits, just return the string.  If they contain anything else,
 enclose in {{{\texttt}}}, as mentioned above.

 A patch will follow soon.

--

Comment(by jhpalmieri):

 I'm attaching a patch which implements all of the solutions discussed
 above.  When applied to version 4.1.2.alpha4, this passes all doctests on
 sage.math.

 If you have questions about the design decision, say the appearance of
 strings typeset in {{{\texttt}}} vs. {{{\text}}}, well, for what it's
 worth, I tried to discuss some of these issues on
 [http://groups.google.com/group/sage-
 
devel/browse_thread/thread/ae85918789e25f3b/71d71887154151cb?tvc=2#71d71887154151cb
 sage-devel] a few months ago, but there was essentially no response.  With
 this version, typesetting Python strings via LaTeX will produce different
 looking output, but (a) I like the new look, and (b) this seemed like the
 best way to deal with symbols like <, >, and _.

 If necessary, we can split this into several tickets, because the first
 issue ({{{_latex_}}} method for types) is separate from the others.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7051#comment:1>
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to