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

Adapt github_document() format for @includeRmd #1304

Merged
merged 4 commits into from
Mar 24, 2022
Merged

Conversation

cderv
Copy link
Contributor

@cderv cderv commented Mar 16, 2022

This PR is in relation to rstudio/rmarkdown#2331

I believe the issue could be from the fact that github_document() is unnecessary rendering a HTML self_contained document. html_preview = FALSE should be set in the case of @includeRmd usage.
We could obviously also make some adaption regarding the default value in rmarkdown side but this is not as straightforward (preview is want when rendered in background inside IDE)

There may be other adjustment needed so I am creating this as a draft for now until this is tested and sorted out.

@cderv
Copy link
Contributor Author

cderv commented Mar 16, 2022

Looking at what is produced in the Rd file we get something like this

(\figure{https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;%5Ceta}{\eta})

This does not render well
image

Are image from the web possible to include in R HTML help page ?

The solution to this may also be to deactivate completely the math support for roxygen2 @includeRmd

For comparaison, this is what we get without no specific Math support

In initial md file

$$
\eta_{i} = (\beta_0 + b_{0i}) + \beta_1x_{i1}
$$ 

Result of Pandoc conversion

*η*<sub>*i*</sub> = (*β*<sub>0</sub>+*b*<sub>0*i*</sub>) + *β*<sub>1</sub>*x*<sub>*i*1</sub>

Result in Rd file

\emph{η}\if{html}{\out{<sub>}}\emph{i}\if{html}{\out{</sub>}} = (\emph{β}\if{html}{\out{<sub>}}0\if{html}{\out{</sub>}}+\emph{b}\if{html}{\out{<sub>}}0\emph{i}\if{html}{\out{</sub>}}) + \emph{β}\if{html}{\out{<sub>}}1\if{html}{\out{</sub>}}\emph{x}\if{html}{\out{<sub>}}\emph{i}1\if{html}{\out{</sub>}}

If the equation were to have some specific LaTeX command, we would get a warning and not transformation. Something like

$ echo "$\frac{1}{2}$" | pandoc -t gfm
[WARNING] Could not convert TeX math \frac{1}{2}, rendering as TeX
$\\frac{1}{2}$

The Rd file will have this $\frac{1}{2}$ untouch syntax when math support is not activated.

Trying to give more context on all this so that we can discuss and decide what should be done.

@cderv
Copy link
Contributor Author

cderv commented Mar 17, 2022

If we want to deactivate with github_document(math_method = NULL) this can only be done for rmarkdown >= 2.12
I have made the addition of math_method = NULL conditional to package version.

Obviously if we decide to make math_method = NULL the default in rmarkdown then we won't need this.

@cderv
Copy link
Contributor Author

cderv commented Mar 18, 2022

Looking closer at how to do math in Rd document, I believe this should be a better way: https://docs.ropensci.org/katex/reference/math_to_rd.html

So I think it ok to deactivate webtex in the case of this PR.

@cderv cderv marked this pull request as ready for review March 18, 2022 08:44
[skip ci]
@cderv
Copy link
Contributor Author

cderv commented Mar 18, 2022

@topepo @EmilHvitfeldt this should solve your issue and also undesired change in Rd file when running devtools::document()

@gaborcsardi this PR does not deal with the fact that I don't think a user can adapt the rendering by setting a YAML header in the Rmd included. If we want to support that, this requires other adjustment.

Not sure who should merge this, but this is ready on roxygen2 side.

@gaborcsardi
Copy link
Member

Looks good to me.

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

Successfully merging this pull request may close these issues.

3 participants