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

Incorrectly rendering of a code snippet #149

Closed
terrytangyuan opened this issue Jan 8, 2018 · 10 comments
Closed

Incorrectly rendering of a code snippet #149

terrytangyuan opened this issue Jan 8, 2018 · 10 comments

Comments

@terrytangyuan
Copy link

The following code snippet

library(dlm)
form <- function(theta){ dlmModPoly(order = 1, dV = exp(theta[1]), dW = exp(theta[2])) }
model <- form(dlmMLE(Nile, parm = c(1, 1), form)$par)
filtered <- dlmFilter(Nile, model)

was rendered incorrectly using R Journal template. The following text is displayed in the generated PDF file.

\begin{Schunk} \begin{Sinput} library(dlm) form <- function(theta){ dlmModPoly(order = 1, dV= exp(theta[1]), dW = exp(theta[2])) } model <- form(dlmMLE(Nile, parm = c(1, 1), form)$par) filtered<- dlmFilter(Nile, model) \end{Sinput} \end{Schunk}

Any ideas on what I might have done incorrectly here?

@yihui
Copy link
Member

yihui commented Jan 9, 2018

Duplicate of #6 #10 #49 #132 etc. You didn't do anything wrong. It is our bug, which we haven't had a chance to fix yet.

@jaredhuling
Copy link

jaredhuling commented Mar 31, 2018

Any idea of how to go about to fixing this? The underscore problem is making it impossible to use rticles for jss. I'm willing to work on this but I'm really not sure where to start

@jaredhuling
Copy link

If there is a way to grep through the resulting .tex file created after pandoc, one hack would be to insert a \begin{verbatim} \end{verbatim} around calls to CodeChunk, CodeOutput in jss_article.R and then clear out the verbatims after pandoc is done.
ie
hook_chunk <- function(x, options) {
if (output_asis(x, options)) return(x)
paste0('\begin{verbatim}\n\begin{CodeChunk}\n', x, '\end{CodeChunk}\n\end{verbatim}')
}
This way pandoc will properly handle the inside contents. But here I guess there is a risk of stripping out actual calls written by the user to verbatim, so maybe some unique identifier after the \begin{verbatim} could be used, like \begin{verbatim}%removethis\n

@yihui
Copy link
Member

yihui commented Apr 2, 2018

@jaredhuling That is exactly the hack on my mind. I just haven't had time to do it. You could use a post_processor in the output format to post-process the .tex file, e.g., https://github.com/rstudio/bookdown/blob/cd2fb76f818528e/R/latex.R#L45-L79 (certainly not the best example but shows the idea).

@jaredhuling
Copy link

Does anything special need to be done to enable the prost_processor to be run? I've gotten the wrapper part to work, but the post_processor doesn't seem to be called when I put it into jss_article()

@yihui
Copy link
Member

yihui commented Apr 2, 2018

@jaredhuling You need to add it to base$post_process: https://github.com/rstudio/rticles/blob/master/R/jss_article.R

@jaredhuling
Copy link

jaredhuling commented Apr 2, 2018

I think what's happening is the intermediate .tex file doesn't compile and it bombs out before it gets to the post processing step.
edit:scratch that

@yihui
Copy link
Member

yihui commented Apr 2, 2018

@yihui
Copy link
Member

yihui commented Jul 3, 2018

Fixed. Please try devtools::install_github('rstudio/rticles'). Note that it will require Pandoc 2.2.1. You can use the Preview version of RStudio if you do not want to install Pandoc separately: https://www.rstudio.com/products/rstudio/download/preview/

yihui added a commit that referenced this issue Jul 3, 2018
…raw latex block ```{=latex} for R Journal articles, which is the same fix as 8da3d29
yihui added a commit that referenced this issue Jul 3, 2018
…raw latex block ```{=latex} for R Journal articles, which is the same fix as 8da3d29
@github-actions
Copy link

github-actions bot commented Nov 2, 2020

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants