Pretty print

53 views
Skip to first unread message

Jorge Manrique

unread,
Sep 1, 2017, 4:52:50 PM9/1/17
to sage-cell
Hello everyone,
I am new user of SageMath. As a practice I am using a program that I find in section 6.2 of the book "Sage for Undergraduetes" by Professor Gregory Bard.
I have two questions:
  1. How can I delete / hide the star in the upper right corner? The one that has to do with bookmarks. Use "hide: permalink" and "hide" the entire cell.
  2. Using the same program, I change the "printt" to "pretty_print". When I make the change in Jupiter notebook it works fine (well not very pretty) but when I do it using Sage-Cell prints nothing. Should I change anything else?
I hope not to bother with silly questions.
Thank you in advance for your cooperation.

Jorge

Andrey Novoseltsev

unread,
Sep 1, 2017, 7:32:33 PM9/1/17
to sage-cell
Hi Jorge,


On Friday, 1 September 2017 14:52:50 UTC-6, Jorge Manrique wrote:
  1. How can I delete / hide the star in the upper right corner? The one that has to do with bookmarks. Use "hide: permalink" and "hide" the entire cell.
I don't understand the end of the question, but for hiding in general you should refer to https://github.com/sagemath/sagecell/blob/master/doc/embedding.rst#hiding-sage-cell-elements Apparently hiding the bookmarks star is not implemented, but I can look into doing it.
  1. Using the same program, I change the "printt" to "pretty_print". When I make the change in Jupiter notebook it works fine (well not very pretty) but when I do it using Sage-Cell prints nothing. Should I change anything else?
Can you please give complete code that you are trying to execute? To my knowledge everything that can be "print"ed can also be "pretty_print"ed in some way.

Best,
Andrey

Jorge Manrique

unread,
Sep 2, 2017, 5:06:29 PM9/2/17
to sage-cell
Hello Andrey,
sorry for the confusing question I meant when I use "hide: permalink" the cell is not displayed at all

Regarding pretty_print was my mistake. I set MathJax erroneously, I use AM_CHTML which only works for AsciiMath. I changed it to TeX-MML-AM_HTMLorMML which also works for MathML (and LaTex) and now it works but not so pretty. I need to work a little more on that

Thank you very much for your help.
Now I will try my own code, soon you will hear from me again

Andrey Novoseltsev

unread,
Sep 3, 2017, 6:49:46 PM9/3/17
to sage-cell


On Saturday, 2 September 2017 15:06:29 UTC-6, Jorge Manrique wrote:
Hello Andrey,
sorry for the confusing question I meant when I use "hide: permalink" the cell is not displayed at all

If this is exactly what you have typed, then this is the problem, you need "hide: ['permalink']" which works for me as expected. If you still have problems, can you please give a link to your non-working example?

Regarding pretty_print was my mistake. I set MathJax erroneously, I use AM_CHTML which only works for AsciiMath. I changed it to TeX-MML-AM_HTMLorMML which also works for MathML (and LaTex) and now it works but not so pretty. I need to work a little more on that

MathJax will be loaded automatically, so there is no need to do anything with it at all, unless of course you are using it in your pages independently of SageMathCell.

Jorge Manrique

unread,
Sep 5, 2017, 8:11:13 PM9/5/17
to sage-cell
Holo Andrey, 
now the syntax is correct but that does not hide the little star in the upper right corner. 
It's not important at the moment.

Thank you very much for your attention

Jorge Manrique

unread,
Sep 5, 2017, 8:49:41 PM9/5/17
to sage-cell

I have another question: 
I want to print something like this
As it can be noticed the size of the parenthesis in relation to the text is asymmetric
I wish it looks like this:







I have thought to use latex () but I do not know how to deal with the right parentesis in f () so it is not confused with the right parentesis of the pretty_print
I searched for some escape sequence but I have not found any

Andrey Novoseltsev

unread,
Sep 5, 2017, 10:42:19 PM9/5/17
to sage-cell

You have to build a complete LaTeX expression and then display it as a single entity, for example

x0 = 2/3
f(x) = x + 1
pretty_print("f(", x0, ")=", f(x0))

latex_code = r"f\left({}\right) = {}" # r in front to avoid escaping \ and {} are places for expressions
expressions = [x0, f(x0)]
pretty_print(LatexExpr(latex_code.format(*map(latex, expressions))))

Jorge Manrique

unread,
Sep 7, 2017, 5:22:55 PM9/7/17
to sage-cell
Hello Andrey
I did not know LatexExpr() and I would not have realized its existence in years. 
Thanks for your help

Now I have problems with the web page layout:
  • The text is centered instead of left justified
  • The spaces are not taken into account













As you can see in the previous code, spaces are included when I use print (in green) but this is not the case when I use pretty_print (in blue)

Any help would be appreciated,
Joge

Andrey Novoseltsev

unread,
Sep 7, 2017, 7:18:24 PM9/7/17
to sage-cell
On Thursday, 7 September 2017 15:22:55 UTC-6, Jorge Manrique wrote:
Hello Andrey
I did not know LatexExpr() and I would not have realized its existence in years. 
Thanks for your help

Now I have problems with the web page layout:
  • The text is centered instead of left justified
  • The spaces are not taken into account













As you can see in the previous code, spaces are included when I use print (in green) but this is not the case when I use pretty_print (in blue)

Well, this is how LaTeX works - space in math mode does not matter and is determined automatically according to some rules, but you can use commands to change it. Also, if you want to mix actual text and formulas, you can use HTML code with formulas via
pretty_print(html(r"Arbitrary HTML code with <h1>any tags</h1> and math formulas in $delimiters$ of \[different\ kind\]"))

Jorge Manrique

unread,
Sep 8, 2017, 10:26:54 PM9/8/17
to sage-cell
Hello Andrey,
I did this:





and it seems to work.
Now I'll try to make the text aligned to the left rather than centered
Reply all
Reply to author
Forward
0 new messages