-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bookdown::pdf_book does NOT process reference inside table #1184
Comments
Thanks for the report. I believe the difference between the format is because of how the table is written in intermediate When using Table: Foo.
|Reference |
|:-----------------------------------------|
|[@crawfordRiskFactorsMusculoskeletal2021] | which will then be processed by Pandoc, and When using \begin{table}
\caption{(\#tab:unnamed-chunk-1)Foo.}
\centering
\begin{tabular}[t]{l}
\hline
Reference\\
\hline
[@crawfordRiskFactorsMusculoskeletal2021]\\
\hline
\end{tabular}
\end{table} In this case, the content won't be processed by Pandoc citeproc, mainly because Pandoc does not support Markdown in LaTeX blocks (old feature request ! jgm/pandoc#2453). This is an old issue of Pandoc which leads to issue here because you have Markdown syntax inside a LaTeX table. One could leverage this explanation to use another citation engine, and another syntax For example using Example---
title: "mwe"
author: "Raniere Silva"
date: "22/06/2021"
output:
bookdown::pdf_book:
keep_md: true
citation_package: biblatex
keep_tex: true
pdf_document:
keep_md: true
citation_package: biblatex
keep_tex: true
bibliography: mwe.bib
---
```{r}
df <- data.frame(Reference = "\\autocite{crawfordRiskFactorsMusculoskeletal2021}")
knitr::kable(df, caption = 'Foo.', escape = FALSE)
```
```{cat, engine.opts = list(file = "mwe.bib")}
@article{crawfordRiskFactorsMusculoskeletal2021,
title = {The {{Risk Factors}} for {{Musculoskeletal Injuries}} in {{Thoroughbred Racehorses}} in {{Queensland}}, {{Australia}}: {{How These Vary}} for {{Two}}-{{Year}}-{{Old}} and {{Older Horses}} and with {{Type}} of {{Injury}}},
shorttitle = {The {{Risk Factors}} for {{Musculoskeletal Injuries}} in {{Thoroughbred Racehorses}} in {{Queensland}}, {{Australia}}},
author = {Crawford, Kylie L. and Finnane, Anna and Phillips, Clive J. C. and Greer, Ristan M. and Woldeyohannes, Solomon M. and Perkins, Nigel R. and Kidd, Lisa J. and Ahern, Benjamin J.},
date = {2021-02},
journaltitle = {Animals},
volume = {11},
pages = {270},
publisher = {{Multidisciplinary Digital Publishing Institute}},
doi = {10.3390/ani11020270},
url = {https://www.mdpi.com/2076-2615/11/2/270},
issue = {2},
number = {2}
}
``` However, currently the best supported way would be to use text reference. This mechanism allow to have some markdown syntax processed in some places not already. You would use this to have the citation processed by Pandoc then moved into the table. This would look like this---
title: "mwe"
author: "Raniere Silva"
date: "22/06/2021"
output:
bookdown::pdf_book:
keep_md: true
keep_tex: true
bibliography: mwe.bib
---
(ref:citation1) [@crawfordRiskFactorsMusculoskeletal2021]
```{r}
df <- data.frame(Reference = "(ref:citation1)")
knitr::kable(df, caption = 'Foo.')
```
```{cat, engine.opts = list(file = "mwe.bib")}
@article{crawfordRiskFactorsMusculoskeletal2021,
title = {The {{Risk Factors}} for {{Musculoskeletal Injuries}} in {{Thoroughbred Racehorses}} in {{Queensland}}, {{Australia}}: {{How These Vary}} for {{Two}}-{{Year}}-{{Old}} and {{Older Horses}} and with {{Type}} of {{Injury}}},
shorttitle = {The {{Risk Factors}} for {{Musculoskeletal Injuries}} in {{Thoroughbred Racehorses}} in {{Queensland}}, {{Australia}}},
author = {Crawford, Kylie L. and Finnane, Anna and Phillips, Clive J. C. and Greer, Ristan M. and Woldeyohannes, Solomon M. and Perkins, Nigel R. and Kidd, Lisa J. and Ahern, Benjamin J.},
date = {2021-02},
journaltitle = {Animals},
volume = {11},
pages = {270},
publisher = {{Multidisciplinary Digital Publishing Institute}},
doi = {10.3390/ani11020270},
url = {https://www.mdpi.com/2076-2615/11/2/270},
issue = {2},
number = {2}
}
``` BibliographyBut it would only work with bookdown. I acknownledge this is far from ideal. Having this to work would mean to be sure the table is written as a markdown table for the code to be processed. using **pander** package to write the table---
title: "mwe"
author: "Raniere Silva"
date: "22/06/2021"
output:
bookdown::pdf_book:
keep_md: true
keep_tex: true
pdf_document:
keep_md: true
keep_tex: true
bibliography: mwe.bib
---
```{r table, results='asis'}
df <- data.frame(Reference = "[@crawfordRiskFactorsMusculoskeletal2021]")
pander::pandoc.table(df, caption = '(\\#tab:table) Foo.')
```
See table \@ref(tab:table)
```{cat, engine.opts = list(file = "mwe.bib")}
@article{crawfordRiskFactorsMusculoskeletal2021,
title = {The {{Risk Factors}} for {{Musculoskeletal Injuries}} in {{Thoroughbred Racehorses}} in {{Queensland}}, {{Australia}}: {{How These Vary}} for {{Two}}-{{Year}}-{{Old}} and {{Older Horses}} and with {{Type}} of {{Injury}}},
shorttitle = {The {{Risk Factors}} for {{Musculoskeletal Injuries}} in {{Thoroughbred Racehorses}} in {{Queensland}}, {{Australia}}},
author = {Crawford, Kylie L. and Finnane, Anna and Phillips, Clive J. C. and Greer, Ristan M. and Woldeyohannes, Solomon M. and Perkins, Nigel R. and Kidd, Lisa J. and Ahern, Benjamin J.},
date = {2021-02},
journaltitle = {Animals},
volume = {11},
pages = {270},
publisher = {{Multidisciplinary Digital Publishing Institute}},
doi = {10.3390/ani11020270},
url = {https://www.mdpi.com/2076-2615/11/2/270},
issue = {2},
number = {2}
}
```
# Bibliography but in this case the labels from referencing should be inserted manually. So this is not an easy task to cover all cases. Citation in Hope it helps |
@cderv Thanks very much for the long explanation and possible work around. |
@cderv Inspired by your example using pander, I was able to have a work around using kable:
Use the I'm happy to close this issue. I will let you do it if appropriate. Thanks! |
Oh yes I forgot the obvious: you can ask kable() to output markdown also. Thanks for sharing back ! |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
Consider the following minimal working example:
with the following dependencies:
The output of
is
Bookdown failed to convert
[@crawfordRiskFactorsMusculoskeletal2021]
in Table 1.This bug doesn't exist in R Markdown! The output of
is
Session Info
Checklist
When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:
formatted your issue so it is easier for us to read?
included a minimal, self-contained, and reproducible example?
pasted the output from
xfun::session_info('bookdown')
in your issue?upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?
installed and tested your bug with the development version of the bookdown package using
remotes::install_github("rstudio/bookdown")
?The text was updated successfully, but these errors were encountered: