Skip to content

Conversation

@vincentarelbundock
Copy link
Contributor

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

#182
#99

The solution is to add this to the template:

$if(highlighting-macros)$
$highlighting-macros$
$endif$

@cderv
Copy link
Collaborator

cderv commented Jul 22, 2021

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
Copy link
Contributor Author

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
Copy link
Collaborator

cderv commented Jul 22, 2021

In your article,

  • do you have some non R chunk ?
  • do you have some verbatim code (non executed) that you apply a class language too ? like
    ```yaml
    title: hello
    ```

This is the two case I need to reproduce.

@vincentarelbundock
Copy link
Contributor Author

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
Copy link
Collaborator

cderv commented Jul 22, 2021

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

Thanks again.

@cderv cderv added the next to consider for next release label Jul 22, 2021
@nbenn
Copy link

nbenn commented Aug 16, 2021

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
Copy link
Collaborator

cderv commented Aug 16, 2021

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

```{r}
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
Copy link

nbenn commented Aug 16, 2021

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 cderv changed the title jss ShadedRegion macros Add highlighting macros for Pandoc in JSS template Aug 16, 2021
@cderv cderv merged commit 22debeb into rstudio:master Aug 16, 2021
@cderv
Copy link
Collaborator

cderv commented Aug 16, 2021

Thanks @vincentarelbundock !

@vincentarelbundock
Copy link
Contributor Author

Thank you for all your work on this great package!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

next to consider for next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants