Interest Ask. I would like to know the right way to do this, but this (very) hacker way works for me.
--- output: html_document: css: ~/knitr.css --- ```{r, include=FALSE} library(knitr) knit_hooks$set(plot = function(x, options) { fig_fn = paste0(opts_knit$get('base.url'), paste(x, collapse = '.')) fig.cap <<- knitr:::.img.cap(options) sprintf("<figure><img src='%s'><figcaption>%s</figcaption></figure>", fig_fn, fig.cap) }) ``` ```{r, fig.cap = 'Figure I: the plot of my figure.'} plot(1:5) ```` I say some things and some other things. Oh, yeah please refer to `r fig.cap`

This works for the most recently created shape, but you can work on the shape counter or something else to create unique variables for each label so you can refer whenever you want.
source share