Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sage cells in knowls #981

Closed
davidfarmer opened this issue Dec 12, 2018 · 23 comments
Closed

Sage cells in knowls #981

davidfarmer opened this issue Dec 12, 2018 · 23 comments

Comments

@davidfarmer
Copy link
Contributor

This issue explains what to do to fix issue #190 and partially fix issue #629 .

The knowls code has been changed to support the following:

Suppose a div in a hidden knowl has class "hidden-sagecell-sage".
When the knowl opens, that class is changed to "sagecell-sage", and then
that div is converted into a sage cell.

So we need to:

  1. Change the class on the div in the hidden knowl to "hidden-sagecell-sage".
  2. Tell me what other sagecell-* things might be hidden in a knowl, so that
    the knowls code can also take care of those.

Testing can start once 1) is done. (I looked at the code briefly but could not
immediately see how to do that.) We don't know if linking will work properly
for hidden sage cells, for example.

For 2), I am not clear on why there are several classes starting with sagecell-,
instead of one sagecell class and something else to indicate the language.

@rbeezer
Copy link
Collaborator

rbeezer commented Dec 13, 2018

Thank-you, thank-you, thank-you. Christmas comes early this year!

I hacked a hidden- prefix onto every cell, and the sample-article example meant to test this worked properly. So just a confirmation of that.

I tried to be fancy with some abstract templates for Sage Cells. It has needed a rethink for a long time. "Passing in" if a cell is in a knowl or not could be difficult. I'll see what I can cook up.

For 2), I am not clear on why there are several classes starting with sagecell-,
instead of one sagecell class and something else to indicate the language.

Go to the Customization section here:
https://github.com/sagemath/sagecell/blob/master/doc/embedding.rst

You will see that linking, and languages, and automatic-evaluation are all setup per-page and are bound to a JQuery selector (I've just been using classes). Maybe there is a fancier way to do this, but I have been prioritizing linking. So a page may have two languages in use, so there are two sets of linked cells. I think this is the impediment to just having an inital cell or two do automatic evaluation.

If there is some way to get all the cells linked, language specified in some other class, and some cells automatically evaluated (and others not), through some sort of CSS selector technique, that'd be great. We'd have a lot more flexibility.

@davidfarmer
Copy link
Contributor Author

davidfarmer commented Dec 13, 2018 via email

@rbeezer
Copy link
Collaborator

rbeezer commented Dec 15, 2018

Yes, I think those 9 are it. Not sure we need/want "allLanguages".

Sorry for the delay - getting it from all sides right now. ;-)

@kcrisman
Copy link
Contributor

kcrisman commented Jan 4, 2019

Just curious as to the status of this innovation; thanks for figuring it out!

@rbeezer
Copy link
Collaborator

rbeezer commented Jan 5, 2019

I need to refactor how Sage cells migrate to HTML, in order to get this right properly. Soon, since I need it for FCLA. It was on today's list, but I think footnotes have taken much of the wind out of my sails.

@rbeezer
Copy link
Collaborator

rbeezer commented Jan 7, 2019

I have pushed code to identify whenever a Sage cell is being constructed as part of a born-hidden knowl. Now the cells in this situation will render and execute correctly. Good progress.

But, linking is broken, which for FCLA means these knowls can't be used. On a whim, I hand edited one page, set the class in the Sage cell configuration to hidden-sagecell-sage and that was worse. The cells rendered but had "extra" stuff in them and were guaranteed to throw Python errors.

Single test page up. "Sage MS" is in the early going. Second cell fails due to no-linking. Last cell is pure and executes fine.

https://pretextbook.org/beta/section-MO-20190106.html

@rbeezer
Copy link
Collaborator

rbeezer commented Jan 7, 2019

There is a sage-display class as well. May be unnecessary in the long term, and certainly not a priority.

@rbeezer
Copy link
Collaborator

rbeezer commented Dec 31, 2019

This fix caused Sage cells to render within knowls and be executable. Good. But it broke linking ("remembering" results and variables across cells). This is the last hurdle (I think!) to releasing a fully-PreTeXt version of FCLA. Here's what I know:

Sage Cell setup involves a per-page hunk of javascript, which identifies cells with mechanisms like an element and a class (CSS selectors). Then a linked variable is set to true to make all those cells share results.

https://github.com/sagemath/sagecell/blob/master/doc/embedding.rst#linked-cells

So the hidden-sagecell-sage class made cells render and execute within a knowl. But other cells on the page have a sagecell-sage class, and are not linked. There is no Sage Cell setup for the .hidden-sagecell-sage cells as (I think) their class name is being changed dynamically.

(The "-sage" part indicates the language for the cell. Part of setup, and it seems odd to link cells with different languages, hence multiple possible setups and multiple class names. I don't think considering this twist is necessary for the immediate problem.)

Test page here:

https://pretextbook.org/beta/2019-12-31-sage-knowl/interesting-corollary.html

Execute cell prior to Example 4.2, open knowl, run cells. We'd like variables a and b to be linked for the cells in the knowl when run in order.

@rbeezer
Copy link
Collaborator

rbeezer commented Jun 16, 2020

Example 4.2 of the sample article is a knowl which has some simple (linked) Sage cells which do not remember the values in previous cells. There is a cross-reference shortly afterward which will test a different type of knowl (cross-reference, versus born-hidden).

https://pretextbook.org/examples/sample-article/html/interesting-corollary.html#mNo

@kcrisman
Copy link
Contributor

On a related note, the evaluate button for the Sage cell immediately before Example 4.2 is apparently located within the statement of Example 4.2 (check out the "L"-shaped line that sets off the Example). As a result, I can't even press the evaluate button.

@kcrisman
Copy link
Contributor

(Also, to be clear to anyone else reading this, the linking that is broken is only linking involving the knowled cells.)

@rbeezer
Copy link
Collaborator

rbeezer commented Jun 16, 2020

I don't see this at all with Ubuntu Firefox. Can you open a new issue (perhaps mention David Farmer), include OS/browser details, and maybe a screenshot? Thanks.

On a related note, the evaluate button for the Sage cell immediately before Example 4.2 is apparently located within the statement of Example 4.2 (check out the "L"-shaped line that sets off the Example). As a result, I can't even press the evaluate button.

@kcrisman
Copy link
Contributor

kcrisman commented Jun 16, 2020 via email

@JeanSebastienTurcotte
Copy link
Contributor

JeanSebastienTurcotte commented Jun 16, 2020 via email

@kcrisman
Copy link
Contributor

See #1313 for the evaluate button, with pictures.

@JeanSebastienTurcotte
Copy link
Contributor

With the current version of PreTeXt, Sagecells in knowls seem to work fine. However, if the sagecell is in a (within an at least), the input won't render. The "evaluate" button is clickable, but does nothing.

@davidfarmer
Copy link
Contributor Author

davidfarmer commented Aug 11, 2020 via email

@JeanSebastienTurcotte
Copy link
Contributor

JeanSebastienTurcotte commented Aug 11, 2020

See solution2 and solution3 at http://alir.jsturcotte.profweb.ca/sec-SELgeo.html#example-68

3.3.1 also has the same issue.
Another edit: Open the xref 3.3.1 at http://alir.jsturcotte.profweb.ca/sec-SELgeo.html#p-2081
and open solution2 (solution1 has a typo). The sagecell now works.

If it helps, I thought the problem was a knowl inside a knowl, but the lines "TEST avec 3.3.18 " works fine both inside just and inside .

@rbeezer
Copy link
Collaborator

rbeezer commented Aug 11, 2020

The Sage Cell setup in the head is not being used/applied as the Evaluate button does not display text provided in other languages. See #1344

@rbeezer
Copy link
Collaborator

rbeezer commented Aug 12, 2020

This is fixed, and tested with the sample article and FCLA. @JeanSebastienTurcotte do you want to review with your material?

@JeanSebastienTurcotte
Copy link
Contributor

@rbeezer So, it seems that it partly fixed theissue. The cells inside both and of an now have the Evaluate (Sage) button and properly translated. So my git pull worked. However only cells inside the first-level knowl render. Those inside a knowled solution do not.

As mentioned in my previous comment, see the xref 3.3.1 at http://alir.jsturcotte.profweb.ca/sec-SELgeo.html#p-2081
and open any solutions at the bottom. The sagecell works. But if you click in-context and see the in text example, the cells in solution do not work.

@rbeezer
Copy link
Collaborator

rbeezer commented Aug 14, 2020 via email

@rbeezer
Copy link
Collaborator

rbeezer commented Oct 8, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants