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
``` `
\newif\ifsol
\sol`r ifelse(solution, 'true', 'false')`
# Simple example of non-compiling code
\ifsol
Text to conditionally skip
\fi
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}
\label{simple-example-of-non-compiling-code}}
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
\newif\ifsol
\soltrue
the file which does not work has instead
\newif\ifsol
\def\iffalse\iftrue
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.
As for your suggestion to use a conditional chunk with asis, I just tested it on the RStudio cloud (on my machine I set things up to use Pandoc 2.13) with a simple example and it seems to work. The only down side of that is that the parts I wish to include conditionally are in LaTeX, and using code chunks the editor syntax highlighting won't work. In addition I have several files using the code which doesn't work and it would not be much fun having to change all of them.
For clarification my intention is not to compile different things for different formats (LaTeX or HTML) but just really to includes sections of text conditionally (solution to exercise in the specifics).
Yes I know. You could try visual editor in RStudio IDE, maybe it can detect better this.
As this is now how Pandoc is rendering things until it is possibly fixed, you need to stick with pandoc 2.13.
Or deactivated the Pandoc extensions that cause the trouble as it was adviced on the issue thread in GIthub
LaTeX reader: improve handling of newif.
Adding a pair of braces around the second argument of `\def`
prevents LaTeX from an emergency stop with: Closes #6096.