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

Images showing the results of the codes (again) #7

Open
dbitouze opened this issue Jul 1, 2022 · 11 comments
Open

Images showing the results of the codes (again) #7

dbitouze opened this issue Jul 1, 2022 · 11 comments

Comments

@dbitouze
Copy link

dbitouze commented Jul 1, 2022

For the French FAQ that, at GUTenberg, we are currently trying to modernize (relying on Sphinx-doc, BTW), it would be helpful to provide the feature of testing online the examples. I managed to make it work (many thanks, BTW!) but, for most of the cases, it would be nice for the reader to immediately see the results of the codes with images attached to each code blocks.

This subject has been extensively discussed about learnlatex.org and it was decided to not provide such a feature for such a LaTeX tutorial. Okay but, IMO, such a feature does make sense for a FAQ.

Would it be possible for latexcgi to provide, in addition to the PDFs obtained on request by compilation of the code blocks, static images automatically and by default attached to each of these code blocks?

@davidcarlisle
Copy link
Owner

@dbitouze that depends... for initial faq examples you know the code and so you could host the image. For dynamically edited code, you need to submit to say you have edited, at which point I generate and show the pdf, I could in principle generate a png from the pdf and show that as well but that seems a bit weird.

I suspect that the way I phrased the above comment means I have not really understood your intended workflow.

What might be possible is for examples to fire the PDF generation on page load so you initially see the output. To be honest I can't remember if that is allowed or not (browsers block some events on page load and force manual interaction for security reasons) If that isn't blocked you can probably do that already without change here. I can check, if that would be useful.
(If generating a pdf is blocked, same will be true of an image, which would come back to the question of when the images are generated and where are they hosted)

@davidcarlisle
Copy link
Owner

You can of course cause the pdfs to be generated on page load, eg

https://texlive.net/run?hello

@dbitouze
Copy link
Author

dbitouze commented Jul 1, 2022

@dbitouze that depends... for initial faq examples you know the code and so you could host the image. For dynamically edited code, you need to submit to say you have edited, at which point I generate and show the pdf, I could in principle generate a png from the pdf and show that as well but that seems a bit weird.

I suspect that the way I phrased the above comment means I have not really understood your intended workflow.

Indeed, maybe it was not that clear in my mind as well 😄: probably (already displayed) PDFs instead of images would be preferable.

What might be possible is for examples to fire the PDF generation on page load so you initially see the output. [...]

See below.

You can of course cause the pdfs to be generated on page load, eg

https://texlive.net/run?hello

It's nice but:

  • I don't see how this works: what is hello? is it a file? how does it work in case of several paragraphs and several codes (complete examples, snippets/document fragment examples, etc.)?
  • it would solicit the server each time a page is visited and hence would not be energy-friendly: more Internet traffic, more servers requested, etc.

Maybe a better option would be for the PDFs to be generated just once when the pages of the FAQ are built, and regenerated only when the visitor edits the code and submits what he has edited.

@davidcarlisle
Copy link
Owner

davidcarlisle commented Jul 1, 2022

I don't see how this works: what is hello?

on that demo it is an arbitrary string, try https://texlive.net/run?bonjour a more realistic example with two inline documents is attached here (as .txt for github, save as .html and view locally)

run2.txt

Maybe a better option would be for the PDFs to be generated just once when the pages of the FAQ are built, and regenerated only when the visitor edits the code and submits what he has edited.

Well as I say I can't host the images or pre-generated PDF. There is no login, no session ID and no financing so I can't offer to save and store images for anyone, and as I don't really know if one request is coming from the same session as the last I can't serve images made previously either, by design there are no session cookies or any user data stored.

So anything displayed on the page has to come from your site (you could make images of the initial faq examples, and lose them on edit) or be generated on the fly in a single call to texlive.net so I can generate and return to the same browser.

Of course this mostly relates to the texlive.net hosted latex, if you clone the whole mechanism and serve your own generated files, you could choose to keep as many images as you have space for, and manage user data so users can or can not see the data of others.

Basically to preserve data between sessions (where regenerating after an edit is a new session) you need to be more like overleaf than texlive.net with user accounts that can host project edits not visible to other users but preserved and restored if that user logs in again.

This is basically a stateless service, so yes stuff gets re-done every time anyone looks at the page, but that's the price for a login free instant run service:-)

@dbitouze
Copy link
Author

dbitouze commented Jul 2, 2022

I don't see how this works: what is hello?

on that demo it is an arbitrary string, try https://texlive.net/run?bonjour a more realistic example with two inline documents is attached here (as .txt for github, save as .html and view locally)

run2.txt

Does it mean it is enough to add to each of the HTML pages of the FAQ the script:

<script>
    function preloadPDF (){
        var p=0;
        while (editors["pre"+ p]) {
            latexcgi("pre" + p);
            p=p+1;
        }
    }
    window.addEventListener('load', preloadPDF, false);
</script>

to make the PDFs displayed each time a page is visited?

Maybe a better option would be for the PDFs to be generated just once when the pages of the FAQ are built, and regenerated only when the visitor edits the code and submits what he has edited.

Well as I say I can't host the images or pre-generated PDF. There is no login, no session ID and no financing so I can't offer to save and store images for anyone, and as I don't really know if one request is coming from the same session as the last I can't serve images made previously either, by design there are no session cookies or any user data stored.

So anything displayed on the page has to come from your site (you could make images of the initial faq examples, and lose them on edit)

Yes, that's what I had in mind (sorry to have been not precise enough): in order to reduce server solicitation and bandwidth, making and storing locally the images beforehand would be a good solution.

or be generated on the fly in a single call to texlive.net so I can generate and return to the same browser.

Do you mean each time a single page of the FAQ is visited, texlive.net generates all the images? Well, our FAQ currently contains 1295 pages (okay not all of them contain code blocks but many of them contain more than one code block).

Of course this mostly relates to the texlive.net hosted latex, if you clone the whole mechanism and serve your own generated files, you could choose to keep as many images as you have space for, and manage user data so users can or can not see the data of others.

Maybe that's a solution. But in the long run...

Basically to preserve data between sessions (where regenerating after an edit is a new session) you need to be more like overleaf than texlive.net with user accounts that can host project edits not visible to other users but preserved and restored if that user logs in again.

Well, it would be too complicated, I guess.

This is basically a stateless service, so yes stuff gets re-done every time anyone looks at the page, but that's the price for a login free instant run service:-)

So you don't mind if (for the moment) all the PDFs of our FAQ's pages are generated thanks to texlive.net when they are visited?

@davidcarlisle
Copy link
Owner

to make the PDFs displayed each time a page is visited?

yes , but this puts some load on the server, you might consider hosting your own copy of latexcgi in that case.
human readers typically don't generate all the examples and if they do, they do it minutes apart not all at the same time.

Yes, that's what I had in mind (sorry to have been not precise enough): in order to reduce server solicitation and bandwidth, making and storing locally the images beforehand would be a good solution.

I would use PDF not images. That is fine and probably what you should do but doesn't require any change here. If you have a page with initial tex examples and initial pdf display from pdfs on your site, your copy of runlatex.js can easily make the initial pdf be replaced by a generated one. Either a small edtit to the javascript or it probably works unchanged if you give the iframe holding your original pdf the same id as the ids used here: it will be updated just as re-clicking the button updates a generated pdf.

Do you mean each time a single page of the FAQ is visited, texlive.net generates all the images?

all the pdf on that page would be generated on page load by the loop you showed (not all the pdf for your whole site)

So you don't mind if (for the moment) all the PDFs of our FAQ's pages are generated thanks to texlive.net when they are visited?

well we'll see.. If all the forums running this grind to a halt, and Stefan's server starts running at maximum load, then we may start to mind. But currently it typically serves 3 to 4 thousand document requests a day, so if this adds a few hundred a day more, it is probably not an issue. If it adds thousands a day more, then it may be.

@davidcarlisle
Copy link
Owner

@dbitouze I guess this is closest to what you are looking for

https://davidcarlisle.github.io/latexcgi/test-preload.html

view source or look in git view for the source: all the files are in this commit

e0eb872

That shows two tex examples each followed by an iframe showing PDF output. The pdf are pre-generated and statically served by the site hosting the page, so no interaction with texlive.net unless you click on the button

The iframes have id pre0ifr, pre1ifr, ... so if you do click on a texlive.net button runlatex.js replaces the iframe with one hosting a newly generated pdf.

@dbitouze
Copy link
Author

dbitouze commented Jul 2, 2022

to make the PDFs displayed each time a page is visited?

yes , but this puts some load on the server, you might consider hosting your own copy of latexcgi in that case. human readers typically don't generate all the examples and if they do, they do it minutes apart not all at the same time.

Okay. Hosting our own copy of latexcgi is probably currently beyond my scope.

Yes, that's what I had in mind (sorry to have been not precise enough): in order to reduce server solicitation and bandwidth, making and storing locally the images beforehand would be a good solution.

I would use PDF not images.

Sorry, I meant PDFs.

That is fine and probably what you should do but doesn't require any change here. If you have a page with initial tex examples and initial pdf display from pdfs on your site, your copy of runlatex.js can easily make the initial pdf be replaced by a generated one. Either a small edtit to the javascript or it probably works unchanged if you give the iframe holding your original pdf the same id as the ids used here: it will be updated just as re-clicking the button updates a generated pdf.

Nice!

Do you mean each time a single page of the FAQ is visited, texlive.net generates all the images?

all the pdf on that page would be generated on page load by the loop you showed (not all the pdf for your whole site)

Okay.

So you don't mind if (for the moment) all the PDFs of our FAQ's pages are generated thanks to texlive.net when they are visited?

well we'll see.. If all the forums running this grind to a halt, and Stefan's server starts running at maximum load, then we may start to mind. But currently it typically serves 3 to 4 thousand document requests a day, so if this adds a few hundred a day more, it is probably not an issue. If it adds thousands a day more, then it may be.

I see. Thanks.

@davidcarlisle
Copy link
Owner

@dbitouze sorry errors in that pre-loaded pdf example (still had remnants of the example calling latexcgi on page load) corrected at 8ce3c97

@dbitouze
Copy link
Author

dbitouze commented Jul 2, 2022

@dbitouze sorry errors in that pre-loaded pdf example (still had remnants of the example calling latexcgi on page load) corrected at 8ce3c97

Thanks for digging into this! I'm not sure it will be easy to proceed like this with our current workflow (migrating from Dokuwiki to Sphinx-doc) but I'll think about it.

@davidcarlisle
Copy link
Owner

@dbitouze well it's there as a backup if generating pdf on page load ends up overloading us at texlive.net

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

No branches or pull requests

2 participants