2

I am using bookdown to generate html and pdf at the same time. I would like to use dynamic tables (DT) in the html version, but a normal table in the pdf file. Is there a way to do this in markdown without having to have to separate files as input and using the yml file. Something like

if (output = html) {
    DT...
}
if (output = "pdf"){
    xlatex ...
}

THanks Renger

arnyeinstein
  • 669
  • 1
  • 5
  • 14
  • It looks like you can use the same approach described in http://stackoverflow.com/questions/35144130/in-knitr-how-can-i-test-for-if-the-output-will-be-pdf-or-word/35149103. I had marked this as a duplicate, then retracted it because I wasn't sure if the `bookdown` mechanism was the same. But now that I've looked into it, I believe it is. – Benjamin Jan 19 '17 at 15:37

1 Answers1

4

Edited thanks to Yihui's comment:

if( knitr:::is_latex_output() ) {
    xlatex ...
} else {
    DT...
}
Chris Conlan
  • 2,774
  • 1
  • 19
  • 23
  • 2
    You can use `knitr:::is_latex_output()`. – Yihui Xie Jan 19 '17 at 19:42
  • [Since knitr 1.18](https://github.com/yihui/knitr/blob/master/NEWS.md#changes-in-knitr-version-118), you can use `knitr::is_latex_output()`, with two colons instead of three. – Frank Feb 07 '19 at 03:33