rstudio / pagedown

Paginate the HTML Output of R Markdown with CSS for Print
https://pagedown.rbind.io
Other
885 stars 129 forks source link

`chrome_print()` hangs when printing html with maths produced by Quarto #320

Open niklz opened 10 months ago

niklz commented 10 months ago

Hi,

I've been having issues using chrome_print() to produce a pdf from html that I have made from a Quarto document. Digging deeper I have found that it's due to the presence of maths symbols. I am not sure where in the document pipeline the failure is occurring, as the same document renders when using RMarkdown instead of Quarto.

Here's a minimal example of what I'm doing:

Quarto doc:

---
title: "test"
format:
  html
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

This is a test with some inline maths. $x$ is a cool variable.

Rendering this to produce 'test.html' I am then experiencing the failure (where `chrome_print()` hangs indefinitely) when running:

chrome_print( "test.html", output = "test.pdf", )


I get the following errors:

Error in force(expr) : Failed to generate output in 30 seconds (timeout). [2023-10-24 15:03:05] [error] handle_read_frame error: asio.system:10054 (An existing connection was forcibly closed by the remote host.)

Any advice or ideas of things I could check would be appreciated!

Session info:

sessionInfo() R version 4.2.3 (2023-03-15 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale: [1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=C LC_MONETARY=English_United Kingdom.utf8 [4] LC_NUMERIC=C LC_TIME=English_United Kingdom.utf8

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] Rcpp_1.0.11 pak_0.4.0 ps_1.7.5 later_1.3.1 digest_0.6.33 mime_0.12 R6_2.5.1
[8] jsonlite_1.8.7 magrittr_2.0.3 evaluate_0.22 rlang_1.1.1 cli_3.6.1 promises_1.2.0.1 rstudioapi_0.15.0 [15] rmarkdown_2.23 tools_4.2.3 servr_0.24 processx_3.8.2 httpuv_1.6.5 xfun_0.39 yaml_2.3.7
[22] fastmap_1.1.1 compiler_4.2.3 htmltools_0.5.6.1 websocket_1.4.1 pagedown_0.20 knitr_1.44

cderv commented 10 months ago

Error in force(expr) : Failed to generate output in 30 seconds (timeout).

About this, did you try to increase the timeout already ?

niklz commented 10 months ago

Error in force(expr) : Failed to generate output in 30 seconds (timeout).

About this, did you try to increase the timeout already ?

Yes, I tried increasing the timeout to no avail. Also, if you remove the inline maths (by deleting the $ symbols in the .qmd) chrome_print() works flawlessly and very quickly.

cderv commented 10 months ago

Thanks for the report. I'll try to have a look into this. It seems related to how mathjax is loaded then... something seems to hang the page load and the expected websocket message is not sent. This is not easy to debug.

In the meantime you could try another chrome R package (like chromote or crrri) that could communicate with chrome, but I suspected it will be the same error. Changing the HTML math method for the format may be the best workaround for now.

yihui commented 10 months ago

I'd suggest that you try katex instead of the default mathjax: https://quarto.org/docs/output-formats/html-basics.html#latex-equations katex is often a lot faster in rendering math expressions.

niklz commented 10 months ago

I'd suggest that you try katex instead of the default mathjax: https://quarto.org/docs/output-formats/html-basics.html#latex-equations katex is often a lot faster in rendering math expressions.

I can confirm that using html-math-mathod: katex in the html output options produces html with maths symbols which chrome_print() can handle, thanks!

I can consider this issue closed, however I guess the bug with mathjax is still at large

cderv commented 10 months ago

We'll keep that open to see how we could fix the issue with this Mathjax loading. I don't think this is a timing issue but rather something related to how it is loading, and the websocket process not intercepting and so hanging.