manual font control when kniting rmarkdown to MS Word

When kniting to MS Word, I sometimes need to control fonts by making some bits bigger or smaller. My approach has been to use the chunk_styled_text from the worded package to give me more control. So I'll put something like this in my document:

Here I have a sentence with a r worded::chunk_styled_text("freaking big bit", size=24) right in the middle.

Which scratches my itch:

Are there other ways of doing this with Word and rmarkdown? Are there any ways that are output format agnostic?

1 Like

You mean one markdown syntax that would do the job for MS word, html output and pdf output ?

For MS word, there is the pandoc feature to apply custom style to some block of text. This custom style refer to your docx template. So you could have a BigFont style in your reference doc and use it in your markdown text.

Here an example, with a template where I set up the text style BigFont to size 24

title: "R Notebook"
    reference_docx: reference_doc.docx

Here I have a sentence with a r [freaking big bit]{custom-style="BigFont"} right in the middle.

This will output

This is only working for word output as custom-styles is only a word pandoc feature.
However the bracketed spans syntax is also working for other format (ex for html : [This is *some text*]{.class key="val"})


ok, I had not realized how the bracketed syntax works. That's helpful. Thank you!

1 Like

It is pretty powerful !

If you use these custom-styles in your rmarkdown without a reference docx, and generate the word output, it will create all the style in the document. You can then manually update the style in word. Save the document as reference_doc.docx, and use it as template for following generation.
No need to create all those custom style in the word document manually naming them.

Also, the is the fenced_divs syntax to apply custom-styles on paragraph.

::: {custom-style="Poetry"}
| A Bird came down the Walk---
| He did not know I saw---

The same as my example, but this time it will be a paragraph style.

1 Like

so this raises a meta question. How in the world did you figure this out? I'm no expert, but I have read a considerable amount of junk and never seen the syntax above with ::: before.

1 Like

The pandoc MANUAL :exclamation::exclamation: :star_struck:

When you want to do some pretty advanced stuff this a must read.
It is something @yihui blogged about several times.

rmarkdown is, in some way, a wrapper around pandoc, so you can get all the power of pandoc, but one need to learn about this power to be able to use it. :blush: I can say that it is a really useful reading! And I discovered all this when I applied to myself the expression RTFM :stuck_out_tongue_closed_eyes:

It is like reading Writing R extension when you want to develop :package:. At some point it is a must read!

1 Like

Ha! Trust me I have no aversion to reading. I just didn't realize what was needing to be read. This is an important learner point: I've authored a book using bookdown and done considerable work with RMarkdown. Until you told me that the ::: syntax was actually a Pandoc construct, I had no idea it was.

I can only imagine how perplexing all this is to new learners who literally can't figure out what piece of software they are controlling. They think they are using, maybe RStudio, no wait, it's RMarkdown, well maybe knitr ... only to discover they are actually using Pandoc.

I have no idea what the solution is, but this ambiguity of what software/library we are coding against is a real conceptual challenge to new learners. It's big enough that I suspect some give up in a fit of rage before figuring out what to Google.

Yes I agree. But I find this is also a challenge with lot of helps in the rstat community ! thanks to tools like blogdown, pkgdown, bookdown, that helps creating lots of resources to explain all this. Tools that you could use easily without advanced feature to create all this :slight_smile:

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.