R Markdown with \newif fails to compile to pdf after update

After the latest update to RStudio "Ghost Orchid" (Build 372) the RMarkdown below fails to compile to pdf on macOS Monterey, as well as on RStudio cloud.

An identical file compiles fine on a different machine running previous versions of both RStudio and macOS ("Juliet Rose" (Version 1.4.1717), macOS Big Sur).

Any help to fix the problem is highly appreciated, thanks!

title: "minimalTest"
output: pdf_document

``` {r, include = F}
solution <- TRUE 
``` `

\sol`r ifelse(solution, 'true', 'false')`

# Simple example of non-compiling code


Text to conditionally skip


The error produce is the following

! Use of ifMT@inlist@ doesn't match its definition.
MT@setupfont ...g MT@check@font ifMT@inlist@ else 
                                                  MT@vinfo {Setting up font ...
l.77 code}

The same error is generated under Ubuntu with an earlier version of RStudio. It's a LaTeX error message. Try this

title: "minimalTest"
output: pdf_document

``` {r, include = TRUE}
solution <- TRUE 

\def\sol{r solution}


Thanks a lot for your response. Yes, that's absolutely right, it's LaTeX to throw the error. However, from comparing the tex files between the machine where it compiles and that where it doesn't I find the following lines differ in the generated .tex

the file which works has


the file which does not work has instead


Is this a difference due to pandoc?

Also, I am not sure I understand how to use \def instead. Basically I want to use the variable solution to conditionally include text in a file, and I have that code in a large number of files, so I would really like to find a solution that allows me to compile those files without modifications on the new machine. Since the identical file compiles on different machines, something must have changed in the way one of the softwares involved handles the source.

Too many moving pieces. Let me think about the problem in the terms you've now described it—conditionally including text based on the evaluation of some arbitrary R command and get back to you.

Just ran a few more tests confirming the suspicion that it may be a pandoc issue. In fact doing the following works

  • installing a previous version of pandoc (2.13 is the latest I know to work on my laptop)

  • telling rmarkdown to use the desired version of pandoc: rmarkdown::find_pandoc(version="2.13")

  • rendering the document with a command instead of pressing the knit button
    rmarkdown::render("minimalTest.Rmd", pdf_document())

For the last point it would be great if there were an option in RStudio to specify the location of the pandoc to use, rather than having to go via render.

More generally to avoid this sort of problem it would be even better to be able to choose the pandoc version to use in RStudio

I can't reproduce the problem due to lack of a minimal working example‐what is working with the portions of tex posted is missing something for it to work.

Since the goal is to salvage existing code, there's nothing I can offer beyond using \def. I can post more detailed examples of that with error trapping being done in the online r snippet if of interest.

Thanks. Actually, I do now have a workaround: configure RStudio to use panic 2.13. Then all my files compile correctly without problems (including the minimal example originally provided).
Some more details are here Can pandoc deal with ifdefined or skip certain parts with special LaTeX macros. · Issue #6096 · jgm/pandoc · GitHub

1 Like