Cross-referencing single words/sentences in R Markdown

Hello!

I am looking to add cross-referencing to single words in an R Markdown document so as to not have to manually update the relevant words when changes are made to them. More specifically, I have a number of references throughout the document to criteria which are called "QUANT1", "QUANT2", etc. The numbering can change depending on their placement in a table contained elsewhere in the document.

Reading chapter 2.2.4 of the bookdown book, it seems possible to add cross-references to single words (or even sentences).

Specifically, the book states (at the end of the chapter) that "[t]ext references can be used anywhere in the document (not limited to figure captions). It can also be useful if you want to reuse a fragment of text in multiple places."

Let's say I have a reference like this:

(ref:quant1) QUANT1

The reference is generated as expected (i.e. it is not shown in the text after rendering). However, I cannot figure out how to make a reference to it in running text (i.e. not in a figure, table or other caption). I have tried several methods of referencing this in the running text, none of which work:

(ref:quant1)
`(ref:quant1)`
"(ref:quant1)"
\@ref(quant1)

Does anyone know how to make use of references created as outlined above in running text?

Well, now it works...

Define the reference as follows:

(ref:label) reference

It is then possible to invoke the reference in the running text simply by printing (ref:label) at the appropriate location in your document. Whatever is in reference will then be printed.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.