Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal links in PDF file inside a flextable no longer work #632

Open
GauthierMagnin opened this issue May 10, 2024 · 1 comment
Open
Labels

Comments

@GauthierMagnin
Copy link

Hello,

I'm not really sure if the issue is about flextable, knitr, tinytex or any other related packages, but here is the problem: internal links in PDF file inside flextables no longer work.
Recently, I had to update tinytex because of a new version of Tex Live. Since then, it seems that PDF internal links does not work the same way as before. Internal links outside of flextables still work as expected.

Here is a reproducible example of an Rmd document:

---
title: "Internal links in PDF file inside a flextable"
date: "2024-05-10"
output:
  pdf_document:
    latex_engine: xelatex
linkcolor: red
urlcolor: blue
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

library(flextable)
library(magrittr)
```

The following link works: [appendix A](#appendix-a).

Internal links inside flextable do not (but external links still work):

```{r}
dat <- data.frame(col1 = c("Internal link", "External link"),
                  col2 = c("#appendix-a", "https://github.com/davidgohel/flextable/issues"))

flextable(dat) %>%
  set_table_properties(layout = "autofit") %>%
  compose(i = c(1, 2), j = 2,
          value = as_paragraph(
            "See ",
            hyperlink_text(x = c("appendix A", "flextable issues"), url = col2),
            "."
          ))
```

\newpage

## Appendix A {#appendix-a}

I get the same result using the "Knit" button in RStudio and using devtools::build_rmd. I get the same issue regardless of the software used to open the resulting PDF file.

When I open the PDF file in a browser to inspect it, I see that the href value is "#appendix-a" for the link inside the table, but is "#section*.1" for the one outside the table. In PDF files created before the recent update, both were "#appendix-a".
My guess is that flextable have to consider a change about this update to keep working. But maybe I'm wrong, it is the other way and I should duplicate this issue elsewhere.

Here is the result of sessionInfo():

R version 4.0.5 (2021-03-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252   
[3] LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] magrittr_2.0.1  flextable_0.9.6

loaded via a namespace (and not attached):
 [1] zip_2.1.1               Rcpp_1.0.9              fontBitstreamVera_0.1.1
 [4] compiler_4.0.5          later_1.2.0             gfonts_0.2.0           
 [7] tools_4.0.5             uuid_1.0-3              digest_0.6.27          
[10] jsonlite_1.7.2          evaluate_0.23           lifecycle_1.0.4        
[13] rlang_1.1.3             shiny_1.6.0             cli_3.6.2              
[16] rstudioapi_0.13         crul_1.4.0              curl_4.3.1             
[19] yaml_2.2.1              fontLiberation_0.1.0    xfun_0.43              
[22] fastmap_1.1.1           xml2_1.3.2              officer_0.6.5          
[25] knitr_1.46              askpass_1.1             gdtools_0.3.7          
[28] systemfonts_1.0.3       grid_4.0.5              glue_1.4.2             
[31] httpcode_0.3.0          data.table_1.14.2       R6_2.5.0               
[34] textshaping_0.3.7       rmarkdown_2.22          fontquiver_0.2.1       
[37] promises_1.2.0.1        htmltools_0.5.8.1       ellipsis_0.3.2         
[40] mime_0.10               xtable_1.8-4            httpuv_1.6.1           
[43] ragg_1.2.7              openssl_2.1.2           crayon_1.4.1  
@davidgohel
Copy link
Owner

Hello

I can reproduce but have no diagnostic for now. I think I did not change anything related to PDF recently. I'll have a look soon

@davidgohel davidgohel added the bug label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants