Internal links and URLs not working after embedding fonts in PDF kitted with R markdown

血红的双手。 提交于 2020-06-17 09:14:11

问题


I use extrafont::embed_fonts to embed fonts in a simple R markdown document which works fine.

However, after embedding the fonts contained in the document, any references (internal links, URLs, citations) do not work anymore.

Below an MWE with sample output (with & without embedding) is provided. Many thanks for help!

MWE:

---
title: "Embedding Fonts in PDF"
output: pdf_document
---

```{r echo=FALSE, message=FALSE, warning=FALSE, out.width = '30%'}
library(ggplot2)
library(extrafont)
# font_import()   # run
loadfonts()       # loadfonts
```

### Plot with standard font {#standard}
```{r echo=FALSE, message=FALSE, warning=FALSE, out.width = '30%'}
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +     
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon")
```

### Load fonts and set ggplot theme globally
```{r message=FALSE, warning=FALSE, include=FALSE}
# install.packages("extrafont") # see https://github.com/wch/extrafont/
# library(extrafont)
# font_import()   # run
loadfonts()       # loadfonts

# globally set ggplot2 theme and font ("Lato Light")
theme_set(theme_minimal(base_size=12, base_family="Lato Light"))
```

### Plot with new standard font (= Lato) {#lato}
```{r echo=FALSE, message=FALSE, warning=FALSE, out.width = '30%'}
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +     
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon")
```

### Plot with Impact font {#impact}
```{r echo=FALSE, message=FALSE, warning=FALSE, out.width = '30%'}
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
  theme(text=element_text(size=16, family="Impact"))
```

### Run to embed fonts
```{r eval=FALSE, include=TRUE}
embed_fonts("TestRmd.pdf", outfile="TestRmd_embedded.pdf")
```

### Links test

Links test 1 (internal reference): [Headline standard](#standard)

Links test 2 (URL): [RStudio has become a Public Benefit Corporation](https://blog.rstudio.com/2020/01/29/rstudio-pbc)

Sidenote: embedding of fonts seems necessary for "standards" fonts like impact

MWE: Output with fonts not embedded

MWE: Output with fonts embedded

来源:https://stackoverflow.com/questions/60277473/internal-links-and-urls-not-working-after-embedding-fonts-in-pdf-kitted-with-r-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!