[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-22 Thread Andrey Novoseltsev
Hi Minh,

I probably was not very clear. I know how to change printed and
typeset version of a particular object that I create. What I don't
like is how just plain strings are typeset: if I put "123\n 23" in a
notebook cell in typeset mode and hit Shift-Enter, I will see "123 23"
in a pretty font, but on a single line. And as I understand, all
objects that don't have _latex_ will be typeset from _repr_ in the
same way - all newlines and indentations are gone. There are such
output examples in attachment to http://trac.sagemath.org/sage_trac/ticket/8694,
where I have fixed it for schemes by implementing _latex_. My point is
that if the default handling was a little bit more sophisticated, the
output of ALL objects without _latex_ would look better. And if a user
tries to output "123\n 23", then (s)he probably wants to have two
lines, no matter if the output is printed or typeset.

Hope this makes more sense ;-)
Andrey


On May 22, 10:07 pm, Minh Nguyen  wrote:
> Hi Andrey,
>
> On Sun, May 23, 2010 at 8:06 AM, Andrey Novoseltsev  
> wrote:
> > Hello,
>
> Just so that we are clear...
>
> > When strings or objects with only _repr_ are typeset, they are just
> > wrapped as a chunk of text. The main problem with it is removing line
> > breaks. Another one - removing indentation. For example, if "123\n 23"
> > is printed, we get
>
> > 123
> >  23
>
> ... the printed version is done handled by how __repr__ is defined to
> handle string representation of an object.
>
> > with 23 right under 23. The typeset version gives
>
> > 123 23
>
> And the LaTeX typeset version is handled by how _latex_ is defined to
> handle LaTeX typeset version of an object. But you might know this
> already.
>
> --
> Regards
> Minh Van Nguyen
>
> --
> To post to this group, send an email to sage-devel@googlegroups.com
> To unsubscribe from this group, send an email to 
> sage-devel+unsubscr...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/sage-devel
> URL:http://www.sagemath.org

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-22 Thread Andrey Novoseltsev
On May 22, 10:17 pm, Robert Bradshaw 
wrote:
> Though in Sage we use _repr_, which is used by __str__, __repr__ and  
> _latex_. I think this is a question about the default _latex_ which  
> does some postprocessing of _repr_.
>
> sage: class A(SageObject):
> :     def _repr_(self):
> :         return "A\n B"
> :
> sage: latex(A())
> \texttt{A
>   B}
>
> I'd imagine we could substituted all newlines with something  
> (\newline?), and leading/multiple whitespace with something (~), which  
> wouldn't be too hard.
>
> - Robert

Hi Robert,

That's precisely what I am talking about!

Andrey

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-22 Thread Rob Beezer
1.  In the notebook (or at the command line)

latex('thing-one\nthing-two')

produces

\texttt{thing-one
thing-two}

which would be useful if a string is encountered in tex's math-mode
($..$).  But the "newline" would not be recognized as such by tex.

2.  In the notebook,

view('thing-one\nthing-two')

produces in the "source" for the worksheet (use the "Edit" button to
see this)

"\newcommand{\Bold}[1]{\mathbf{#1}}
\hbox{thing-one
thing-two}"

(Outer guotes added in hopes this comes through email/web OK)

which is rendered (I believe by jsMath) due the CSS "math" class and
the rendering has no line break, presumably since jsMath is following
tex conventions s in (1).

3.  In the notebook, with the "typeset" button checked,

'thing-one\nthing-two'

has *exactly* the same output as in (2).

~~

It looks to me like the JSMath class converts all instances of
\texttt{} to \hbox{} and this is part of view/pretty_print.

The \texttt{} seems to originally come from the str_function()
function.

So as Robert suggests, it might be easy to just modify
str_function()  to replace "\n" by "\newline" and get what I think
Andrey is after.  All this is processing is contained in sag/misc/
latex.py.  John Palmieri might have some insights/ideas as well.

Andrey - is there anything else you'd want to have happen to a string?

Rob


-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-22 Thread John H Palmieri
On May 22, 9:57 pm, Rob Beezer  wrote:

> So as Robert suggests, it might be easy to just modify
> str_function()  to replace "\n" by "\newline" and get what I think

That doesn't seem to work for me.

> Andrey is after.  All this is processing is contained in sag/misc/
> latex.py.  John Palmieri might have some insights/ideas as well.

I don't know about that, but I'll try: perhaps the best thing would be
to use some sort of verbatim environment for LaTeX typesetting of
strings.  My impression is that people tried this a while ago and ran
into problems -- a while ago there were comments to this effect in
misc/latex.py, but they seem to have been removed, probably by me.

Regardless of the approach, it has to work with actual LaTeX and also
with jsMath; the current plan uses \texttt in plain LaTeX and changes
this to \hbox in jsMath (because jsMath doesn't understand the command
\texttt).  I think jsMath has some sort of verbatim environment, so
you could try using that instead of \hbox.  Similarly, you could try
\verb... in plain LaTeX.  To implement any solution, it would probably
be a good idea to search the trac server and also search sage-devel
and sage-support for comments about LaTeX typesetting of strings, to
make sure that the proposed solution deals successfully with all
previous issues.  If anyone does this searching, regardless of whether
they implement any solution, it would be very helpful to record the
results so that everyone has a good list of test cases.

Also, please cc me on any trac ticket about this.

--
John

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-22 Thread Rob Beezer
On May 22, 10:22 pm, John H Palmieri  wrote:
> On May 22, 9:57 pm, Rob Beezer  wrote:
>
> > So as Robert suggests, it might be easy to just modify
> > str_function()  to replace "\n" by "\newline" and get what I think
>
> That doesn't seem to work for me.

Based on some limited testing - just editing the text version of a
worksheet - would indicate that jsMath does not want to deal with
\newline or \\ to break lines.  With no better idea, I was able to use
HTML paragraph tags to get two chunks of text on different lines, of
course.  Maybe a string could be chunked up based on the presence of
\n, then each handled on its own, producing HTML (as currently),
though deciding just when to wrap these with  sounds
problematic (maybe just the presence of \n would be good enough?).

Rob

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-23 Thread Nathan O'Treally
On 23 Mai, 08:15, Rob Beezer  wrote:
> Based on some limited testing - just editing the text version of a
> worksheet - would indicate that jsMath does not want to deal with
> \newline or \\ to break lines.  With no better idea, I was able to use
> HTML paragraph tags to get two chunks of text on different lines, of
> course.  Maybe a string could be chunked up based on the presence of
> \n, then each handled on its own, producing HTML (as currently),
> though deciding just when to wrap these with  sounds
> problematic (maybe just the presence of \n would be good enough?).

I think the presence of \n indicates some ASCII art (_asciiart_()?,
_is_asciiart_()?), but I would use  instead of .

-Leif

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-24 Thread ablondin
What about using the verbatim environment of Latex ?

class A(SageObject):

def _latex_(self):
from sage.misc.latex import LatexExpr
return '\\begin{verbatim}\n123\n 23\n\\end{verbatim}'


sage: attach latex.sage
sage: latex(A())
\begin{verbatim}
123
 23
\end{verbatim}

In the notebook, it works fine for me.
Alex

On 23 mai, 03:00, "Nathan O'Treally"  wrote:
> On 23 Mai, 08:15, Rob Beezer  wrote:
>
> > Based on some limited testing - just editing the text version of a
> > worksheet - would indicate that jsMath does not want to deal with
> > \newline or \\ to break lines.  With no better idea, I was able to use
> > HTML paragraph tags to get two chunks of text on different lines, of
> > course.  Maybe a string could be chunked up based on the presence of
> > \n, then each handled on its own, producing HTML (as currently),
> > though deciding just when to wrap these with  sounds
> > problematic (maybe just the presence of \n would be good enough?).
>
> I think the presence of \n indicates some ASCII art (_asciiart_()?,
> _is_asciiart_()?), but I would use  instead of .
>
> -Leif
>
> --
> To post to this group, send an email to sage-devel@googlegroups.com
> To unsubscribe from this group, send an email to 
> sage-devel+unsubscr...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/sage-devel
> URL:http://www.sagemath.org

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-24 Thread John H Palmieri
On May 24, 2:17 pm, ablondin 
wrote:
> What about using the verbatim environment of Latex ?
>
> class A(SageObject):
>
>     def _latex_(self):
>         from sage.misc.latex import LatexExpr
>         return '\\begin{verbatim}\n123\n 23\n\\end{verbatim}'
>
> sage: attach latex.sage
> sage: latex(A())
> \begin{verbatim}
> 123
>  23
> \end{verbatim}
>
> In the notebook, it works fine for me.

>From the notebook, try executing

  view(A())

I bet you'll see a box saying

  Unknown environment "verbatim"

This is because jsMath doesn't know about the verbatim environment.
The extension

  

might be an option here, but that doesn't seem to deal with newlines
very well.

--
John

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-24 Thread ablondin
You're right ! It doesn't work with the view() function. On the other
hand, when I select latex instead of sage and I enter the command

\sage{A()}

it displays 123 on the first line and 23 on the second line, with the
2's aligned properly, i.e. it handles the newlines and indentation as
desired. That said, I guess it's not a clean solution...

Alex

On 24 mai, 18:01, John H Palmieri  wrote:
> On May 24, 2:17 pm, ablondin 
> wrote:
>
>
>
> > What about using the verbatim environment of Latex ?
>
> > class A(SageObject):
>
> >     def _latex_(self):
> >         from sage.misc.latex import LatexExpr
> >         return '\\begin{verbatim}\n123\n 23\n\\end{verbatim}'
>
> > sage: attach latex.sage
> > sage: latex(A())
> > \begin{verbatim}
> > 123
> >  23
> > \end{verbatim}
>
> > In the notebook, it works fine for me.
>
> From the notebook, try executing
>
>   view(A())
>
> I bet you'll see a box saying
>
>   Unknown environment "verbatim"
>
> This is because jsMath doesn't know about the verbatim environment.
> The extension
>
>   
>
> might be an option here, but that doesn't seem to deal with newlines
> very well.
>
> --
> John
>
> --
> To post to this group, send an email to sage-devel@googlegroups.com
> To unsubscribe from this group, send an email to 
> sage-devel+unsubscr...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/sage-devel
> URL:http://www.sagemath.org

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Can LaTeX of strings be improved?

2010-05-25 Thread John H Palmieri
On May 24, 9:11 pm, ablondin 
wrote:
> You're right ! It doesn't work with the view() function. On the other
> hand, when I select latex instead of sage and I enter the command
>
> \sage{A()}
>
> it displays 123 on the first line and 23 on the second line, with the
> 2's aligned properly, i.e. it handles the newlines and indentation as
> desired. That said, I guess it's not a clean solution...

Another not clean solution: typeset strings with

\begin{verbatim}
string
\end{verbatim}

and then put "\\begin{verbatim}" in the jsmath_avoid list.  This
results in inconsistent behavior: jsMath output appears in blue, while
LaTeX output appears in black.

Another option: use the \verb option for jsMath, but break the string
at newlines and typeset each line individually, inserting line breaks
explicitly in the html produced by the JSMath class in sage/misc/
latex.py.

--
John

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Can LaTeX of strings be improved?

2010-05-22 Thread Andrey Novoseltsev
On Sat, May 22, 2010 at 10:57 PM, Rob Beezer  wrote:
> Andrey - is there anything else you'd want to have happen to a string?
>
> Rob
>
>
> --
> To post to this group, send an email to sage-devel@googlegroups.com
> To unsubscribe from this group, send an email to 
> sage-devel+unsubscr...@googlegroups.com
> For more options, visit this group at 
> http://groups.google.com/group/sage-devel
> URL: http://www.sagemath.org
>

Hi Rob,

I will be quite happy with newlines and some kind of indentations.

It may be reasonable to also typeset such things using a fixed width
font, since this will take care of indentations in the best possible
way, but I don't know if it worth it. After all, there is always a
possibility to use "print" explicitly when one wants to see a
complicated object where they are really important (e.g. I have some
matrices with labels printed all around and aligned with columns). It
is just annoying to type "print" all the time for things like
Sequence(..., cr=True) and for my objects that have _repr_ but no
_latex_.

Thank you!
Andrey

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Can LaTeX of strings be improved?

2010-05-25 Thread ross kyprianou
I couldnt see a solution to this in this thread so heres a related question

The following produces the exact output Id like to produce (to assign to the
_repr_ property of a class)

%latex
N(\mu,\sigma^2)


How can I set things up to do this in a (_repr_) function (as a sage
statement/function call)?
Does a function exist so I call it to produce such an output?

I was hoping something like this would work

from sage.misc.latex import pretty_print
pretty_print_default(True)
pretty_print('N('+'\mu'+','+'\sigma^2'+')')

but all it displays is

N(\mu,\sigma^2)

(hope I didnt miss something too obvious - thanks)

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org