Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install_tinytex does not work if username has a space in it #420

Closed
AJThurston opened this issue Sep 3, 2023 · 15 comments · Fixed by #429
Closed

install_tinytex does not work if username has a space in it #420

AJThurston opened this issue Sep 3, 2023 · 15 comments · Fixed by #429
Assignees

Comments

@AJThurston
Copy link


running xelatex - 1
command xelatex not found, attempting install
finding package for xelatex

1 package to install
installing xelatex (1 of 1)
ERROR: tlmgr returned a non zero status code
'C:\Users\AJ' is not recognized as an internal or external command,
operable program or batch file.


My machine's username is "AJ Thurston"

@cderv
Copy link
Contributor

cderv commented Sep 4, 2023

ERROR: tlmgr returned a non zero status code

This is the error so I wonder if this is not an issue with tlmgr itself and even after install you could have issue.

Anyhow, this type of error was reported in the past:

so you should try what is adviced on #210 (comment)

@cderv cderv added the question label Sep 4, 2023
@wesleyburr
Copy link

Can confirm this does not work with spaces. We just finished a deployment of about 800 manual installs of TinyTex onto a variety of user machines, and ran into 5-10 who had this issue running on new-ish Windows 11 OS systems. It presents as

finding package for scrartcl.cls

compilation failed- no matching pacakges
LaTeX Error: File scrartcl.cls not found.

Type X to quite or <RETURN> to proceed,
or enter new file name. (Default extension: cls)

when trying to Render a default brand-new Quarto document with no modifiers, except to say

format: pdf

So R + Rtools + RStudio + tinytex + quarto + tinytex::install_tinytex() -> make a new Quarto doc, specify pdf -> save -> Render, and it fails. Very reproducible - just need the User doing the activity to have a username with a space in it.

After a lot of back and forth trying to debug it, and not knowing to search "space in user name" as an issue, we discovered a functional workaround. Manually go into C:\Users\[user name with spaces]\AppData\Roaming\ and delete the TinyTex folder entirely. Then, to be sure, run R as Administrator, and reinstall the package, and then do the install with the modifiers:

install.packages("tinytex")
tinytex::install_tinytex(bundle="TinyTex-2", force = TRUE, dir = "C:\Users\TinyTex")

This ensures that: there are no permissions issues (e.g., with OneDrive syncing); the old version of TinyTex is gone (if you skip this, it still defaults to that one); that the FULL CTAN library is installed, which skips the "first time you Quarto Render it sorts out stuff by downloading more CTAN libraries; and bypasses the User with the space by installing into C:\Users\TinyTex. This last could be anywhere, I guess, but this keeps it out of the way so the User doesn't notice it and touch it (since Windows users rarely go outside of their own home directory).

Can probably skip the bundle as well, since once it's not in the User's directory, the space issue is no longer there, and tlmgr can handle things and install on the fly.

It would be nice if these steps could be skipped, since it's not at ALL intuitive that this is the problem. Took a lot of trial and error to track down why these particular users were having this issue.

@yihui
Copy link
Member

yihui commented Sep 15, 2023

@wesleyburr Thank you so much for sharing your experience! That's very helpful.

I don't have a Windows machine to test with. @cderv might be able to help and see if the problem is reproducible. If the problem only affects users who have spaces in their Windows usernames, and it started only recently, I guess it might be a bug of either Quarto or TeX Live. To verify, you can try to compile a test.tex file directly:

\documentclass{scrartcl}
\begin{document}
Test.
\end{document}

If tinytex is able to install the koma-script LaTeX package automatically in this case, the culprit must be Quarto or RStudio:

tinytex::tlmgr_remove('koma-script')
tinytex::pdflatex('test.tex')

@wesleyburr
Copy link

I'll try to replicate this deliberately with a brand new install next week, and then test your suggestion to narrow down the root. I've been reverse engineering it (six different computers fixed by following the path above), but haven't tried a MRL on a VM yet. Added to my todo list!

@wesleyburr
Copy link

wesleyburr commented Sep 18, 2023

Update: easy reproduction of the error.

  1. Windows 10 in a VM.
  2. Make a user with a space ("Test User")
  3. RStudio 2023.06.2, R 4.3.1, Rtools
  4. install.packages(c("rmarkdown", "quarto", "tinytex"))
  5. tinytex::install_tinytex() - installs to C:\Users\Test User\AppData\Roaming\TinyTex\
  6. New Quarto doc, choose PDF.
  7. Save, Render.

image

From your suggestion about manually checking, make that test.tex file, and run

tinytex::pdflatex('test.tex')

and interestingly, it installs koma-script just fine. And compiles.

image

So it's not tlmgr or tinytex, it's something else in the way that the Quarto render is running ... ?

@yihui
Copy link
Member

yihui commented Sep 18, 2023

@wesleyburr Great! Thanks for the verification! I think this means the problem comes from the Quarto side. I don't know why it can't run tlmgr when the user name contains a space (perhaps it didn't quote the path to tlmgr properly). You may file a report there: https://github.com/quarto-dev/quarto-cli/issues

@cderv
Copy link
Contributor

cderv commented Sep 19, 2023

Thanks a lot for all these informations. I'll have a look into this with Quarto not working as it should.

@cderv cderv self-assigned this Sep 19, 2023
@cderv cderv added the quarto label Sep 19, 2023
@yihui
Copy link
Member

yihui commented Oct 31, 2023

I've found a Windows machine, created a user with spaces in the name, and was able to reproduce the problem with Quarto.

  • tinytex::install_tinytex() worked fine when the system username contains spaces (so what the title of this post indicated may not be true).

  • tinytex::xelatex() and friends also worked fine to find and install missing LaTeX packages.

  • quarto render failed to identify or install LaTeX packages. To reproduce the problem, you can first remove a package, e.g., tinytex::tlmgr_remove('koma-script'), and then render a minimal document to PDF with Quarto:

    ---
    title: Test
    format: pdf
    ---
    
    Test.
    

    Quarto is unable to identify the koma-script package from the missing file scartcl.cls.

@cderv
Copy link
Contributor

cderv commented Oct 31, 2023

Interesting. So this is a Quarto issue regarding path with names. Is that right ?

@yihui
Copy link
Member

yihui commented Oct 31, 2023

I think so, although I don't understand why.

@yihui
Copy link
Member

yihui commented Nov 7, 2023

This reply https://tug.org/pipermail/tex-live/2023-November/049634.html makes me feel we need to rethink the installation directory when the username contains multibyte characters on Windows. And the problem in this Github issue makes me feel we also need to use a path that doesn't even contain spaces. Something like C:/TinyTeX...

For the Quarto issue, I'm not sure if this diagnosis is correct: https://tug.org/pipermail/tex-live/2023-November/049635.html I don't have my Windows machine at hand this week, and will check it next week.

@yihui
Copy link
Member

yihui commented Nov 14, 2023

For now, I'm thinking of using C:/ProgramData/ (the path can be obtained from the env var ProgramData) to install TinyTeX. This path doesn't contain spaces or non-ASCII characters, and seems to be writable for any user no matter the user has admin privilege or not.

This means we need to change APPDATA to ProgramData in

  1. The R installer tinytex::install_tinytex();
  2. The bat installers https://github.com/rstudio/tinytex/blob/main/tools/install-bin-windows.bat and https://github.com/rstudio/tinytex/blob/main/tools/install-windows.bat;
  3. quarto install tinytex;

The only uncertainty to me at the moment is whether ProgramData is guaranteed to be writable. If not, where should we install TinyTeX? We can't use user-specific directories when the username contains non-ASCII characters.

@cderv
Copy link
Contributor

cderv commented Nov 15, 2023

Are you planning to do the change only when user name has specific character ? Or move all install from APPDATA to ProgramDATA ?

FWIW this folder is hidden on Windows

> (Get-ItemProperty $env:ProgramData).Attributes
Hidden, Directory, NotContentIndexed

And this is where any Global installation of tools I have are installing some files

This is also the path use for ALLUSERSPROFILE env var on my system.

Good be a good place to store those - there would just be conflict probably on some multiple user windows server or windows computer as this is global. I would mean the TinyTeX install will be shared.

Maybe this needs to stay optional and opt-in when we detect potential username issue

@yihui
Copy link
Member

yihui commented Nov 15, 2023

Yes, ProgramData is hidden by default.

And yes, I was thinking of falling back to ProgramData when APPDATA contains spaces or non-ASCII characters. This means when the bib/windows/ directory is not in PATH, tinytex (and Quarto) will have to search both places for the possible installation. Note that tinytex::install_tinytex() also allows users to specify an arbitrary directory to install TinyTeX, so if they don't like the default path, they can provide their own choice.

I also discovered that tlmgr path add was unable to modify PATH on my Windows machine. That means if TinyTeX is not installed to APPDATA or ProgramData, it won't be found (unless options(tinytex.tlmgr.path) is set). I need to investigate this. Update: I was wrong. Forget it.

yihui added a commit that referenced this issue Nov 17, 2023
@yihui
Copy link
Member

yihui commented Nov 17, 2023

I'll write a blog post about this change tomorrow. In short, if APPDATA contains spaces or non-ASCII characters,

  • Users will see a warning message when reinstalling or using TinyTeX that was previously installed to APPDATA. The message will tell users how to move TinyTeX to ProgramData, i.e.,
    tinytex::copy_tinytex(to = Sys.getenv('ProgramData'), move = TRUE)
  • For users who install TinyTeX for the first time, the installation path will be ProgramData.
  • For users who specify a custom installation path via tinytex::install_tinytex(dir = ...), no checking on the path is done currently (but perhaps should be). Checking is done now.

I don't know how quarto install tinytex works. If it uses the installation script tools/install-bin-windows.bat in this repo, there isn't anything you need to do, otherwise you will have to apply the same logic.

@AJThurston @wesleyburr You can move TinyTeX using the R code I mentioned in the first bullet above, which requires the development version of tinytex:

remotes::install_github('rstudio/tinytex')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants