On the first use case, a marginfigure chunk, I realized I could try tufte::margin_note() instead, so I put this inside a r code chunk:
```{r margin, eval=knitr::is_html_output(), echo=FALSE}
tufte::margin_note("new test")
```
It did not have the intended effect though. The html version renders the following in the main column:
#> [1] "<label for=\"tufte-mn-\" class=\"margin-toggle\">⊕</label><input type=\"checkbox\" id=\"tufte-mn-\" class=\"margin-toggle\"><span class=\"marginnote\">new test</span>"
It does not appear in the pdf version (as expected).