Skip to content

Commit 6d28c1d

Browse files
author
smeyer
committed
prioritize explicit 'texinputs' in tools::texi2pdf()
e.g., R's texmf tree when building R (amends r85965) git-svn-id: https://svn.r-project.org/R/trunk@87670 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent eae49e7 commit 6d28c1d

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

doc/Makefile.in

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ NEWS.pdf: NEWS.rds
7373
$(ECHO) "'pdflatex' is needed to make NEWS.pdf but is missing on your system."; \
7474
else \
7575
$(ECHO) "creating doc/NEWS.pdf"; \
76-
$(ECHO) 'options(warn=1);tools:::Rd2pdf_NEWS_in_Rd("NEWS.rds", "NEWS.pdf")' | \
77-
TEXINPUTS="$(top_srcdir)/share/texmf/tex/latex:$$TEXINPUTS" $(R_EXE) || rm $*; \
76+
$(ECHO) 'options(warn=1);tools:::Rd2pdf_NEWS_in_Rd("NEWS.rds", "NEWS.pdf")' | $(R_EXE) || rm $*; \
7877
fi
7978

8079
docs3: NEWS.3.rds NEWS.3.html NEWS.3.pdf
@@ -97,8 +96,7 @@ NEWS.3.pdf: NEWS.3.rds
9796
$(ECHO) "'pdflatex' is needed to make NEWS.3.pdf but is missing on your system."; \
9897
else \
9998
$(ECHO) "creating NEWS.3.pdf"; \
100-
$(ECHO) 'options(warn=1);tools:::Rd2pdf_NEWS_in_Rd("NEWS.3.rds", "NEWS.3.pdf")' | \
101-
TEXINPUTS="$(top_srcdir)/share/texmf/tex/latex:$$TEXINPUTS" $(R_EXE) || rm $*; \
99+
$(ECHO) 'options(warn=1);tools:::Rd2pdf_NEWS_in_Rd("NEWS.3.rds", "NEWS.3.pdf")' | $(R_EXE) || rm $*; \
102100
fi
103101

104102
## NEWS.2.html ships as doc/html/NEWS.2.html in the sources.
@@ -123,8 +121,7 @@ NEWS.2.pdf: NEWS.2.rds
123121
$(ECHO) "'pdflatex' is needed to make NEWS.2.pdf but is missing on your system."; \
124122
else \
125123
$(ECHO) "creating NEWS.2.pdf"; \
126-
$(ECHO) 'options(warn=1);tools:::Rd2pdf_NEWS_in_Rd("NEWS.2.rds", "NEWS.2.pdf")' | \
127-
TEXINPUTS="$(top_srcdir)/share/texmf/tex/latex:$$TEXINPUTS" $(R_EXE) || rm $*; \
124+
$(ECHO) 'options(warn=1);tools:::Rd2pdf_NEWS_in_Rd("NEWS.2.rds", "NEWS.2.pdf")' | $(R_EXE) || rm $*; \
128125
fi
129126

130127

doc/NEWS.Rd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@
416416

417417
\item \code{R CMD build} now supports \option{--compression=zstd}
418418
on platforms with sufficient support for \command{zstd}.
419+
420+
\item \code{tools::texi2pdf(..., texinputs=\var{paths})} now
421+
\emph{pre}pends the specified \var{paths} to \env{TEXINPUTS}.
422+
When building \R (\file{doc/NEWS.pdf} and base vignettes), this
423+
now ensures that its own \file{Rd.sty} takes precedence over
424+
(incompatible) versions in default \dQuote{texmf trees}.
419425
}
420426
}
421427

src/library/tools/R/admin.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/tools/R/admin.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2024 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -743,10 +743,12 @@ function(dir, outDir, keep.source = TRUE)
743743
})
744744
## In case of an error, do not clean up: should we point to
745745
## buildDir for possible inspection of results/problems?
746-
## We need to ensure that the src vignettes dir is in (TEX|BIB)INPUTS.
746+
## We need to ensure that the src vignettes dir is in (TEX|BIB)INPUTS
747+
## and this R's texmf is found (system TEXINPUTS could list another R).
747748
if (vignette_is_tex(output)) {
748749
tryCatch({
749-
texi2pdf(file = output, quiet = TRUE, texinputs = vigns$dir)
750+
texi2pdf(file = output, quiet = TRUE,
751+
texinputs = c(vigns$dir, paste0(R.home("share"), "/texmf//")))
750752
output <- find_vignette_product(name, by = "texi2pdf", engine = engine)
751753
}, error = function(e) {
752754
stop(gettextf("compiling TeX file %s failed with message:\n%s",

src/library/tools/R/news.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/tools/R/news.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2024 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -376,7 +376,9 @@ function(f, pdf_file)
376376
on.exit(setwd(od))
377377
## avoid broken texi2pdf scripts: this is simple LaTeX
378378
## and emulation suffices
379-
texi2pdf("NEWS.tex", quiet = TRUE, texi2dvi = "emulation")
379+
texi2pdf("NEWS.tex", quiet = TRUE, texi2dvi = "emulation",
380+
## ensure _this_ R's Rd.sty is found first:
381+
texinputs = file.path(R.home("share"), "texmf", "tex", "latex"))
380382
setwd(od); on.exit()
381383
invisible(file.copy(file.path(dirname(f3), "NEWS.pdf"),
382384
pdf_file, overwrite = TRUE))

src/library/tools/R/utils.R

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/tools/R/utils.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2024 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -314,41 +314,34 @@ function(file, pdf = FALSE, clean = FALSE, quiet = TRUE,
314314
} # else the provided one should work
315315
}
316316

317-
envSep <- .Platform$path.sep
318-
texinputs0 <- texinputs
319-
Rtexmf <- file.path(R.home("share"), "texmf")
320-
Rtexinputs <- file.path(Rtexmf, "tex", "latex")
321-
## "" forces use of default paths.
322-
texinputs <- paste(c(texinputs0, Rtexinputs, ""),
323-
collapse = envSep)
317+
paths2env <- function(x) paste(x, collapse = .Platform$path.sep)
324318
## not clear if this is needed, but works
325319
if(.Platform$OS.type == "windows")
326320
texinputs <- gsub("\\", "/", texinputs, fixed = TRUE)
327-
Rbibinputs <- file.path(Rtexmf, "bibtex", "bib")
328-
bibinputs <- paste(c(texinputs0, Rbibinputs, ""),
329-
collapse = envSep)
330-
Rbstinputs <- file.path(Rtexmf, "bibtex", "bst")
331-
bstinputs <- paste(c(texinputs0, Rbstinputs, ""),
332-
collapse = envSep)
321+
Rtexmf <- file.path(R.home("share"), "texmf", fsep = "/")
322+
Rtexinputs <- file.path(Rtexmf, "tex", "latex", fsep = "/")
323+
Rbibinputs <- file.path(Rtexmf, "bibtex", "bib", fsep = "/")
324+
Rbstinputs <- file.path(Rtexmf, "bibtex", "bst", fsep = "/")
333325

334326
otexinputs <- Sys.getenv("TEXINPUTS", unset = NA_character_)
335327
if(is.na(otexinputs)) {
336328
on.exit(Sys.unsetenv("TEXINPUTS"))
337329
otexinputs <- "."
338330
} else on.exit(Sys.setenv(TEXINPUTS = otexinputs))
339-
Sys.setenv(TEXINPUTS = paste(otexinputs, texinputs, sep = envSep))
331+
## "" below represents system paths
332+
Sys.setenv(TEXINPUTS = paths2env(c(texinputs, otexinputs, Rtexinputs, "")))
340333
obibinputs <- Sys.getenv("BIBINPUTS", unset = NA_character_)
341334
if(is.na(obibinputs)) {
342335
on.exit(Sys.unsetenv("BIBINPUTS"), add = TRUE)
343336
obibinputs <- "."
344337
} else on.exit(Sys.setenv(BIBINPUTS = obibinputs, add = TRUE))
345-
Sys.setenv(BIBINPUTS = paste(obibinputs, bibinputs, sep = envSep))
338+
Sys.setenv(BIBINPUTS = paths2env(c(texinputs, obibinputs, Rbibinputs, "")))
346339
obstinputs <- Sys.getenv("BSTINPUTS", unset = NA_character_)
347340
if(is.na(obstinputs)) {
348341
on.exit(Sys.unsetenv("BSTINPUTS"), add = TRUE)
349342
obstinputs <- "."
350343
} else on.exit(Sys.setenv(BSTINPUTS = obstinputs), add = TRUE)
351-
Sys.setenv(BSTINPUTS = paste(obstinputs, bstinputs, sep = envSep))
344+
Sys.setenv(BSTINPUTS = paths2env(c(texinputs, obstinputs, Rbstinputs, "")))
352345

353346
if(index && nzchar(texi2dvi) && .Platform$OS.type != "windows") {
354347
## switch off the use of texindy in texi2dvi >= 1.157
@@ -454,11 +447,11 @@ function(file, pdf = FALSE, clean = FALSE, quiet = TRUE,
454447
## and set the path to R's style files.
455448
## -I works in MiKTeX >= 2.4, at least
456449
## http://docs.miktex.org/manual/texify.html
450+
## FIXME: is -I still needed? It documents EnvVars since at least 2016.
457451
ver <- system(paste(shQuote(texi2dvi), "--version"), intern = TRUE)
458452
if(length(grep("MiKTeX", ver[1L]))) {
459453
## AFAICS need separate -I for each element of texinputs.
460-
texinputs <- c(texinputs0, Rtexinputs, Rbstinputs)
461-
texinputs <- gsub("\\", "/", texinputs, fixed = TRUE)
454+
texinputs <- c(texinputs, Rtexinputs, Rbstinputs)
462455
paths <- paste ("-I", shQuote(texinputs))
463456
extra <- "--max-iterations=20"
464457
extra <- paste(extra, paste(paths, collapse = " "))

src/library/tools/man/texi2dvi.Rd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% File src/library/tools/man/texi2dvi.Rd
22
% Part of the R package, https://www.R-project.org
3-
% Copyright 1995-2016 R Core Team
3+
% Copyright 1995-2025 R Core Team
44
% Distributed under GPL 2 or later
55

66
\name{texi2dvi}
@@ -34,23 +34,23 @@ texi2pdf(file, clean = FALSE, quiet = TRUE,
3434
otherwise emulate the script with \code{system2} calls (which
3535
can be selected by the value \code{"emulation"}). See also
3636
\sQuote{Details}.}
37-
\item{texinputs}{\code{NULL} or a character vector of paths to add to
37+
\item{texinputs}{\code{NULL} or a character vector of paths to prepend to
3838
the LaTeX and BibTeX input search paths.}
3939
\item{index}{logical: should indices be prepared?}
4040
}
4141
\details{
4242
\code{texi2pdf} is a wrapper for the common case of
4343
\code{texi2dvi(pdf = TRUE)}.
4444

45-
Despite the name, this is used in \R to compile LaTeX files,
45+
Despite the name, this is used in \R to compile \LaTeX files,
4646
specifically those generated from vignettes and by the
4747
\code{\link{Rd2pdf}} script (used for package reference manuals). It
4848
ensures that the \file{\var{\link{R_HOME}}/share/texmf} directory is
4949
in the \env{TEXINPUTS} path, so \R style files such as \file{Sweave.sty}
5050
and \file{Rd.sty} will be found. The TeX search path used is first the
51+
elements of argument \code{texinputs}, then the
5152
existing \env{TEXINPUTS} setting (or the current directory if unset),
52-
then elements of argument \code{texinputs}, then
53-
\file{\var{R_HOME}/share/texmf} and finally the default path.
53+
then \file{\var{R_HOME}/share/texmf} and finally the system paths.
5454
Analogous changes are made to \env{BIBINPUTS} and \env{BSTINPUTS}
5555
settings.
5656

0 commit comments

Comments
 (0)