yonicd/texPreview

Missing requirements in check_requirement ?

cderv opened this issue · 15 comments

cderv commented

I did run check_requirements which gave me this:

> texPreview::check_requirements()
  xcolor booktabs multirow    array   helvet  amsmath rotating listings 
    TRUE     TRUE    FALSE     TRUE     TRUE     TRUE     TRUE     TRUE 
graphicx setspace  caption 
    TRUE    FALSE     TRUE 
Warning message:
In texPreview::check_requirements() :
  missing tex packages needed for texPreview: multirow, setspace

But running tinytex::tlmgr_install(c("multirow", "setspace")) was not enough

I need to installed other packages:

  • standalone => mentioned in the README but not in check_requirement()
  • varwidth
  • colortbl

It would be interesting to add them to check_requirements(), don't you think ?

After that it worked well ! thanks for this package!

Good point.

How would you change this to grep the necessary deps from the tex template?

https://github.com/yonicd/texPreview/blob/master/R/tex_check.R#L14

tinytex::tlmgr_install(c("multirow", "setspace"))

I was able to install all missing packages using the method described by @cderv. But the helvet package cannot be installed.

Registered S3 methods overwritten by 'htmltools':
  method               from         
  print.html           tools:rstudio
  print.shiny.tag      tools:rstudio
  print.shiny.tag.list tools:rstudio
missing tex packages needed for texPreview: helvetmissing tex packages needed for texPreview: helvet
> tinytex::tlmgr_install(c("helvet"))
tlmgr install helvet
tlmgr install: package helvet not present in repository.
tlmgr: action install returned an error; continuing.
tlmgr: package repository http://ctan.math.washington.edu/tex-archive/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr: An error has occurred. See above messages. Exiting.
tlmgr update --self
tlmgr install helvet
tlmgr install: package helvet not present in repository.
tlmgr: action install returned an error; continuing.
tlmgr: package repository https://ctan.math.illinois.edu/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr: An error has occurred. See above messages. Exiting.

Also, @cderv could you kindly provide more details on how you got it to work? Much appreciated.

cderv commented

@drfurtado this is because helvet is not a package. The message is not good advice for this one.
You are missing helvet.sty - you can look the package by searching using

> tinytex::parse_packages(file = "helvet.sty")
tlmgr search --file --global "/helvet.sty"
[1] "psnfss"

You need to install psnfss: tinytex::tlmgr_install("psnfss")
This will do the both step in one

tinytex::parse_install(file = "helvet.sty")

@yonicd that is why tinytex is interesting with Tex Live.

Does your template change often ? Because you could just hard code the list of package required and not just rely on parsing a .tex file. kableExtra have them in kableExtra:::kableExtra_latex_packages() for example. (to be used in yaml header of a Rmd)

I believe there is no good way to determine from a tex file and that is why tinytex does it by parsing the log : trying and failing, installing, then retrying and failing.

tinytex::parse_install(file = "helvet.sty")

It worked as described. @cderv, you sr are very knowledgeable. Good bless you.
@yonicd, thanks for creating and maintaining this package, which allowed me to do this.

@drfurtado that is great, glad the package has helped you!

@cderv if i try and install a package on macos using tinytex i get the sudo problem i was talking about

> tinytex::tlmgr_install('snapshot')
tlmgr install snapshot
You don't have permission to change the installation in any way,
specifically, the directory /usr/local/texlive/2019basic/tlpkg/ is not writable.
Please run this program as administrator, or contact your local admin.
tlmgr: An error has occurred. See above messages. Exiting.
tlmgr update --self
You don't have permission to change the installation in any way,
specifically, the directory /usr/local/texlive/2019basic/tlpkg/ is not writable.
Please run this program as administrator, or contact your local admin.
tlmgr: An error has occurred. See above messages. Exiting.
tlmgr: package repository https://mirrors.rit.edu/CTAN/systems/texlive/tlnet (not verified: gpg unavailable)
fmtutil [ERROR]: format directory not writable: /usr/local/texlive/2019basic/texmf-var/web2c
tlmgr install snapshot
You don't have permission to change the installation in any way,
specifically, the directory /usr/local/texlive/2019basic/tlpkg/ is not writable.
Please run this program as administrator, or contact your local admin.
tlmgr: An error has occurred. See above messages. Exiting.
cderv commented

How did you install texlive ? Is it a global installation on your system ?
Can you install package with tlmgr without using sudo on your system usually ?
How do you do it without tinytex ?

I believe with an installation of TeX Live in a place accessible by user (which tinytex::install_tinytex() will do it), there won't be access issue. I am not sure it is a sudo issue in tinytex.
However, depending on the answer on the question above we may be able to improve it.

Using standard install of texlive: https://www.tug.org/texlive/quickinstall.html

cderv commented

And with it can you install package with tlmgr install without sudo privilege ?

you have to have sudo privileges

cderv commented

Thanks. So that is why tinytex can't handle. It assume the distribution is in a place writeable to install the tex package. The installation of TinyTeX from the package is in a writeable place.

I feared we missed something. Thanks for the confirmation

so tinytex cant integrate well with existing texlive installations? you need to start from scratch if you want to use tinytex?

cderv commented

tinytex can use the existing installation. It just won't be able to install missing package automatically if the user don't the have the right to do so.

So if your TeX Live installation needs sudo to install CTAN packages, tinytex will also require this. It just don't assume user have any specific right. It will execute tlmgr command as the same user running R process. e.g. the R command tinytex::tlmgr_install() runs tlmgr install on the system. If the user running this has not the correct access right, it won't work.

Do you find it not correct ? What would you suggest to change this ?

that description is right, but a major part of tinytex gets lost in such a case. maybe tinytex::tlmgr_install(sudo = TRUE) or tinytex::tlmgr_sudo_install(...)

in the end in tinytex all that is run is

function (args = character(), usermode = FALSE, ..., .quiet = FALSE) 
{
    tweak_path()
    if (!.quiet && !tlmgr_available()) 
        warning("\nTeX Live does not seem to be installed. See https://yihui.org/tinytex/.\n")
    if (usermode) 
        args = c("--usermode", args)
    if (!.quiet) 
        message(paste(c("tlmgr", args), collapse = " "))
    system2("tlmgr", args, ...)
}

switching out the last call for

system2(command = "pkexec",
        args = "env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY tlmgr",
        stdout = TRUE,
        stderr = TRUE)

i found that in SO

cderv commented

We could indeed support a sudo mode in this case. Not sure about switching for pkexec completely, I suspect it will not work on Windows for example.

Also, it seems a bit too invasive to have a R package run sudo command to act as root. I'll see with Yihui about the choice in tinytex about that.

I know it supports the user mode of TeX Live alreay which is useful for users that don't have write permission to the main installation.

In a way, TinyTeX was created to make a lightweight portable version of TeX Live to avoid all these issue too.

tinytex now is the backend of texpreview. PR #52