Ask Your Question
1

Table frame not showing in Jupyter Notebook and inconsistent in other environments

asked 2020-04-06 18:10:42 +0100

dsejas gravatar image

Hello, Sage community!

The table command in Sage has this useful option called frame. If I set frame=True in SageCell, CoCalc, the Sage terminal and SageTeX, the result is the expected: a frame is shown for the corresponding table. However, the same command does not work properly in Jupyter Notebooks. Also, the results are quite different in SageCell and CoCalc.

The following three images show the result of executing the following commands:

rows = [[100,2,3], [4,5,60]]
t = table(rows, frame=True)
show(t)

This is the result in SageCell:

image description

This is the result in CoCalc:

image description

This is the result in Jupyter (executed using sage -n jupyter):

image description

Here are my questions:

  1. Why is the frame=True option not working in Jupyter?
  2. Why the difference in the results?
  3. Is there any way to make these results consistent through these environments?
edit retag flag offensive close merge delete

Comments

The table module was written by John Palmieri (and reviewed by me:) before the inclusion of the Jupyter notebook in Sage. You are welcome to contribute to Sage to fix those issues.

Sébastien gravatar imageSébastien ( 2020-04-06 21:02:56 +0100 )edit

Hello, @Sébastien! I have been thinking about enhancing the table module a little bit, ever since I was translating Prof. Bard's "Sage for Undergraduates" to Spanish. Basically, I would like a little bit more of customization. This could be a good opportunity to do that and fix the issues you mentioned.

I hope you don't mind my asking: How can I send patches of code or new code if I don't know how to use git? (Of course, I can learn, but it will take me a few weeks.)

dsejas gravatar imagedsejas ( 2020-04-07 02:20:15 +0100 )edit

Perhaps it is worth writing first to Andrey Novoseltsev, the maintainer of SageCell. How has he managed to get working the frame=True option?

Juanjo gravatar imageJuanjo ( 2020-04-07 03:50:49 +0100 )edit

"How can I send patches of code or new code if I don't know how to use git? (Of course, I can learn, but it will take me a few weeks.)"

It seems to be a nice question to ask on ask! :)

Sébastien gravatar imageSébastien ( 2020-04-07 09:53:13 +0100 )edit

Hello, @Sébastien! I was about to post the question, but I can see that you already did. Thank you very much, I appreciate it! I hope I can collaborate with the Sage community!

dsejas gravatar imagedsejas ( 2020-04-10 18:57:11 +0100 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2020-04-06 22:41:28 +0100

Juanjo gravatar image

The appearance of tables strongly depends of the active CSS attributes applying to them. For example, as shown in the screen capture below, if you add and evaluate the following code in a Jupyter notebook, you will get tables more similar to those in SageCell:

%%html
<style>
table.table_form{
    border: 1px solid gray;
    border-collapse: separate;
    border-spacing: 2px;}
table.table_form td {
    border: 1px solid gray;
    padding: 5px 15px; 
    color: #00a;
    background-color: #f8f8f8;
    text-align: left;
    font-size:medium}
</style>

image description

Now, consider the code

rows = [[100,2,3], [4,5,60]]
t = table(rows, frame=True)
print(html(t))

The output is

<div class="notruncate">
<table border="1" class="table_form">
<tbody>
<tr class ="row-a">
<td><script type="math/tex">100</script></td>
<td><script type="math/tex">2</script></td>
<td><script type="math/tex">3</script></td>
</tr>
<tr class ="row-b">
<td><script type="math/tex">4</script></td>
<td><script type="math/tex">5</script></td>
<td><script type="math/tex">60</script></td>
</tr>
</tbody>
</table>
</div>

Look at the second line. The border attribute of table is not longer supported in HTML5. Since it has no effect in a modern browser, the frame is not shown.

In SageCell, however, the frame option works. So I imagine that the base code has been modified somehow. Quite surely the same patch could be applied for Jupyter notebooks.

Reading $SAGE_SRC/sage/misc/table.py, it seems that the problem comes from lines 720-723, that is,

if self._options['frame']:
        frame = 'border="1"'
    else:
        frame = ''

Perhaps it would suffice to replace frame = 'border="1"' by

frame = 'style="border-style: solid"'

or something similar.

edit flag offensive delete link more

Comments

Thank you very much, @Juanjo! This was really helpful. If I could give you more than one upvote, I would do it.

dsejas gravatar imagedsejas ( 2020-04-07 02:11:12 +0100 )edit

Many thanks, @dsejas. I also learn a lot from your questions and answers. By the way, it is nice to know from a comment above that there exists a translation to Spanish of Sage for Undergraduates and that you are precisely the translator ;-) . I have quickly searched, found and downloaded it!

Juanjo gravatar imageJuanjo ( 2020-04-07 03:44:08 +0100 )edit

I really hope the translation will be useful for everybody, especially for Sage beginners and undergraduates.

If you are interested, I will be uploading information regularly on the book's website: www.sage-para-estudiantes.com.

Disclaimer: This is not intended as a shameless publicity.

dsejas gravatar imagedsejas ( 2020-04-07 05:22:44 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-04-06 18:10:42 +0100

Seen: 1,243 times

Last updated: Apr 06 '20