rstudio / rticles

LaTeX Journal Article Templates for R Markdown
https://pkgs.rstudio.com/rticles/
1.46k stars 516 forks source link

Add highlighting macros for Pandoc in JSS template #422

Closed vincentarelbundock closed 2 years ago

vincentarelbundock commented 2 years ago

Compiling a JSS article results in an error about "Shaded Environment undefined". The same error was previously reported for different article types here:

https://github.com/rstudio/rticles/issues/182 https://github.com/rstudio/rticles/issues/99

The solution is to add this to the template:

$if(highlighting-macros)$
$highlighting-macros$
$endif$
cderv commented 2 years ago

Hi @vincentarelbundock,

Can you just share a reproducible example with the issue ?

I want to understand what we missed for not having an error in our test about that.

With the default template, I don't have an issue and it contains a R chunk. So I want to be sure we got it correctly covered.

I assumes this is for other language chunk ?

The fix is the correct one, don't get me wrong.

Thanks for the PR !

vincentarelbundock commented 2 years ago

I just tried to produce a MWE, but for some reason I can no longer replicate the problem.

Sorry!

There are so many parts interacting here. It's a fairly complicated article with kableExtra tables, colors, and tikz diagrams. I also vaguely remember having more issues on some of my machines than others (I run a mac laptop, windows machine, and linux in WSL2).

Would love to help more, but can't at the moment.

Feel free to ignore the PR if you need a test or example.

cderv commented 2 years ago

In your article,

This is the two case I need to reproduce.

vincentarelbundock commented 2 years ago

sorry, should have answered that. No, it's only R, and no verbatim environment with class language. There are some eval=FALSE, but that's it.

cderv commented 2 years ago

Ok thanks. I'll see what I'll do. If you got the error again, please come back and share!

Thanks again.

nbenn commented 2 years ago

I might be able to contribute an example that triggers the issue @vincentarelbundock is trying to address. Creating the JSS draft .Rmd using rmarkdown::draft() and adding a chunk as

```r
foo <- "bar"
```

for me (macOS 11.5, R 4.1.1, rticles 0.20), gives ! LaTeX Error: Environment Shaded undefined. The reason for this is that the resulting code block is wrapped in Shaded and Highlighting environments instead of the standard CodeChunk and CodeInput, one gets when having a chunk like

```{r}
foo <- "bar"
```

The proposed PR does resolve the issue such that both ways of specifying a code chunk compile just fine. Visually, however, they are distinct: Shaded/Highlighting actually provides syntax highlighting, whereas CodeChunk/CodeInput for JSS is strictly b/w.

cderv commented 2 years ago

Thanks. That confirms what I thought.

As context, let me give some details.

This syntax

```r
foo <- "bar"
is a Pandoc direct syntax. It will apply class `r` to the code so that Pandoc's highlighting gets triggered for R syntax. Hence the highlighting. This is why the LaTeX error happens because we need the environment definition required by Pandoc's Highlighting. Using this syntax won't evaluate the code. 

However, using 
foo <- "bar"

will evaluate the code and we specifically output with `CodeChunk` and `CodeInput` (there is `CodeOutput` too) which are defined in `jss.cls`. They don't highlight the same obviously.

So we can add the missing definition for Pandoc's Syntax Highlighting. However, I don't how correct it is for JSS submission if a document contains these environments.
nbenn commented 2 years ago

Thanks @cderv!

I don't how correct it is for JSS submission if a document contains these environments.

It's probably not. However JSS papers are not the only use-case for rticles::jss_article. I was using this in a package vignette with the nojss classopt.

In my post, I was not trying to say, this should or should not be merged. That's up to you @cderv. I simply commented b/c this issue caused me a bit of a headache to track down. For some reason, the rhub machines and CRANs r-devel-windows-ix86+x86_64 machine did not trip over this, only r-devel-linux-x86_64-debian-gcc. Just out of curiosity, @cderv, does that make sense to you that this works in some cases and does not in others?

I guess, with my troubles in mind, I'd be slightly in favor of merging this. Just to make people's life easier. But that's just my opinion.

cderv commented 2 years ago

Thanks @vincentarelbundock !

vincentarelbundock commented 2 years ago

Thank you for all your work on this great package!