-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Implement LaTeX formula render #5073
Conversation
Really? Id expected it to be automatic as it should just print whatever it shows |
Yeah, now it's exported broken PDF, in fact will export a html but with .pdf suffix.... Can you help? @JorisGoosen An additional question is why we didn't use Qtwebengine's built-in html2pdf function, which can fully export what the browser can render. Are there additional considerations here? |
Additional considerations to keep in mind:
|
For point 1,3 ,now we will get both MathML and HTML in result page (also to clipboard) which was set from Katex config option For point 2: katex render html element what we added in jaspHtml which just pass strings so it will not break any tests (This works fine, at least in the use case I tried). Now we cannot render it in Rstudio Viewer because now render by qt webengine,but if we want we can using katex from its R bind package or tinyTex. |
d39ff6c
to
4e6e842
Compare
Sorry for this PR has been stuck for a while (I blame it on my addiction to Zelda: Tears of the Kingdom these days😂) So far I think it's ready to review. The following known issues will be finalized in a later stage after you feedback.
|
We are using the same functions from webengine for this actually.
connect(m_view.data(), &[QWebEngineView](https://doc.qt.io/qt-6/qwebengineview.html)::pdfPrintingFinished, this, &Html2PdfConverter::pdfPrintingFinished); ->
|
Sorry I change the delimiters |
Also pdf seems to work fine on my system? |
Ok Ill fix the testmodule |
Ah yeah, but why it just be a .PDF file(but in fact a html file with that suffix) in my two Windows PC built... that would be good if it works because I never found the reason. |
Ill try it on windows too then, this was macos |
Well, I dont know what happened on your system im afraid, but this is what I get on windows: |
@Kucharssim so you think the If you wanna play some more with the latex before approving this? |
Also, this PR doesnt implement latex for help, we do want that right? |
That had been implemented in my dev branch and I'll launch it after this PR is merged with some minor adjustments:-) |
No, but also we'll have: jasp-stats/jaspBase#127 so we would avoid that altogether.
Yes I wanna play before this is merged, unfortunately I am running out of time this week - will try to check it out next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice!
I found some corner cases though, mainly with copy pasting the output. To reproduce, use this code in a test module:
jaspResults[["html"]] <- createJaspHtml(title = gettextf("Formula for %s", jaspBase::mathExpression(r"{\mathcal{M}_{1}}")))
jaspResults[["html"]]$text <- gettextf(
"Under %s, we have %s where %s",
jaspBase::mathExpression(r"{\mathcal{M}_1}"),
jaspBase::mathExpression(r"{p(\theta \mid y) = \frac{p(\theta) \times p(y \mid \theta)}{p(y)},}", inline = FALSE),
jaspBase::mathExpression(r"{p(y) = \int p(\theta) \times p(y \mid \theta) d\theta.}", inline = FALSE)
)
jaspResults[["table"]] <- createJaspTable(title = gettextf("Summary for %s", jaspBase::mathExpression(r"{\theta}")))
jaspResults[["table"]]$addColumnInfo(name = "parameter", title = gettext("Parameter"))
jaspResults[["table"]]$addColumnInfo(name = "estimate", title = jaspBase::mathExpression(r"{\mathop{\mathbb{E}}(\theta \mid y)}"), type = "number")
jaspResults[["table"]]$addColumnInfo(name = "variance", title = jaspBase::mathExpression(r"{\mathop{\mathbb{VAR}}(\theta \mid y)}"), type = "number")
jaspResults[["table"]]$setData(
list(
parameter = jaspBase::mathExpression(c("\\alpha", "\\beta", "\\gamma", "\\delta")),
estimate = rnorm(4),
variance = rexp(4, 1)
)
)
jaspResults[["table"]]$addFootnote(
message = gettextf(
"Posterior expectation for parameter %s is computed as %s",
jaspBase::mathExpression("\\theta"),
jaspBase::mathExpression(r"{\bar{\theta} = \frac{\sum \theta_i}{n}}")
),
symbol = jaspBase::mathExpression("\\ast"),
colNames = "estimate"
)
In JASP, it looks like this (really nice!!!):
Issues
- Using a subscript in a
jaspObject
title (e.g.,\mathcal{M}_{1}
) instead appears as a superscript:
-
Using math formula in
jaspObject
title and then exporting the results into a pdf puts each symbol on a new line:
-
Results -> Copy -> Paste to google docs seems to have an issue with copying the table + the indentation is not correct (display equations are not on a separate line)
-
Copy
jaspHtml
object -> paste to a google doc copies the LaTeX code, not the symbols:
-
On the other hand, copy
jaspHtml
object -> paste to overleaf copies the correct LaTeX code but wrapper up in html tags so one has to remove that manually to get the correct output:
-
Copy table -> paste to google docs renders it incorrectly (same as in point 3)
-
Cope LaTeX of table -> paste to overleaf gets the correct LaTeX code but again wrapped up inside of html code
Regarding 1 and 2, not sure how important this is - but if we can fix it then it would be great.
Regarding 3 and 6 we probably cannot expect that we can copy any symbol from LaTeX into a word processor correctly... But some symbols can be copied from a jaspHtml object but not from a jaspTable, so perhaps there is something wrong with that.
Regarding 4, 5, and 7, that's related to #5081: Merging this PR would solve 7, but to fix both 4 and 5 we would probably have to implement "copy to LaTeX" option for jaspHtml
as well.
Except for point 1, these issues only affect exporting results from JASP, it does not affect UX in JASP itself. Considering that that issue is relatively minor, I think we could already merge this and work on the other issues elsewhere. Unless @shun2wang wants to polish it here now. @JorisGoosen any comments?
Ah, also it would be nice to allow editing a formula that user wrote in a note by double clicking it. Currently you can only delete it and write it again. But again that's just a minor thing. |
I think the google doc thing is because we use a specific katex font to render the formulas right? Is there a way to get a render from katex.js? As in, a |
That may be for some of the symbols, but some of the same symbols can be copied from a jaspHtml to a google doc but not from a jaspTable to a google doc, so perhaps something else it going on there as well? |
Hi, @Kucharssim What browser/version are you using to look a exported HTML? I take care of Chromium (version 108 or older) used by JASP Qt webengine to use both Katex's MathML and Html output, which I did not do when exporting...So there may be some Mathml issues here generated for the superscript things...The advantage of using MathML is that you can paste it directly into MS Word and get beautiful formula rendering. Thanks for pointing these out, Katex does have issues with confusing subscripts and subscripts in some cases, this one I thought I fixed it so I will revisit it again😀
i will keep in mind, in fact there may indeed be a good solution here. but not now:-)
Yeah, it may because font things, to be honest I haven't tested Google doc.
Well, I think not, Katex doesnot have that but MathJax will... |
Good point, ill have a look |
Exporting to html looks nice in Chrome, Safari, even in Edge (run from a VM), so there does not seem to be a problem there. The subscripts/superscript confusion only appears in JASP (where we use some chromium based browser I assume) and if I export to a pdf - and only if it's in the title of a jaspObject -- the subscript is correctly rendered elsewhere.
Yeah, I thought that should be the case as well... I did not try MS Word (I don't have it), hence I tried it in Google docs. |
Considering that chrome/chromium's support for MathML is not very complete until version 108, and the latest version of chromium we use in Qt is 108 (actually I guess your build is Qt6.4 (chromium 102 see here) so there may be A bit of a surprise, but it's strange that Katex only promotes MathML as an accessibility boost instead of displaying it when MathML and Html are output at the same time, so I guess there may be some thing else in jaspObject. I'll revisit it anyway, leave this PR or maybe merged for now, I'll improve it in another PR (to bringing formula rendering to help docs). |
It's very pretty |
@JorisGoosen In Google doc I can only paste some htmld code, so I doubt it respect the MIME types ( EDIT: because it depends on browser what you using, in Firefox with google docs have different behavior... EDIT2: Google Docs needs install a Offline Editing Extension in chrome if you install it the behavior will same in FireFox. |
Yeah there is something off about the copy code, im having a look at it now. However, I also tried the "experimental-web-features" and it doesnt help the copying. Also, I dont understand why the fractions dissappear... |
This may require special annotations for some of MathML's media types, if you paste this into MS Word you'll get a nice formula.
perhaps with escape? |
The |
@JorisGoosen From a clipboard raw data viwer with browser API I can see it paste a |
Ah yes, I fixed that already. Ill push it |
Implement for exported html rendering style change github editor always screw up formatting style changes again!
oops! wrong cleanup Cleanup
Relpaced by #5109 |
Implement LaTeX support for JASP result.