rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.88k stars 975 forks source link

Tex intermediate files are written in input directory even if output file is in another dir, or intermediates file is set #1975

Open cderv opened 3 years ago

cderv commented 3 years ago

This is more like a note for future us to question the current behavior.

Currently, it seems that the aux files are written to the working directory (from which latexmk is run) and not in the same directory as the input tex file.

This was notice on a server with special access rights by a user on community, and I find it is not obvious. I would have expect to have the files produce by latex conversion to the same dir as tex input or pdf output. Or at least when used with rmarkdown in the intermediate_dir.

I open this issue in rmarkdown not tinytex because the behavior was found while using rmarkdown. I can reopen in tinytex if this is more scoped to there. From tinytex point of view: Auxiliary files are written in current working dir, not in the input directory unless tinytex.output_dir is set with engine_args containing --output-directory=output_dir.

Example

dir.create(tmp_dir <- tempfile())
owd <- setwd(tmp_dir)
xfun::write_utf8(c(
  "---",
  "title: test",
  "---",
  "",
  "# A header",
  ""
), "test.Rmd")
dir.create("temp")
dir.create("out")
options(tinytex.clean = FALSE)
rmarkdown::render("test.Rmd", "pdf_document", 
                  output_options = list(keep_tex = TRUE),
                  output_file = "out/test.pdf",
                  intermediates_dir = "temp",
                  quiet = TRUE)
fs::dir_tree()
#> .
#> +-- out
#> |   +-- test.pdf
#> |   \-- test.tex
#> +-- temp
#> +-- test.aux
#> +-- test.log
#> +-- test.out
#> \-- test.Rmd
setwd(owd)
unlink(tmp_dir, recursive = TRUE)

Created on 2020-12-09 by the reprex package (v0.3.0.9001)

cderv commented 3 years ago

Closing this one will close #1615

stiberger commented 3 years ago

Came across this issue as well. From Shiny I am trying to render markdowns outside application folders, to avoid giving Shiny write permissions to any folders within application. Would be nice if rendering could work, without render user having write access to Rmd folder.

cderv commented 3 years ago

@stiberger this is also for PDF document, right ?

squirrellina commented 2 years ago

Is there an update to this issue? I've also come across it in the context of rendering Rmd in a directory with read-only access. It would be nice to have an argument specifying the folder where .log and related documents will be processed.

cderv commented 2 years ago

No update yet to change the behavior - it still open. When this will be dealt with, we will update here.

Current workaround is to copy Rmd file and resources in a place with write access (like Rmd templates in package installation folder are copied to user's project). I believe rmarkdown assumes in several places that working directory is writable and this issue may not be the only limitation. Do not hesitate to add a 👍 to the main post above to move this up among the topic to tackle next. thanks !