问题
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