Skip to content

Commit

Permalink
prioritize explicit 'texinputs' in tools::texi2pdf()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
smeyer committed Jan 31, 2025
1 parent eae49e7 commit 6d28c1d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
9 changes: 3 additions & 6 deletions doc/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ NEWS.pdf: NEWS.rds
$(ECHO) "'pdflatex' is needed to make NEWS.pdf but is missing on your system."; \
else \
$(ECHO) "creating doc/NEWS.pdf"; \
$(ECHO) 'options(warn=1);tools:::Rd2pdf_NEWS_in_Rd("NEWS.rds", "NEWS.pdf")' | \
TEXINPUTS="$(top_srcdir)/share/texmf/tex/latex:$$TEXINPUTS" $(R_EXE) || rm $*; \
$(ECHO) 'options(warn=1);tools:::Rd2pdf_NEWS_in_Rd("NEWS.rds", "NEWS.pdf")' | $(R_EXE) || rm $*; \
fi

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

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


Expand Down
6 changes: 6 additions & 0 deletions doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@

\item \code{R CMD build} now supports \option{--compression=zstd}
on platforms with sufficient support for \command{zstd}.

\item \code{tools::texi2pdf(..., texinputs=\var{paths})} now
\emph{pre}pends the specified \var{paths} to \env{TEXINPUTS}.
When building \R (\file{doc/NEWS.pdf} and base vignettes), this
now ensures that its own \file{Rd.sty} takes precedence over
(incompatible) versions in default \dQuote{texmf trees}.
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/library/tools/R/admin.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# File src/library/tools/R/admin.R
# Part of the R package, https://www.R-project.org
#
# Copyright (C) 1995-2024 The R Core Team
# Copyright (C) 1995-2025 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -743,10 +743,12 @@ function(dir, outDir, keep.source = TRUE)
})
## In case of an error, do not clean up: should we point to
## buildDir for possible inspection of results/problems?
## We need to ensure that the src vignettes dir is in (TEX|BIB)INPUTS.
## We need to ensure that the src vignettes dir is in (TEX|BIB)INPUTS
## and this R's texmf is found (system TEXINPUTS could list another R).
if (vignette_is_tex(output)) {
tryCatch({
texi2pdf(file = output, quiet = TRUE, texinputs = vigns$dir)
texi2pdf(file = output, quiet = TRUE,
texinputs = c(vigns$dir, paste0(R.home("share"), "/texmf//")))
output <- find_vignette_product(name, by = "texi2pdf", engine = engine)
}, error = function(e) {
stop(gettextf("compiling TeX file %s failed with message:\n%s",
Expand Down
6 changes: 4 additions & 2 deletions src/library/tools/R/news.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# File src/library/tools/R/news.R
# Part of the R package, https://www.R-project.org
#
# Copyright (C) 1995-2024 The R Core Team
# Copyright (C) 1995-2025 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -376,7 +376,9 @@ function(f, pdf_file)
on.exit(setwd(od))
## avoid broken texi2pdf scripts: this is simple LaTeX
## and emulation suffices
texi2pdf("NEWS.tex", quiet = TRUE, texi2dvi = "emulation")
texi2pdf("NEWS.tex", quiet = TRUE, texi2dvi = "emulation",
## ensure _this_ R's Rd.sty is found first:
texinputs = file.path(R.home("share"), "texmf", "tex", "latex"))
setwd(od); on.exit()
invisible(file.copy(file.path(dirname(f3), "NEWS.pdf"),
pdf_file, overwrite = TRUE))
Expand Down
31 changes: 12 additions & 19 deletions src/library/tools/R/utils.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# File src/library/tools/R/utils.R
# Part of the R package, https://www.R-project.org
#
# Copyright (C) 1995-2024 The R Core Team
# Copyright (C) 1995-2025 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -314,41 +314,34 @@ function(file, pdf = FALSE, clean = FALSE, quiet = TRUE,
} # else the provided one should work
}

envSep <- .Platform$path.sep
texinputs0 <- texinputs
Rtexmf <- file.path(R.home("share"), "texmf")
Rtexinputs <- file.path(Rtexmf, "tex", "latex")
## "" forces use of default paths.
texinputs <- paste(c(texinputs0, Rtexinputs, ""),
collapse = envSep)
paths2env <- function(x) paste(x, collapse = .Platform$path.sep)
## not clear if this is needed, but works
if(.Platform$OS.type == "windows")
texinputs <- gsub("\\", "/", texinputs, fixed = TRUE)
Rbibinputs <- file.path(Rtexmf, "bibtex", "bib")
bibinputs <- paste(c(texinputs0, Rbibinputs, ""),
collapse = envSep)
Rbstinputs <- file.path(Rtexmf, "bibtex", "bst")
bstinputs <- paste(c(texinputs0, Rbstinputs, ""),
collapse = envSep)
Rtexmf <- file.path(R.home("share"), "texmf", fsep = "/")
Rtexinputs <- file.path(Rtexmf, "tex", "latex", fsep = "/")
Rbibinputs <- file.path(Rtexmf, "bibtex", "bib", fsep = "/")
Rbstinputs <- file.path(Rtexmf, "bibtex", "bst", fsep = "/")

otexinputs <- Sys.getenv("TEXINPUTS", unset = NA_character_)
if(is.na(otexinputs)) {
on.exit(Sys.unsetenv("TEXINPUTS"))
otexinputs <- "."
} else on.exit(Sys.setenv(TEXINPUTS = otexinputs))
Sys.setenv(TEXINPUTS = paste(otexinputs, texinputs, sep = envSep))
## "" below represents system paths
Sys.setenv(TEXINPUTS = paths2env(c(texinputs, otexinputs, Rtexinputs, "")))
obibinputs <- Sys.getenv("BIBINPUTS", unset = NA_character_)
if(is.na(obibinputs)) {
on.exit(Sys.unsetenv("BIBINPUTS"), add = TRUE)
obibinputs <- "."
} else on.exit(Sys.setenv(BIBINPUTS = obibinputs, add = TRUE))
Sys.setenv(BIBINPUTS = paste(obibinputs, bibinputs, sep = envSep))
Sys.setenv(BIBINPUTS = paths2env(c(texinputs, obibinputs, Rbibinputs, "")))
obstinputs <- Sys.getenv("BSTINPUTS", unset = NA_character_)
if(is.na(obstinputs)) {
on.exit(Sys.unsetenv("BSTINPUTS"), add = TRUE)
obstinputs <- "."
} else on.exit(Sys.setenv(BSTINPUTS = obstinputs), add = TRUE)
Sys.setenv(BSTINPUTS = paste(obstinputs, bstinputs, sep = envSep))
Sys.setenv(BSTINPUTS = paths2env(c(texinputs, obstinputs, Rbstinputs, "")))

if(index && nzchar(texi2dvi) && .Platform$OS.type != "windows") {
## switch off the use of texindy in texi2dvi >= 1.157
Expand Down Expand Up @@ -454,11 +447,11 @@ function(file, pdf = FALSE, clean = FALSE, quiet = TRUE,
## and set the path to R's style files.
## -I works in MiKTeX >= 2.4, at least
## http://docs.miktex.org/manual/texify.html
## FIXME: is -I still needed? It documents EnvVars since at least 2016.
ver <- system(paste(shQuote(texi2dvi), "--version"), intern = TRUE)
if(length(grep("MiKTeX", ver[1L]))) {
## AFAICS need separate -I for each element of texinputs.
texinputs <- c(texinputs0, Rtexinputs, Rbstinputs)
texinputs <- gsub("\\", "/", texinputs, fixed = TRUE)
texinputs <- c(texinputs, Rtexinputs, Rbstinputs)
paths <- paste ("-I", shQuote(texinputs))
extra <- "--max-iterations=20"
extra <- paste(extra, paste(paths, collapse = " "))
Expand Down
10 changes: 5 additions & 5 deletions src/library/tools/man/texi2dvi.Rd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% File src/library/tools/man/texi2dvi.Rd
% Part of the R package, https://www.R-project.org
% Copyright 1995-2016 R Core Team
% Copyright 1995-2025 R Core Team
% Distributed under GPL 2 or later

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

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

Expand Down

0 comments on commit 6d28c1d

Please sign in to comment.