I am trying to put a margin note in my Tufte Latex document that is partially generated by r code, but have been unsuccessful. Code blocks set to print in the margin only seem to put plots there, not text or tables. Margin notes called with tufte::marginfigure()
throw an error if they have inline code in them. And margin figure blocks ignore inline code. I have been successful getting my code-generated text to print in the margin with a footnote, but then I get footnote numbering, which I don't want. I thought of turning off numbering on that footnote, but haven't been able to.
Here's an example:
---
title: "Tufte Test"
author: "Neal"
date: "`r Sys.Date()`"
output:
tufte::tufte_handout: default
---
```{r setup, include=FALSE}
library(tufte)
library(tidyverse)
```
Here is some normal text with inline code: 2+3=`r 2+3`
\vspace{10pt}
```{r block, fig.margin=TRUE, echo=FALSE, results='asis'}
cat('Here is a margin code block with code-generated text and a plot.')
mtcars %>% ggplot(aes(mpg, disp)) + geom_point()
cat('The text stays in the main body.')
```
\vspace{10pt}
I can combine text and code in a footnote^[2+3=`r 2+3` \newline\vspace{10pt}], but I get footnote numbering, which I don't want.
```{marginfigure, echo=TRUE}
Here is a margin figure with inline code that doesn't work: 2+3=`r 2+3` \newline\vspace{10pt}
```
`r tufte::margin_note('This is a margin note. If I try to include inline code in it, I get an error because it "failed to tidy R code in chunk"')`
And the output: tufte-test.pdf
Any ideas? Thanks.