Search code examples
rbookdown

Using pandoc-crossref with R bookdown


Is it possible to use pandoc-crossref in bookdown?

I tried to change the yaml header to:

output: 
    bookdown::tufte_book2:
        toc: yes
        highlight: tango
        pandoc_args: -F /usr/local/bin/pandoc-crossref

Which should pass the filter to pandoc, but I get the error:

pandoc: Error running filter  pandoc-crossref:
Could not find executable ' pandoc-crossref'.

The above error does not make sense, as I entered the correct path. What kind of env is bookdown using, which is precluding the access to the filter file?


Solution

  • Here is an example

    ---
    output: bookdown::html_document2
    ---
    
    # Section name {#id}
    
    ```{r pressure, echo=FALSE, fig.cap='test plot'}
    plot(pressure)
    ```
    
    Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. To cross-reference the figure, use `\@ref(fig:pressure)` to produce Figure \@ref(fig:pressure). All this is found within the section \@ref(id).
    

    Which produces...

    enter image description here

    See https://bookdown.org/yihui/bookdown/figures.html for the official documentation.