rstudio / rticles

LaTeX Journal Article Templates for R Markdown
https://pkgs.rstudio.com/rticles/
1.47k stars 518 forks source link

Add cross-referencing to all rticles #328

Open etiennebr opened 3 years ago

etiennebr commented 3 years ago

I think that it could be easier to use cross-referencing in rticles. References to tables, figures and equations are ubiquitous to scientific papers. bookdown provides a generic solution that, I think, is more likely to bring users to success from the start.

\begin{equation}
(\#eq:eq)
c = a \cdot b
\end{equation}

see \@ref(eq:eq)

Gives image

@cderv suggested that maybe we could provide two possible default outputs in the skeletons. Something like:

output:
  rmarkdown::pdf_document:
    base_format: rticles::mdpi_article
  bookdown::pdf_book: 
    base_format: rticles::mdpi_article

It has the benefit that the default output does not require bookdown, and it shows that other outputs are possible. While cross-referencing would not work from the start, enabling it would be a matter of picking the next output in the list. If using bookdown as the default output is excluded, then I think this solution is pretty good.

Following #327, I believe that the solution might need to be applied to all skeletons.

etiennebr commented 3 years ago

From https://github.com/rstudio/rticles/pull/327#issuecomment-699640117

Make that

output:
  rticles::mdpi_article: default
  bookdown::pdf_book: 
    base_format: rticles::mdpi_article
cderv commented 3 years ago

Would a vignette in rticles explaining how to use bookdown features by modifying the yaml header be a good idea to better document this ?

etiennebr commented 3 years ago

I agree that a vignette would be useful since there are so many options from bookdown. I still believe that using bookdown::pdf_book as default would enlarge the pit of success, though.

sbgraves237 commented 3 years ago

I just noticed that figure references stopped working with Ecfun::ForecastingNuclearProliferation vignette: For example, the second line of the "Introduction" in the PDF this Rmd file produces used to display "see Figure 1." Now it displays "see Figure @ref(fig:plot)."

Section "4.7 Cross-referencing within documents" of "RMarkdown Cookbook" says, "To use cross-references, you will need: ... an output format from bookdown (e.g., ... pdf_document2 ...) in the YAML output field.". I changed "output: pdf_document" to "output: pdf_document" and got, "Error in eval(parse(text = name)) : object 'pdf_document2' not found".

What do you suggest I do to get around this? Thanks, Spencer Graves

etiennebr commented 3 years ago

Hi @sbgraves237, looking at your vignette, this looks like an issue with bookdown, rather than rticles. But I think the solution is the same than above, although you'll either need xelatex or to include a preamble with \DeclareUnicodeCharacter.

Have you tried

output: 
  bookdown::pdf_book:
    latex_engine: xelatex
cderv commented 3 years ago

@sbgraves237 I am not sure your issue is related to rticles 📦 To use cross reference, you need to use a format from bookdown as explained in the book you linked

output: pdf_document

must be changed to

output: bookdown::pdf_document2

Please ask your question on https://community.rstudio.com or open an issue in the correct repo rather than asking in the middle of another thread. Thanks !

sbgraves237 commented 3 years ago

Thanks. "output: bookdown::pdf_book:latex_engine: xelatex" fixed the problem. Thanks again.