PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
254 stars 203 forks source link

Sage cells in knowls #981

Closed davidfarmer closed 3 years ago

davidfarmer commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

I see 9 language options. Will it always be the case that the class is "sagecell-X" where X is one of those 9? If so, I'll just make each of those work.

Or 10 if we include "allLanguages".

On Thu, 13 Dec 2018, Rob Beezer wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.[AAM6LLN-GCB3DdrbIMPrXsG1eJPVI68eks5u4t87gaJpZM4ZQU1P.gif]

rbeezer commented 5 years ago

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 commented 5 years ago

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

rbeezer commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

rbeezer commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

rbeezer commented 3 years ago

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 commented 3 years ago

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.

If I can confirm today (you know how bugs you're not responsible for always seem to disappear when you actually mention them) I will definitely do that. Assuming GH lets me put up a screenshot.

JeanSebastienTurcotte commented 3 years ago

because (somehow) I'm on this thread, I can confirm the bug as well. I cannot click on the evaluate button above example 4.2 on pc Windows/ chrome. However, on android chrome I can.

Le mar. 16 juin 2020 11 h 44, kcrisman notifications@github.com a écrit :

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.

If I can confirm today (you know how bugs you're not responsible for always seem to disappear when you actually mention them) I will definitely do that. Assuming GH lets me put up a screenshot.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rbeezer/mathbook/issues/981#issuecomment-644847294, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6COPPDBQG57MAPKDLQYBLRW6HPVANCNFSM4GKBJVHQ .

kcrisman commented 3 years ago

See #1313 for the evaluate button, with pictures.

JeanSebastienTurcotte commented 3 years ago

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 commented 3 years ago

Can you post a live example?

On Tue, 11 Aug 2020, JeanSebastienTurcotte wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, orunsubscribe.[AABTULEB46P4QPOZGJNKWWDSAFPE3A5CNFSM4GKBJVH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORP WSZGOFAHB6YI.gif]

JeanSebastienTurcotte commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

JeanSebastienTurcotte commented 3 years ago

@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 commented 3 years ago

Yes, these cells do not render for me. And I can't quite tell why. The markup looks not much different to me than what I see inside

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

I looked into the knowl.js code and wonder if div.hidden-sagecell-sage does not need to be used/considered more often, but I'm operating above my pay grade here.

Maybe @davidfarmer sees something?

On 8/13/20 8:35 AM, JeanSebastienTurcotte wrote:

@rbeezer https://github.com/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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rbeezer/mathbook/issues/981#issuecomment-673549323, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOLM4V6I4CVEQNTRX3ZSMDSAQB3LANCNFSM4GKBJVHQ.

rbeezer commented 2 years ago

More (for MathJax 3) at https://groups.google.com/g/pretext-support/c/Tk9XfuIQo1U/m/_5IMITeiAwAJ