I am having issues using the Visual Editor to create cross-references while building a bookdown site. I want to have a link on one page to a section heading on another page, with the section header as the link text on the first page.
The Cross-references chapter in the bookdown book says I can do this by putting square brackets around the text of the link header like this
[Section header text]. Indeed this works as long as I am not using the Visual Editor in RStudio. When using the visual editor, it escapes the square brackets so the code ends up like this
\[Section header text\]. I can remove the escapes in the code view, but as soon as I switch back to the Visual Editor it adds the escapes back.
The strange thing is, the square brackets work if I am linking to a section on the same page. Only links to sections on other pages have the escape characters added.
Similarly, I can use the Visual Editor to insert a link (Insert > Link...) and change the link type to Heading, upon which the dialog window gives me a list of headings in the current document, but no headings from other documents. If I insert a heading to a section in the current document, it uses the square bracket format described above, and does not escape the brackets; i.e. it works.
So how do I get this to work for section headings in other documents?
I did try using the Visual Editor to add
@ref(section-header-text). As expected, section headers from all documents show up in the preview, and I am able to select any of them. When the page is converted to HTML, the link works, but the text for the link is a number, not the section heading text. I suppose the number is the automatically generated id number for that section. I could solve my problem if I knew how to change the link text when using the
@ref() method. Is that possible?
Thanks for any help.