Using rmarkdown with TeX Live 2019: the directory /usr/local/texlive/2019/tlpkg/ is not writable.

I'm trying to use R Studio, R version 3.6.3 and MacTex (TeX Live) to create a pdf from a *.Rmd file.

My code:

---
title: "Test"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)```

Error message:

processing file: Untitled.Rmd
  |.......................                                               |  33%
  ordinary text without R code

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

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


/usr/local/bin/pandoc +RTS -K512m -RTS Untitled.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output Untitled.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter /Users/Jo/Library/R/3.6/library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /Users/Jo/Library/R/3.6/library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in' 
output file: Untitled.knit.md

TeX Live 2019 is frozen forever and will no
longer be updated.  This happens in preparation for a new release.

If you're interested in helping to pretest the new release (when
pretests are available), please read [link omitted].
Otherwise, just wait, and the new release will be ready in due time.
You don't have permission to change the installation in any way,
specifically, the directory /usr/local/texlive/2019/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
tlmgr: package repository [link omitted] 
(not verified: valid signature with expired key)
TeX Live 2019 is frozen forever and will no
longer be updated.  This happens in preparation for a new release.

If you're interested in helping to pretest the new release (when
pretests are available), please read [link omitted].
Otherwise, just wait, and the new release will be ready in due time.
You don't have permission to change the installation in any way,
specifically, the directory /usr/local/texlive/2019/tlpkg/ is not writable.
Please run this program as administrator, or contact your local admin.
tlmgr: An error has occurred. See above messages. Exiting.
fmtutil [ERROR]: format directory not writable: /usr/local/texlive/2019/texmf-var/web2c
You don't have permission to change the installation in any way,
specifically, the directory /usr/local/texlive/2019/tlpkg/ is not writable.
Please run this program as administrator, or contact your local admin.
tlmgr: An error has occurred. See above messages. Exiting.
! LaTeX Error: File `kvoptions.sty' not found.

! Emergency stop.
<read *>

How should I proceed / do you need any other information to assess the problem?
Thank you so much!

Edit:

Interestingly tho, the errors remain the same when I try to render the *Rmd file as the admin. I checked the permissions for the path mentioned in the error message, hope that helps.

admin@MacBook-Jo Jo % ls -ld "/usr/local/texlive/2019/tlpkg/"
drwxr-xr-x  24 root  staff  768  8 Apr 20:01 /usr/local/texlive/2019/tlpkg/
admin@MacBook-Jo Jo % dscl . read /Groups/staff GroupMembership
GroupMembership: root admin

Following technocrat's suggestion I posted the question on a LaTeX forum: https://tex.stackexchange.com/questions/537532/error-undefined-control-sequence-using-r-markdown-to-create-a-pdf-under-mact

Hi, and welcome!

The key information is

You don't have permission to change the installation in any way,
specifically, the directory /usr/local/texlive/2019/tlpkg/ is not writable.
Please run this program as administrator

There multiple dancers in this ballet but the principal dancer is texlive. I'm not sure why pandoc needs to update texlive for the tlpkg package, but it can't because it's running under a user id that doesn't have administrative privileges.

The best way to fix this without losing sanity to through the TexLiveUtility app to install tlpkg, so that pandoc doesn't have to be involved.

Please see the FAQ: What's a reproducible example (`reprex`) and how do I create one? Using a reprex, complete with representative data will attract quicker and more answers.

1 Like

You are missing a latex package to render your document. tinytex :package: will try to install automatically the missing package. However, it seems you use a system texlive installation on which you don't have the rights do modify and add package. That is why you get a error.

One try would be to contact your admin to ask adding this kvoptions tex package.

You can also look texlive usermode to deal with this I think. See also with your admin what seems the best solution.
https://www.tug.org/texlive/doc/tlmgr.html#USER-MODE

Hope it helps

2 Likes

Thanks for your quick reply!

I don't seem to find a package called tlpkg on any of the mirrors tho... Did I misunderstand something?

admin@MacBook-Jo Jo % sudo tlmgr --verify-repo=none  install tlpkg
TeX Live 2019 is frozen forever and will no
longer be updated.  This happens in preparation for a new release.

If you're interested in helping to pretest the new release (when
pretests are available), please read https://tug.org/texlive/pretest.html.
Otherwise, just wait, and the new release will be ready in due time.
tlmgr: package repository https://packages.oth-regensburg.de/ctan/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr install: package tlpkg not present in repository.
tlmgr: action install returned an error; continuing.
tlmgr: An error has occurred. See above messages. Exiting.

Installing kvoptions worked! I seem to have encountered another error further downstream tho...

/usr/local/bin/pandoc +RTS -K512m -RTS Untitled.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output Untitled.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter /Users/Jo/Library/R/3.6/library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /Users/Jo/Library/R/3.6/library/rmarkdown/rmd/lua/latex-div.lua --variable 'geometry:margin=1in' 
! Undefined control sequence.
l.10 \ifnum 0\ifxetex
                      1\fi\ifluatex 1\fi=0 % if pdftex 

Fehler: LaTeX failed to compile Untitled.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.log for more info.

I'm quite lost at what to make of this to be honest. Would you happen to have any ideas on this?

Untitled.log

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex 2020.4.8) 8 APR 2020 20:53
entering extended mode
restricted \write18 enabled.
file:line:error style messages enabled.
%&-line parsing enabled.
**Untitled.tex
(./Untitled.tex
LaTeX2e <2018-12-01>
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2018/09/03 v1.4i Standard LaTeX file (size option)
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/local/texlive/2019/texmf-dist/tex/latex/lm/lmodern.sty
Package: lmodern 2009/10/30 v1.6 Latin Modern Fonts
LaTeX Font Info: Overwriting symbol font operators' in version normal'
(Font) OT1/cmr/m/n --> OT1/lmr/m/n on input line 22.
LaTeX Font Info: Overwriting symbol font letters' in version normal'
(Font) OML/cmm/m/it --> OML/lmm/m/it on input line 23.
LaTeX Font Info: Overwriting symbol font symbols' in version normal'
(Font) OMS/cmsy/m/n --> OMS/lmsy/m/n on input line 24.
LaTeX Font Info: Overwriting symbol font largesymbols' in version normal'
(Font) OMX/cmex/m/n --> OMX/lmex/m/n on input line 25.
LaTeX Font Info: Overwriting symbol font operators' in version bold'
(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 26.
LaTeX Font Info: Overwriting symbol font letters' in version bold'
(Font) OML/cmm/b/it --> OML/lmm/b/it on input line 27.
LaTeX Font Info: Overwriting symbol font symbols' in version bold'
(Font) OMS/cmsy/b/n --> OMS/lmsy/b/n on input line 28.
LaTeX Font Info: Overwriting symbol font largesymbols' in version bold'
(Font) OMX/cmex/m/n --> OMX/lmex/m/n on input line 29.
LaTeX Font Info: Overwriting math alphabet \mathbf' in version normal'
(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 31.
LaTeX Font Info: Overwriting math alphabet \mathsf' in version normal'
(Font) OT1/cmss/m/n --> OT1/lmss/m/n on input line 32.
LaTeX Font Info: Overwriting math alphabet \mathit' in version normal'
(Font) OT1/cmr/m/it --> OT1/lmr/m/it on input line 33.
LaTeX Font Info: Overwriting math alphabet \mathtt' in version normal'
(Font) OT1/cmtt/m/n --> OT1/lmtt/m/n on input line 34.
LaTeX Font Info: Overwriting math alphabet \mathbf' in version bold'
(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 35.
LaTeX Font Info: Overwriting math alphabet \mathsf' in version bold'
(Font) OT1/cmss/bx/n --> OT1/lmss/bx/n on input line 36.
LaTeX Font Info: Overwriting math alphabet \mathit' in version bold'
(Font) OT1/cmr/bx/it --> OT1/lmr/bx/it on input line 37.
LaTeX Font Info: Overwriting math alphabet \mathtt' in version bold'
(Font) OT1/cmtt/m/n --> OT1/lmtt/m/n on input line 38.
)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/amssymb.sty
Package: amssymb 2013/01/14 v3.01 AMS font symbols

(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/amsfonts.sty
Package: amsfonts 2013/01/14 v3.01 Basic AMSFonts support
@emptytoks=\toks14
\symAMSa=\mathgroup4
\symAMSb=\mathgroup5
LaTeX Font Info: Overwriting math alphabet \mathfrak' in version bold'
(Font) U/euf/m/n --> U/euf/b/n on input line 106.
))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsmath.sty
Package: amsmath 2018/12/01 v2.17b AMS math features
@mathmargin=\skip43

For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amstext.sty
Package: amstext 2000/06/29 v2.01 AMS text

(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0 generic functions
@emptytoks=\toks15
\ex@=\dimen103
))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsbsy.sty
Package: amsbsy 1999/11/29 v1.2d Bold Symbols
\pmbraise@=\dimen104
)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsopn.sty
Package: amsopn 2016/03/08 v2.02 operator names
)
\inf@bad=\count88
LaTeX Info: Redefining \frac on input line 223.
\uproot@=\count89
\leftroot@=\count90
LaTeX Info: Redefining \overline on input line 385.
\classnum@=\count91
\DOTSCASE@=\count92
LaTeX Info: Redefining \ldots on input line 482.
LaTeX Info: Redefining \dots on input line 485.
LaTeX Info: Redefining \cdots on input line 606.
\Mathstrutbox@=\box27
\strutbox@=\box28
\big@size=\dimen105
LaTeX Font Info: Redeclaring font encoding OML on input line 729.
LaTeX Font Info: Redeclaring font encoding OMS on input line 730.
\macc@depth=\count93
\c@MaxMatrixCols=\count94
\dotsspace@=\muskip10
\c@parentequation=\count95
\dspbrk@lvl=\count96
\tag@help=\toks16
\row@=\count97
\column@=\count98
\maxfields@=\count99
\andhelp@=\toks17
\eqnshift@=\dimen106
\alignsep@=\dimen107
\tagshift@=\dimen108
\tagwidth@=\dimen109
\totwidth@=\dimen110
\lineht@=\dimen111
@envbody=\toks18
\multlinegap=\skip44
\multlinetaggap=\skip45
\mathdisplay@stack=\toks19
LaTeX Info: Redefining [ on input line 2844.
LaTeX Info: Redefining ] on input line 2845.
)
(/usr/local/texlive/2019/texmf-dist/tex/generic/iftex/iftex.sty
Package: iftex 2013/04/04 v0.2 Provides if(tex) conditional for PDFTeX, XeTeX,
and LuaTeX
)
./Untitled.tex:10: Undefined control sequence.
l.10 \ifnum 0\ifxetex
1\fi\ifluatex 1\fi=0 % if pdftex
? x

Here is how much of TeX's memory you used:
1115 strings out of 492616
12608 string characters out of 6129482
71085 words of memory out of 5000000
5095 multiletter control sequences out of 15000+600000
3640 words of font info for 14 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
27i,0n,27p,222b,36s stack positions out of 5000i,500n,10000p,200000b,80000s
No pages of output.
PDF statistics:
0 PDF objects out of 1000 (max. 8388607)
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)

1 Like

No sorry I don't know. This is not a R error but a latex error.
Are you using a custom template ?

You should look into the web for latex error and see if there is something else missing in your latex installation.

1 Like

There is a very recent issue that changed something and that could be related...

It is about iftex. :thinking:

can you check if you have iftex latex package ?
or maybe reinstall it ?

\LaTeX is a bit of a dark art, especially for peeps who don't use it in its fully glory all the time from an editor.

This error traces to a malformed LaTeX statement in or from the iftex.sty style.

./Untitled.tex:10: Undefined control sequence.
l.10 \ifnum 0\ifxetex
1\fi\ifluatex 1\fi=0 % if pdftex
? x

basically means, huh??, a syntax violation.

The keys to the error may be in this page. You'll probably get quicker and better answers, though, from the \LaTeX community here or one of the non-English boards.

1 Like

I'm not using a custom template, I'm using everything in default settings. I also reinstalled my MacTex and checked that iftex is installed. :thinking:

I'll try to reinstall iftex for sure measure.

Thanks a lot! I'll go check the page out / ask the masters of the dark art.

Can you open TexLiveUtility app and check that you see what's in the screenshot?

1 Like

Seems to be installed :thinking:

OK, that narrows it to the lines that iftex is being fed.

Someone, including even me, can probably run that down and suggest a fix. However,, that's not what I am best at and I can be more helpful to the community by sticking to problems more closely related to R.

Tell you what, though. I'll stay with you on this if you can do two things:

  1. Skinny down the Rmd file to its bare essentials to throw the error. 2,845 lines produces a lot of noise to cut through. See if you can get it down to the simplest file that reproduces the error.
  2. Dig out the related tex file and post it. I might be able to see what's happening within a \TeX editor.
2 Likes

Thank you for staying on this with me!

This is the *.rmd file at its skinniest, tho not much different to the one before:

---
output: pdf_document
---
Untitled.tex
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering

\author{}
\date{\vspace{-2.5em}}

\begin{document}



\end{document}
1 Like

Great! Thanks.

Just cut and pasted it and ran without inspection and got a has to be included in preamble; not sure that's directly related, but I'll see if I can unravel the spaghetti.

A further skinnied down \TeX compiles; still testing

1 Like

Oh, just read cderv! Try

update.packages("tinytex")
1 Like

I updated all packages + specifically tinytex, the error persists tho. :thinking: Tinytex was already up to date.

1 Like

GAK! I'm about to turn in. If this falls off my radar tomorrow (Seattle time), just edit your post barely and I'll get notified.

1 Like

Mea culpa... After reinstalling MacTex I forgot to update all packages, I did that just now and everything works fine now. It seems my MaxTex installation was somewhat corrupted, I guess?

Really, thanks a lot for your help and stay healthy! :heart:

2 Likes