rocker-org / rocker-versioned

Run current & prior versions of R using docker
https://hub.docker.com/r/rocker/r-ver
GNU General Public License v2.0
297 stars 169 forks source link

Can't knit to PDF if template requires new latex packages #104

Closed raubreywhite closed 6 years ago

raubreywhite commented 6 years ago

On a similar note to: https://github.com/rocker-org/rocker-versioned/issues/101

The issue is, I open up a new rmarkdown file (inside RStudio Server) and give it the YAML header:

---
title: "Untitled"
header-includes:
   - \usepackage{bbm}
output: pdf_document
---

I then click on the "Knit to PDF" button. The following happens:

processing file: test.Rmd
  |.........                                                        |  14%
  ordinary text without R code

  |...................                                              |  29%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |............................                                     |  43%
  ordinary text without R code

  |.....................................                            |  57%
label: cars
  |..............................................                   |  71%
  ordinary text without R code

  |........................................................         |  86%
label: pressure (with options) 
List of 1
 $ echo: logi FALSE

  |.................................................................| 100%
  ordinary text without R code

/usr/lib/rstudio-server/bin/pandoc/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template /usr/local/lib/R/site-library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' --variable 'compact-title:yes' 
output file: test.knit.md

tlmgr search --file --global '/bbm.sty'
Trying to automatically install missing LaTeX packages...
tlmgr install bbm-macros
tlmgr: package repository http://mirror.hmc.edu/ctan/systems/texlive/tlnet (verified)
[1/1, ??:??/??:??] install: bbm-macros [2k]
open(>/opt/TinyTeX/tlpkg/texlive.tlpdb) failed: Permission denied at /opt/TinyTeX/tlpkg/TeXLive/TLUtils.pm line 1154.
tlmgr update --self
tlmgr: package repository http://mirror.hmc.edu/ctan/systems/texlive/tlnet (verified)
tlmgr: no self-updates for tlmgr available.
fmtutil: fmtutil is using the following fmtutil.cnf files (in precedence order):
fmtutil:   /opt/TinyTeX/texmf-dist/web2c/fmtutil.cnf
fmtutil: fmtutil is using the following fmtutil.cnf file for writing changes:
fmtutil:   /opt/TinyTeX/texmf-config/web2c/fmtutil.cnf
fmtutil [INFO]: writing formats under /opt/TinyTeX/texmf-var/web2c
fmtutil [INFO]: --- remaking pdftex with pdftex
fmtutil: running `pdftex -ini   -jobname=pdftex -progname=pdftex -translate-file=cp227.tcx *pdfetex.ini' ...
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (INITEX)
 restricted \write18 enabled.
 (/opt/TinyTeX/texmf-dist/web2c/cp227.tcx)
entering extended mode
(/opt/TinyTeX/texmf-dist/tex/plain/config/pdfetex.ini
(/opt/TinyTeX/texmf-dist/tex/generic/tex-ini-files/pdftexconfig.tex)
(/opt/TinyTeX/texmf-dist/tex/plain/etex/etex.src
(/opt/TinyTeX/texmf-dist/tex/plain/base/plain.tex
Preloading the plain format: codes, registers, parameters, fonts, more fonts,
macros, math definitions, output routines, hyphenation
(/opt/TinyTeX/texmf-dist/tex/generic/hyphen/hyphen.tex
[skipping from \patterns to end-of-file...]))
(/opt/TinyTeX/texmf-dist/tex/plain/etex/etexdefs.lib
Skipping module "grouptypes"; Loading module "interactionmodes";
Skipping module "nodetypes"; Skipping module "iftypes";)
(/opt/TinyTeX/texmf-var/tex/generic/config/language.def
(/opt/TinyTeX/texmf-dist/tex/generic/hyphen/hyphen.tex))
Augmenting the Plain TeX definitions: \tracingall;
Adding new e-TeX definitions: \eTeX, \loggingall, \tracingnone,
register allocation; extended register allocation; 
Recycling: \addlanguage, \@nswer (not defined), \@sk, \b@dresponsetrue,
\b@dresponsefalse, \ch@ckforyn, \mayber@cycle, \et@xabort, \et@xbuf,
\et@xfmtsrc, \et@xfilehdr, \et@xinf, \et@xpatterns, \l@ngdefnfile, \n@xt,
\p@rse (not defined), \pr@mpt (not defined), \pr@mptloop (not defined),
\forcer@cycle, \usef@llback, \usef@llbacktrue, \usef@llbackfalse, 
Retaining: \et@xerr, \et@xinput, \et@xlibhdr, \et@xmsg, \et@xtoks, \et@xwarn,
\et@xl@@d, \et@xl@ad, \et@xload, \et@xlang, \et@xhash, \eTeX, \etexhdrchk,
\etexstatus, \module, \uselanguage, \r@tain, \r@cycle,)
(/opt/TinyTeX/texmf-dist/tex/plain/config/pdftexmagfix.tex) )
Beginning to dump on file pdftex.fmt
 (preloaded format=pdftex 2018.10.11)
2900 strings of total length 43032
7960 memory locations dumped; current usage is 203&7321
1263 multiletter control sequences
\font\nullfont=nullfont
\font\tenrm=cmr10
\font\preloaded=cmr9
\font\preloaded=cmr8
\font\sevenrm=cmr7
\font\preloaded=cmr6
\font\fiverm=cmr5
\font\teni=cmmi10
\font\preloaded=cmmi9
\font\preloaded=cmmi8
\font\seveni=cmmi7
\font\preloaded=cmmi6
\font\fivei=cmmi5
\font\tensy=cmsy10
\font\preloaded=cmsy9
\font\preloaded=cmsy8
\font\sevensy=cmsy7
\font\preloaded=cmsy6
\font\fivesy=cmsy5
\font\tenex=cmex10
\font\preloaded=cmss10
\font\preloaded=cmssq8
\font\preloaded=cmssi10
\font\preloaded=cmssqi8
\font\tenbf=cmbx10
\font\preloaded=cmbx9
\font\preloaded=cmbx8
\font\sevenbf=cmbx7
\font\preloaded=cmbx6
\font\fivebf=cmbx5
\font\tentt=cmtt10
\font\preloaded=cmtt9
\font\preloaded=cmtt8
\font\preloaded=cmsltt10
\font\tensl=cmsl10
\font\preloaded=cmsl9
\font\preloaded=cmsl8
\font\tenit=cmti10
\font\preloaded=cmti9
\font\preloaded=cmti8
\font\preloaded=cmti7
\font\preloaded=cmu10
\font\preloaded=cmmib10
\font\preloaded=cmbsy10
\font\preloaded=cmcsc10
\font\preloaded=cmssbx10
\font\preloaded=cmdunh10
\font\preloaded=cmr7 at 14.51799pt
\font\preloaded=cmtt10 at 14.4pt
\font\preloaded=cmssbx10 at 14.4pt
\font\preloaded=manfnt
14787 words of font info for 50 preloaded fonts
14 hyphenation exceptions
Hyphenation trie of length 6075 has 181 ops out of 35111
  181 for language 0
0 words of pdfTeX memory
0 indirect objects
No pages of output.
Transcript written on pdftex.log.
fmtutil [INFO]: /opt/TinyTeX/texmf-var/web2c/pdftex/pdftex.fmt installed.
TeX::LSR: ls-R file not writable, skipping: /opt/TinyTeX/texmf-var/ls-R
Cannot write ls-R in /opt/TinyTeX/texmf-var. at /opt/TinyTeX/texmf-dist/scripts/texlive/mktexlsr.pl line 583.
tlmgr install bbm-macros
tlmgr: package repository http://mirror.hmc.edu/ctan/systems/texlive/tlnet (verified)
[1/1, ??:??/??:??] install: bbm-macros [2k]
open(>/opt/TinyTeX/tlpkg/texlive.tlpdb) failed: Permission denied at /opt/TinyTeX/tlpkg/TeXLive/TLUtils.pm line 1154.
tlmgr path add
! LaTeX Error: File `bbm.sty' not found.

! Emergency stop.
<read *> 

Error: Failed to compile test.tex. See test.log for more info.
Execution halted

So basically I can't run any rmarkdown documents where the template requires new latex packages, as they don't want to be installed...

cboettig commented 6 years ago

@raubreywhite thanks for the bug report, looks like I've marfed the permissions in /opt/TinyTeX somehow. just a sec

cboettig commented 6 years ago

@yihui tinytex appears not to be doing what I expect when I have tried to install it at system level.

In rocker, we use /opt/TinyTeX as the tinytex_root() directory, which has permissions root:staff; i.e. owned by the staff group, just like $R_HOME, an the user is added to staff. However, when I run @raubreywhite 's example (or just run tinytex::tlmgr_install("bbm")( I don't get quite the same error, I get

...
tlmgr install bbm
tlmgr: package repository http://mirrors.concertpass.com/tex-archive/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr install: package already present: bbm
tlmgr path add
add of symlinks had 1 error(s), see messages above.
mkdir(/root/bin/) failed: Permission denied
tlmgr: An error has occurred. See above messages. Exiting.

Not sure why it should be trying to mess with /root/bin! Could this be a bug in tinytex assumptions (i.e. ignoring group permission settings and getting the wrong user?)

@raubreywhite not sure why you don't see the same error I do...

Relevant config in rocker is:

https://github.com/rocker-org/rocker-versioned/blob/2ed00a8db5dc830ef1f080d6d7239c4454badb79/verse/Dockerfile#L40-L48

raubreywhite commented 6 years ago

Hi! When I made my own LaTeX template and tried to rmarkdown my LaTeX template directly (which required installation of new LaTeX packages), then I got the same error that you have there. So you're definitely circling around the same issue, but it is weird that it's not the same...

cboettig commented 6 years ago

Not that it is a good solution, but what happens if you just do tinytex_install() in R first?

raubreywhite commented 6 years ago

Ok, so firstly I didn't want to do a direct install to ~ because I share that volume with my local computer (so that I can save all my preferences etc) when I'm developing code. But then once I am done, I need to ship it off to the testing and production machines which are completely autonomous (so I can't manually do the tinytex install on them).

So I first tried installing to a random directory (not forcing it):

> tinytex::install_tinytex(dir="/x/")
tlmgr revision 48522 (2018-08-31 06:03:37 +0200)
tlmgr using installation: /opt/TinyTeX
TeX Live (http://tug.org/texlive) version 2018
Error: Detected an existing tlmgr at /opt/TinyTeX/bin/x86_64-linux//tlmgr. It seems TeX Live has been installed (check tinytex:::texlive_root()). You have to uninstall it, or use install_tinytex(force = TRUE) if you are sure TinyTeX can override it (e.g., you are a PATH expert or installed TinyTeX previously).

Then I tried installing to a random directory (forcing it):

> tinytex::install_tinytex(dir="/x/")
[55/55, 03:59/03:59] install: zapfding [46k]
running mktexlsr ...
done running mktexlsr.
running updmap-sys ...
done running updmap-sys.
regenerating fmtutil.cnf in /home/rstudio/.TinyTeX/texmf-dist
running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine tex ...
done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine tex.
running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt mf ...
done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt mf.
tlmgr: package log updated: /home/rstudio/.TinyTeX/texmf-var/web2c/tlmgr.log
Error in file.copy(list.files(from, full.names = TRUE), to, recursive = TRUE) : 
  more 'from' files than 'to' files
You may have to restart your system after installing TinyTeX to make sure ~/bin appears in your PATH variable (https://github.com/yihui/tinytex/issues/16).

Then I tried installing to my home directory (forcing it):

> tinytex::install_tinytex(force=T)

This actually installed. But then when I tried to knit:

processing file: test.Rmd
  |............................                                     |  43%
  ordinary text without R code

  |.....................................                            |  57%
label: cars
  |..............................................                   |  71%
  ordinary text without R code

  |........................................................         |  86%
label: pressure (with options) 
List of 1
 $ echo: logi FALSE

  |.................................................................| 100%
  ordinary text without R code

/usr/lib/rstudio-server/bin/pandoc/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template /usr/local/lib/R/site-library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' --variable 'compact-title:yes' 
output file: test.knit.md

tlmgr search --file --global '/bbm.sty'
Trying to automatically install missing LaTeX packages...
tlmgr install bbm-macros
tlmgr: package repository http://mirror.hmc.edu/ctan/systems/texlive/tlnet (verified)
[1/1, ??:??/??:??] install: bbm-macros [2k]
open(>/opt/TinyTeX/tlpkg/texlive.tlpdb) failed: Permission denied at /opt/TinyTeX/tlpkg/TeXLive/TLUtils.pm line 1154.
tlmgr update --self
tlmgr: package repository http://mirror.hmc.edu/ctan/systems/texlive/tlnet (verified)
tlmgr: no self-updates for tlmgr available.
fmtutil: fmtutil is using the following fmtutil.cnf files (in precedence order):
fmtutil:   /opt/TinyTeX/texmf-dist/web2c/fmtutil.cnf
fmtutil: fmtutil is using the following fmtutil.cnf file for writing changes:
fmtutil:   /opt/TinyTeX/texmf-config/web2c/fmtutil.cnf
fmtutil [INFO]: writing formats under /opt/TinyTeX/texmf-var/web2c
fmtutil [INFO]: --- remaking luatex with luatex
fmtutil: running `luatex -ini   -jobname=luatex -progname=luatex luatex.ini' ...
This is LuaTeX, Version 1.07.0 (TeX Live 2018)  (INITEX)
 restricted system commands enabled.
(/opt/TinyTeX/texmf-dist/tex/generic/tex-ini-files/luatex.ini
(/opt/TinyTeX/texmf-dist/tex/generic/tex-ini-files/luatexconfig.tex
(/opt/TinyTeX/texmf-dist/tex/generic/tex-ini-files/pdftexconfig.tex))
(/opt/TinyTeX/texmf-dist/tex/generic/config/luatexiniconfig.tex)
(/opt/TinyTeX/texmf-dist/tex/generic/unicode-data/load-unicode-data.tex 
load-unicode-data.tex v1.7 (2018-06-09)
Reading Unicode data
# UnicodeData-11.0.0.txt
# Downloaded 2018-06-09 06:00:00 GMT [JAW]
) (/opt/TinyTeX/texmf-dist/tex/plain/etex/etex.src
(/opt/TinyTeX/texmf-dist/tex/plain/base/plain.tex
Preloading the plain format: codes, registers, parameters, fonts, more fonts,
macros, math definitions, output routines, hyphenation
(/opt/TinyTeX/texmf-dist/tex/generic/hyphen/hyphen.tex
[skipping from \patterns to end-of-file...]))
(/opt/TinyTeX/texmf-dist/tex/plain/etex/etexdefs.lib
Skipping module "grouptypes"; Loading module "interactionmodes";
Skipping module "nodetypes"; Skipping module "iftypes";)
(/home/rstudio/.TinyTeX/texmf-var/tex/generic/config/language.def
(/opt/TinyTeX/texmf-dist/tex/generic/hyphen/hyphen.tex))
Augmenting the Plain TeX definitions: \tracingall;
Adding new e-TeX definitions: \eTeX, \loggingall, \tracingnone,
register allocation; extended register allocation; 
Recycling: \addlanguage, \@nswer (not defined), \@sk, \b@dresponsetrue,
\b@dresponsefalse, \ch@ckforyn, \mayber@cycle, \et@xabort, \et@xbuf,
\et@xfmtsrc, \et@xfilehdr, \et@xinf, \et@xpatterns, \l@ngdefnfile, \n@xt,
\p@rse (not defined), \pr@mpt (not defined), \pr@mptloop (not defined),
\forcer@cycle, \usef@llback, \usef@llbacktrue, \usef@llbackfalse, 
Retaining: \et@xerr, \et@xinput, \et@xlibhdr, \et@xmsg, \et@xtoks, \et@xwarn,
\et@xl@@d, \et@xl@ad, \et@xload, \et@xlang, \et@xhash, \eTeX, \etexhdrchk,
\etexstatus, \module, \uselanguage, \r@tain, \r@cycle,))
Beginning to dump on file luatex.fmt
 (format=luatex 2018.10.12)
3253 strings using 10346 bytes
68201 memory locations dumped; current usage is 148&7552
1808 multiletter control sequences
\font\nullfont=nullfont
\font\tenrm=cmr10
\font\preloaded=cmr9
\font\preloaded=cmr8
\font\sevenrm=cmr7
\font\preloaded=cmr6
\font\fiverm=cmr5
\font\teni=cmmi10
\font\preloaded=cmmi9
\font\preloaded=cmmi8
\font\seveni=cmmi7
\font\preloaded=cmmi6
\font\fivei=cmmi5
\font\tensy=cmsy10
\font\preloaded=cmsy9
\font\preloaded=cmsy8
\font\sevensy=cmsy7
\font\preloaded=cmsy6
\font\fivesy=cmsy5
\font\tenex=cmex10
\font\preloaded=cmss10
\font\preloaded=cmssq8
\font\preloaded=cmssi10
\font\preloaded=cmssqi8
\font\tenbf=cmbx10
\font\preloaded=cmbx9
\font\preloaded=cmbx8
\font\sevenbf=cmbx7
\font\preloaded=cmbx6
\font\fivebf=cmbx5
\font\tentt=cmtt10
\font\preloaded=cmtt9
\font\preloaded=cmtt8
\font\preloaded=cmsltt10
\font\tensl=cmsl10
\font\preloaded=cmsl9
\font\preloaded=cmsl8
\font\tenit=cmti10
\font\preloaded=cmti9
\font\preloaded=cmti8
\font\preloaded=cmti7
\font\preloaded=cmu10
\font\preloaded=cmmib10
\font\preloaded=cmbsy10
\font\preloaded=cmcsc10
\font\preloaded=cmssbx10
\font\preloaded=cmdunh10
\font\preloaded=cmr7 at 14.51799pt
\font\preloaded=cmtt10 at 14.4pt
\font\preloaded=cmssbx10 at 14.4pt
\font\preloaded=manfnt
50 preloaded fonts
warning  (pdf backend): no pages of output.
Transcript written on luatex.log.
fmtutil [INFO]: /opt/TinyTeX/texmf-var/web2c/luatex/luatex.fmt installed.
TeX::LSR: ls-R file not writable, skipping: /opt/TinyTeX/texmf-var/ls-R
Cannot write ls-R in /opt/TinyTeX/texmf-var. at /opt/TinyTeX/texmf-dist/scripts/texlive/mktexlsr.pl line 583.
tlmgr install bbm-macros
tlmgr: package repository http://mirror.hmc.edu/ctan/systems/texlive/tlnet (verified)
[1/1, ??:??/??:??] install: bbm-macros [2k]
open(>/opt/TinyTeX/tlpkg/texlive.tlpdb) failed: Permission denied at /opt/TinyTeX/tlpkg/TeXLive/TLUtils.pm line 1154.
tlmgr path add
! LaTeX Error: File `bbm.sty' not found.

! Emergency stop.
<read *> 

Error: Failed to compile test.tex. See test.log for more info.
Execution halted
raubreywhite commented 6 years ago

I guess it didn't recognize the new TinyTex install, because it's not on the PATH?

yihui commented 6 years ago

I don't have an idea about the failure to install LaTeX packages. The error message seems to indicate that the installer didn't have write permission to /opt/TinyTeX/texmf-var.

cboettig commented 6 years ago

@yihui thanks much for the reply!

Note that tinytex::tlmgr_install("bbm") is actually installing the package just fine, so that is not the problem.

The problem has to do with however LateX is detecting the installed package. LaTeX claims it cannot find the package, and attempts to re-install it.

Note that from R, tinytex::tlmgr_search("bbm") also finds the package just fine, but when the same thing is run by LaTeX, it says:

tlmgr search --file --global '/bbm.sty'
! LaTeX Error: File `bbm.sty' not found.

I would really appreciate your help in digging around here a bit. It definitely does have permission to write to all of /opt/TinyTeX, which is (recursively) owned by the staff group. I believe I've followed your FAQ to the letter for system-wide install:

https://github.com/rocker-org/rocker-versioned/blob/db064ba5e89533e2a73bbc6202799d745e39c962/verse/Dockerfile#L40-L52

(Anything jump out at you there?) Things do work fine at the user level install, but we really prefer a system-wide setup here. Can you try running the (or I can spin up a server if you'd prefer).

yihui commented 6 years ago

I've followed your FAQ to the letter [...]

I see. That might be the problem. The part for changing permission shouldn't be followed to the letter. The commands chown and chmod were only examples. In particular, root:staff is meant to be changed according to your system, and I don't know if root is the appropriate user or staff is an appropriate group (or other users are in the staff group).

cboettig commented 6 years ago

@yihui root:staff is correct, I did not mean to suggest that I was blindly following the directions. You may have got root:staff from our Docker configuration in the first place (you recall helping me when we first migrated to tinytex while you were writing the FAQ), as it is how system permissions are managed across rocker images -- the user is always part of the staff group. This is also how we manage global installs of R packages, since /usr/lib/local/R is owned by staff and R packages install there as we set that as the default.

Also, it's quite clear that the user has write permissions to /opt/TinyTeX, since tinytex::tlmgr_install() runs fine from the user, and otherwise would fail. The part I haven't been able to figure out is how LaTeX is deciding to automatically install style packages with tlmgr in the first place -- it didn't use to -- and why when doing so it seems to get something different from tlmgr search --file --global than what I get when running that manually. Any ideas?

yihui commented 6 years ago

@cboettig Okay, I guess I was confused by the error messages above (which indicated permission issues): https://github.com/rocker-org/rocker-versioned/issues/104#issuecomment-429358344. If the permission was set correctly, I might be able to help more.

The part I haven't been able to figure out is how LaTeX is deciding to automatically install style packages with tlmgr in the first place -- it didn't use to

If the .tex document is compiled through the R package tinytex, missing LaTeX packages will be automatically installed by default (I thought you knew that). Note that the intermediate .tex output files of R Markdown are compiled through tinytex, therefore when compile Rmd files, missing LaTeX packages will be installed automatically.

and why when doing so it seems to get something different from tlmgr search --file --global than what I get when running that manually.

I'm lost here. Just to be clear, is this your confusion? You installed a LaTeX package, but LaTeX couldn't find it.

If it is, using tinytex::tlmgr_search() or tlmgr search --file --global is not the correct way to verify if a package has been installed successfully. You need to use tlmgr info with the package name, e.g.

$ tlmgr info bbm-macros
package:     bbm-macros
category:    Package
shortdesc:   LaTeX support for "blackboard-style" cm fonts
longdesc:    Provides LaTeX support for Blackboard variants of Computer Modern fonts. Declares a font family bbm so you can in principle write running text in blackboard bold, and lots of math alphabets for using the fonts within maths.
installed:   Yes
revision:    17224
sizes:       run: 17k
relocatable: No
cat-date:    2016-06-24 19:18:15 +0200
cat-license: lppl
cat-topics:  font-supp
collection:  collection-fontsextra

Are you sure installed is Yes?

cboettig commented 6 years ago

@yihui

Yes, I see:

rstudio@becafa2ea451:~$ tlmgr info bbm-macros
package:     bbm-macros
category:    Package
shortdesc:   LaTeX support for "blackboard-style" cm fonts
longdesc:    Provides LaTeX support for Blackboard variants of Computer Modern fonts. Declares a font family bbm so you can in principle write running text in blackboard bold, and lots of math alphabets for using the fonts within maths.
installed:   Yes
revision:    17224
sizes:       run: 17k
relocatable: No
cat-date:    2016-06-24 19:18:15 +0200
cat-license: lppl
cat-topics:  font-supp
collection:  collection-fontsextra

So it's installed, as I claim.

When I press the Knit button in RStudio, I see this in the render panel:


processing file: test.Rmd
  |.................................................................| 100%
  ordinary text without R code

/usr/lib/rstudio-server/bin/pandoc/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template /usr/local/lib/R/site-library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' --variable 'compact-title:yes' 
output file: test.knit.md

tlmgr search --file --global '/bbm.sty'
Trying to automatically install missing LaTeX packages...
tlmgr install bbm-macros
tlmgr: package repository http://mirrors.ibiblio.org/pub/mirrors/CTAN/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr install: package already present: bbm-macros
tlmgr path add
tlmgr search --file --global '/bbm.sty'
! LaTeX Error: File `bbm.sty' not found.

As you can see in the dialog above, RStudio has automatically detected the bbm call, and it has called tlmgr search --file --global '/bbm.sty', which is why I mentioned that command. As you can see above, it is not finding anything, despite the fact that when I run it, it finds it, and despite the fact tlmgr info bbm-macros shows the package is installed.

So I know that

If the .tex document is compiled through the R package tinytex, missing LaTeX packages will be automatically installed by default

but I don't know precisely how installed by default is doing things, in particular, what environment it has that is causing it not to see what I see when I run tlmgr. Also, I don't know how to turn off this default.

If you have Docker installed, run:

docker run -p 8787:8787 -e DISABLE_AUTH=true rocker/verse

go to localhost:8787 and create an Rmd with the above header, you should see exactly what I see in an active RStudio session, if it helps to poke around.

yihui commented 6 years ago

That's really odd. I don't use Docker myself. Is there an existing server that I can test with? If not, no problem, I can install Docker and the image myself.

cboettig commented 6 years ago

Yes, I've pinged you in twitter with access info for a server

cboettig commented 6 years ago

@raubreywhite So as @yihui points out, there's something funny with how tinytex or tlmgr is handling permissions here which I don't understand, for some reason it doesn't seem to respect linux groups.

Anyway, till I have a better solution, I've set chown -R rstudio:staff /opt/TinyTeX in the Dockerfiles, which should make it work in a single-user solution without having anything installed in your home directory...

eddelbuettel commented 6 years ago

FWIW this particularly example 'works for me' in Ubuntu as bbm.sty is in texlive-fonts-extra which I have installed -- but whenever I had in the past something that tickled tinytex into action, it generally resulted in an error.

I never pursued this further as I actually do not prefer LaTeX to install in $HOME -- I like what texlive does, and it generally works for me via the Debian / Ubuntu packages so I tend not to run tlmgr myself or via tinytex. As best as I can tell from a decidedly rather casual look, there may be more going on and texlive's file indexing and tlmgr / tinytex may be talking past each other. I could of course be completely wrong and missing something simpler -- just wanted to add that I have seen it mostly fail.

In case I could help by testing something locally. I'd be happy to do so. I also have a good working relationship with the Debian texlive maintainer if we needed get advice.

cboettig commented 6 years ago

@raubreywhite This has now been fixed upstream, so everything should work as expected with the system-wide installation regardless of user. Thanks again for the opening the bug report.

agilebean commented 3 years ago

@raubreywhite This has now been fixed upstream, so everything should work as expected with the system-wide installation regardless of user. Thanks again for the opening the bug report.

Can you reopen this issue?

Unfortunately, the error still persists. To summarize the problem: A latex package (here: wrapfig) is installed, but tinytex does not see it during rmarkdown pdf generation, so tries to install it, and then finds it already installed. Then, strangely, it complains that the .sty file does not exist.

I have exactly the same error as @cboettig initially reported, just with a different package:

/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine xelatex --variable graphics --variable 'geometry:margin=1in' --include-in-header /var/folders/90/kz2y3m3n3_s5k9hv9tg3d8mh0000gn/T//RtmpEXuSHw/rmarkdown-str1f685dda1fc2.html 
tlmgr update --all --self
tlmgr: package repository https://mirrors.rit.edu/CTAN/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr install: package already present: wrapfig
! LaTeX Error: File `wrapfig.sty' not found.

! Emergency stop.

As for @cboettig, the package is installed:

tlmgr info wrapfig
package:     wrapfig
category:    Package
shortdesc:   Produces figures which text can flow around
longdesc:    Allows figures or tables to have text wrapped around them. Does not work in combination with list environments, but can be used in a parbox or minipage, and in twocolumn format. Supports the float package.
installed:   Yes
revision:    22048
sizes:       run: 29k
relocatable: No
cat-version: 3.6
cat-license: lppl
cat-topics:  text-flow
cat-related: floatflt
collection:  collection-latexextra