2

I'm using RStudio 0.98.1056 on Windows 7, and the development version of pander as of today (I think it's 0.3.9).

I'm trying to use the knitr->Markdown->.docx literate-programming workflow to create a table in Word. Some of the cells in the table contain two elements. In each of these cells, I'd like to render the first element in the normal base font, and the second in an italicized font that's just a bit smaller. The italics are easy but I'm having trouble with the font size change. In HTML I think using the <small> tag would do it, but when I put this into my cells, pander sanitizes it out (even when I knit to HTML instead of docx).

I gather that on-the-fly font size changes may not really be in the spirit of Markdown, but I'm trying to match an existing document style as closely as I can. Is what I want actually possible in this workflow?

ErinMcJ
  • 593
  • 6
  • 20

1 Answers1

1

I am sure that pander does not remove the <small> tag. Quick example:

> pander(data.frame(a = 'foo <small>bar</small>'))

----------------------
          a           
----------------------
foo <small>bar</small>
----------------------

But to be on-topic: markdown does not support font sizes, but you can use italics or bold emphasis. E.g:

> df <- iris[1:4, 1:4]
> emphasize.cells(which(df > 1, arr.ind = TRUE))
> pander(df)

---------------------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length   Petal.Width 
-------------- ------------- -------------- -------------
    *5.1*          *3.5*         *1.4*           0.2     

    *4.9*           *3*          *1.4*           0.2     

    *4.7*          *3.2*         *1.3*           0.2     

    *4.6*          *3.1*         *1.5*           0.2     
---------------------------------------------------------

This will render just fine in all document formats (HTML, pdf, docx and so on).

daroczig
  • 28,004
  • 7
  • 90
  • 124
  • Oops. I'm so new to this workflow that it's not always clear to me which stage my problem is in. I guess maybe it's the "knit to [Word/HTML]" stage that's removing/ignoring the tag. – ErinMcJ Sep 16 '14 at 23:04
  • @ErinMcJ use [Pandoc](http://johnmacfarlane.net/pandoc/) (which is used by R Markdown v2) and the `` tag should not be removed. How do you `knit` to HTML? The Word document will not preserve it of course. – daroczig Sep 16 '14 at 23:54
  • 1
    Hm, I think I see my conceptual error. I expected that Pandoc's conversion magic meant that any format that worked in one rendition of the document should work in the others. But that's not right, is it -- only things which would be rendered in the .md-friendly version that pander returns will get knitted into other formats, so brute-force HTML will only show up in HTML. Do I have that right now? (I'm using RStudio, and I knit to all formats with the "Knit" button. I think `knitr` is what's under the hood but I wouldn't swear to it.) – ErinMcJ Sep 17 '14 at 01:13
  • @ErinMcJ That's right, HTML markup inside of a markdown document will only affect the HTML output, LaTeX directives only the pdf output etc. – daroczig Sep 17 '14 at 11:41