1

the example from https://bookdown.org/yihui/rmarkdown-cookbook/cross-ref.html does not work for me. I simply get references like "Figure @ref(fig:cars-plot)." appearing in the pdf or html document, i.e the raw markdown appears rather "Figure 1" The code is below and the versions of installed packages are below that. It seems to be an emacs problem. People have tried the attached code in Rstudio and the references come out correctly.

---
title: Cross-referencing figures, tables, and equations
author: Generated by bookdown
output:
  bookdown::html_document2: default
  bookdown::pdf_document2: default
---
See Figure \@ref(fig:cars-plot). 
par(mar = c(4, 4, .2, .1)) 
plot(cars)  # a scatterplot 
> sessionInfo()

R version 4.1.0 (2021-05-18) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.3 LTS

Matrix products: default BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so

locale: [1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_AU.UTF-8 LC_COLLATE=en_AU.UTF-8
[5] LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8
[7] LC_PAPER=en_AU.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_4.1.0 magrittr_2.0.1 fastmap_1.1.0 tools_4.1.0
[5] htmltools_0.5.2 yaml_2.2.2 tinytex_0.36 stringi_1.7.6
[9] rmarkdown_2.11 highr_0.9 knitr_1.37 stringr_1.4.0
[13] xfun_0.29 digest_0.6.29 rlang_0.4.12 evaluate_0.14
``

and the pandoc command is

/usr/bin/pandoc +RTS -K512m -RTS test4.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output test4.tex --lua-filter /home/dun280/local/lib/R/x86_64-pc-linux-gnu/4.0/site-library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/dun280/local/lib/R/x86_64-pc-linux-gnu/4.0/site-library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable 'geometry:margin=1in'

  • Sorry, I can see that the formatting has been mucked up. It seems that StackExchange allows some markdown formatting. I don't know how to format the code in my question without StackExchange interpreting it. However the link to rmarkdown-cookbook in the question goes to a properly formatted version of the code – user7543513 Feb 12 '22 at 10:08
  • The problem seems to be that the command "M-n e" which runs the command polymode-export sends the following to R rmarkdown::render('test.Rmd', output_format = 'pdf_document', output_file = 'test.pdf', knit_root_dir=getwd()) rather than rmarkdown::render('test.Rmd', output_format = 'bookdown::pdf_document2', output_file = 'test.pdf', knit_root_dir=getwd()) – user7543513 Jul 25 '22 at 07:17

1 Answers1

1

It turned out to be quite simple. The first time a document is processed, M-n e brings up the question choose exporter: for which I set markdown-ess. Then it says export to:. The tab key brings up options. Choose "AUTO DETECT", this will set the R command to something like

rmarkdown::render('test.Rmd', output_format = 'bookdown::pdf_document2', output_file = 'test.pdf', knit_root_dir=getwd())

and the output_format = 'bookdown::pdf_document2' makes everything work.