quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.97k stars 327 forks source link

Support other PDF export tools for revealjs (e.g decktape) #4677

Open cderv opened 1 year ago

cderv commented 1 year ago

Current PDF export mode rom revealjs doesn't work reliable on most browsers. For example on Firefox you will still get garbage resp. wrong page breaks in the printed results after activating this mode. Well, you'll find a warning note about this flaw in the documentation, but it's IMHO still a very disappointing behavior.

I would therefore prefer a more reliable solution, which provides reproducible correct results in arbitrary browsers.

This can be realized in practice by integrating decktape resp. puppeteer, playwright or another similar mechanism into the CLI-tool for the document processing to generate a PDF-document beside the HTML-output and just add a download button in the HTML-menu or -toolbar instead of the present print style-switch entry. That's the way, how for example slidev handles this task in a much more reliable manner (see: https://sli.dev/guide/exporting#pdf).

Originally posted by @mash-graz in https://github.com/quarto-dev/quarto-cli/issues/2988#issuecomment-1455245996

Related

FeralFlora commented 1 year ago

For example on Firefox you will still get garbage resp. wrong page breaks in the printed results after activating this mode.

You aren't kidding. Came here after exporting to PDF on Firefox (hadn't seen the doc warning), which produced terrible results. This is a highly needed improvement.

jlperla commented 1 year ago

FWIW I found the revealjs output with decktape with the screenshot size to be excellent. e.g.

decktape myfile.html myfile.pdf --screenshots-size=1280x720

The only issue real issue are errors about having trouble finding embedded fonts when using adobe acrobat (that don't seem to pop up on other pdf viewers).

cderv commented 11 months ago

For reference, good recipe on using docker decktape: https://github.com/quarto-dev/quarto-cli/discussions/7018#discussioncomment-7897967

kjhealy commented 10 months ago

I use decktape from inside R to convert the HTML version of quarto presentations to PDF. I'm presently using quarto prerelease v1.4.534. With the most recent version of decktape (3.11), conversion fails because decktape will not stop printing slides. This might possibly be a version of this old decktape issue: astefanutti/decktape#137, or something like it. What happens is that decktape correctly identifies the number of slides in the deck, prints them all in order, but then just repeatedly prints the last slide forever. If you specify the number of slides to print via decktape's --slides switch, it will correctly terminate after that number of slides. If you specify any n > the number of slides, it will repeatedly print the last slide till it reaches n slides.

To reproduce the problem, create a quarto slide document—the default one created from New File > Quarto Presentation ... in RStudio will do fine. Save it as test.qmd. Render the file to HTML, then from the terminal (and with decktape 3.10 or 3.11 installed) do

decktape --chrome-arg=--allow-file-access-from-files reveal ./test.html test.pdf

Decktape should launch, begin rendering as expected, but not stop after the 4th slide. Instead it just keeps going. No file is produced. To make it render properly, do

decktape --chrome-arg=--allow-file-access-from-files --slides 1-4 reveal ./test.html test.pdf

I believe this is a quarto issue rather than a decktape issue as I can render other non-quarto revealjs decks OK, e.g. this one I found at random that seems to have been written in markdown or directly in html and produced by hugo:

decktape reveal https://ksucs-hugo.russfeld.me/0-basic-content/02-reveal-example-slides/ test.pdf

I apologize for not being able to pin down which quarto prerelease version this issue appeared in ... I'm returning to slides that were happily rendering to PDF last semester in preparation for this semester's classes. Happy to open a new bug report if it seems like it deserves one rather than a comment here.

cscheid commented 10 months ago

@kjhealy Thanks for the report, I can reproduce that. I'll bisect and come back to this.

cscheid commented 10 months ago

The offending commit is 362dbc4bc8556f5be9de806a95e74164c082498c

cscheid commented 10 months ago

Reopening #6800 since that fix breaks the decktape workflow which we want to support. I'll track there.

cscheid commented 10 months ago

@kjhealy Fix is here https://github.com/quarto-dev/quarto-cli/commit/ea55f5740393cf693d079661d77ca72cd05f466f. We're setting up the release candidates for 1.4 tonight, so a new build should be out soon. Thanks again for the report.

kjhealy commented 10 months ago

Fantastic, thanks so much.

jlperla commented 10 months ago

After having this in my workflow last year (and for the upcoming term) my conclusion is that: (1) quarto+revealjs is great for slides - and thanks to the quarto team for pushing me to try it over beamer/pdf; (2) decktape is pretty slick once properly configured and is certainly a good replacement for PDF output of slides, which was the main reason to use latex/pdf; but (3) it is a pain to setup and maintain outside of the rest of the publication toolchain. I think if you supported proper revealjs slide output "out of the box" as an alternative to beamer, it would help the transition for a lot of people.

For example, most people I know have never directly installed node before, etc. (I hadn't) This is especially a problem when I want to think about moving to github action based publications, etc. This latest bug shows how fragile things can be with quarto versions.

So I hope that you guys consider building decktape support direclty into the quarto publication options, which lets you pin version numbers, add in proper unit tests, and becomes much easier for outsiders to get pdf access when trying to replace latex with revealjs.

mcanouil commented 10 months ago

So I hope that you guys consider building decktape support direclty into the quarto publication options

This is the whole point of having this issue (still) open.

mpf commented 10 months ago

Following @jlperla suggestion to use decktape, I observe significant font problems with math. Here's the qmd source, followed by a screenshot of the reveal result in Firefox (perfect) and of the PDF output from decktape.

---
format: revealjs
---

## Slide

$$ \mathcal{X} $$

$$\sqrt{\sum_i^n \sigma_i}$$

revealjs

revealjs (Firefox) screenshot

pdf

This was produced using

decktape math.html math.pdf --screen-shot=1280x720

pdf (Skim) screenshot

I'll be glad for suggestions on how to get proper output out of decktape.

jlperla commented 10 months ago

@mpf

It isn't perfect, but I had to fudge some mathjax settings to get things to work consistently. Maybe try:

html-math-method: # until Quarto 1.4 is released?
  method: mathjax
  url: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"

In the header?

mpf commented 10 months ago

That works. Thank you!

I note the comment in your solution: until Quarto 1.4 is released. I'm using v1.4.542, so still an issue.

jlperla commented 10 months ago

Previously someone had pointed me to #4493 but it looks like the target milestone was changed in December. @cderv is the workaround here I posted still the best option for the upcoming 1.4 release?

cderv commented 10 months ago

is the workaround here I posted still the best option for the upcoming 1.4 release?

Yes - we'll tackle all the revealjs work and updates for next version. Thanks for your patience

mpf commented 9 months ago

It isn't perfect, but I had to fudge some mathjax settings to get things to work consistently. Maybe try:

html-math-method: # until Quarto 1.4 is released?
  method: mathjax
  url: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"

In the header?

This workaround solves the font issue. Thanks!

However, it does cause javascript errors that show up in the console, such as MathJax.Hub is undefined. These errors can be seen on these slides produced by this MWE.

I sometimes have issues with defining macros in mathjax, and I wonder if these errors may be related. Any ideas on how to fix these?

Screenshot 2024-02-07 at 12 15 29 PM

shriv commented 2 months ago

On the latest Quarto 1.5.57, I find several issues with Decktape rendering:

cderv commented 2 months ago

Thanks for the report. @shriv can you share a repo with the slide with problem ?

Last time I used decktape to produce PDF from my slides, it works well.

BTW the command I ran is the following (using docker container)

docker run --rm -t -v .:/slides astefanutti/decktape -s 1280x720 generic /slides/index.html slides-full.pdf

Using generic mode instead of revealjs mode allowed to simulate arrow navigation and gets all the slides as if it was recorded on screen.

If slides are showing correctly in HTML in browser, issues you are encountering could be with decktape and revealjs only. Not sure we can do something in Quarto. You should look into this. If we do generate bad HTML that prevent decktape rendering, then we'll be happy to fix.