I am altering the font of a figure caption in my Rmarkdown and am using bookdown
and pandoc to do so. My question is closely related to: How to change the figure caption format in bookdown?. Further, I was able to get correct figure numbering and was able to alter the format of the "Figure 1" portion of the caption. However, I cannot figure out how to remove the colon in the output (i.e., "Figure 1:. ").
Minimal Example
Pandoc Function (taken from here)
function Image (img)
img.caption[1] = pandoc.Strong(img.caption[1])
img.caption[3] = pandoc.Strong(img.caption[3])
img.caption[4] = pandoc.Strong(". ")
return img
end
To use function Image
in the Rmarkdown, save the file as "figure_caption_patch.lua", which will be called in pandoc_args
in the YAML metadata.
Rmarkdown
---
title: Hello World
author: "Somebody"
output:
bookdown::word_document2:
fig_caption: yes
number_sections: FALSE
pandoc_args: ["--lua-filter", "figure_caption_patch.lua"]
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Test
Some text (Figure \@ref(fig:Xray)). Some text followed by a figure:
```{r Xray, fig.cap="Single-crystal X-ray structure of some text", echo=FALSE}
plot(cars)
```
Output
Figure 1:. This is a caption.
Desired Output
Figure 1. This is a caption.
In the pandoc function, I tried to further subset the string of img.caption[3]
, but it did not work. I tried the following:
img.caption[3] = pandoc.Strong(string.sub(img.caption[3], 1, 1))
But this of course did not work. I know that if I was using R, then I could do something like:
a = c("words", "again")
substring(a, 1, 1)[1]
#output
[1] "w"
But unsure, how to do this with pandoc.