Skip to content

Commit cb1e455

Browse files
Fix \@ref() referencing for PDF output
1 parent a826d65 commit cb1e455

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

R/distill_article.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,24 @@ rjournal_web_article <- function(toc = FALSE,
327327
rjournal_pdf_article <- function(..., self_contained = FALSE) {
328328
fmt <- rticles::rjournal_article(...)
329329
post_process <- fmt$post_processor
330-
fmt$post_processor <- function(...) {
330+
fmt$post_processor <- function(metadata, utf8_input, output_file, clean, verbose) {
331+
332+
# Replace \@ref(***) with \ref{***}
333+
file <- xfun::with_ext(output_file, '.tex')
334+
lines <- xfun::read_utf8(file)
335+
## From bookdown/R/latex.R
336+
lines = gsub(
337+
'(?<!\\\\textbackslash{})@ref\\(([-/:[:alnum:]]+)\\)', '\\\\ref{\\1}', lines,
338+
perl = TRUE
339+
)
340+
xfun::write_utf8(lines, file)
341+
331342
sty_origin <- list.files(system.file("tex", package = "rjdistill"),
332343
full.names = TRUE)
333344
sty_dest <- file.path(".", basename(sty_origin))
334345
copied <- file.copy(sty_origin, sty_dest)
335346
on.exit(unlink(sty_dest[copied]))
336-
post_process(...)
347+
post_process(metadata, utf8_input, output_file, clean, verbose)
337348
}
338349
# output_format(
339350
# knitr = knitr_options(),

0 commit comments

Comments
 (0)