From 836c2a24ed118f99a546e8262faee3cf5a1aae4c Mon Sep 17 00:00:00 2001 From: smeyer Date: Tue, 28 Jan 2025 13:39:29 +0000 Subject: [PATCH] tweak Rd2pdf's graphicspath setup, avoiding redundant rewrites git-svn-id: https://svn.r-project.org/R/trunk@87660 00db46b3-68df-0310-9c12-caf00c1e9a41 --- src/library/tools/R/Rd2pdf.R | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/library/tools/R/Rd2pdf.R b/src/library/tools/R/Rd2pdf.R index abfde2be9b..56ab8c85eb 100644 --- a/src/library/tools/R/Rd2pdf.R +++ b/src/library/tools/R/Rd2pdf.R @@ -232,6 +232,7 @@ outfile <- paste0(basename(pkgdir), "-pkg.tex") hasFigures <- FALSE + graphicspath <- NULL ## First check for a latex dir (from R CMD INSTALL --latex). ## Second guess is this is a >= 2.10.0 package with stored .rds files. @@ -262,15 +263,10 @@ outputEncoding = outputEncoding, defines = NULL, # already processed writeEncoding = FALSE) - if (attr(res, "hasFigures")) { - lines <- readLines(outfilename) - graphicspath <- file.path(pkgdir, "help", "figures") - writeLines(c(.file_path_to_LaTeX_graphicspath(graphicspath), - lines), - outfilename) - hasFigures <- TRUE - } + hasFigures <- hasFigures || attr(res, "hasFigures") } + if (hasFigures) + graphicspath <- file.path(pkgdir, "help", "figures") if (!silent) message(domain = NA) } else { ## As from R 2.15.3, give priority to a man dir. @@ -342,15 +338,10 @@ outputEncoding = outputEncoding, writeEncoding = FALSE, macros = macros) - if (attr(res, "hasFigures")) { - lines <- readLines(outfilename) - graphicspath <- file.path(mandir, "figures") - writeLines(c(.file_path_to_LaTeX_graphicspath(graphicspath), - lines), - outfilename) - hasFigures <- TRUE - } + hasFigures <- hasFigures || attr(res, "hasFigures") } + if (hasFigures) + graphicspath <- file.path(mandir, "figures") if (!silent) message(domain = NA) } } @@ -371,6 +362,10 @@ cat("\n\\chapter{The \\texttt{", basename(pkgdir), "} package}\n", sep = "", file = outcon) + if (!is.null(graphicspath)) + cat(.file_path_to_LaTeX_graphicspath(graphicspath), "\n", + sep = "", file = outcon) + ## Extract (LaTeX-escaped, ASCII) \name for sorting. topics <- rep("", length(files)) names(topics) <- files