Failing to see that LaTeX package is already installed.

For producing a PDF, I am ultimately getting an error of

Trying to automatically install missing LaTeX packages...
tlmgr install pgf
You don't have permission to change the installation in any way,

I fully understand why it doesn't have permission to run that update, but what I don't understand is why it is trying to, as the pgf package is installed

$ kpsewhich pgf.sty
/usr/local/texlive/2019/texmf-dist/tex/latex/pgf/basiclayer/pgf.sty

(it is also up to date).

So while I understand that I could change permissions around to allow unprivileged write to my TeX set up, and that I could also try to purge whatever I'm loading that wants pgf, I am would like to understand (and fix) why Rmarkdown (and the tools it calls) are failing to see that an installed LaTeX package is already in place.

Configuration details

My TOML looks like

---
title: "HOTP modulo bias"
author: "Jeffrey Goldberg"
date: "7/30/2019"
output:
  pdf_document:
    includes:
      in_header: totp_preamble.tex
---

totp_preamble.tex looks like

\newtheorem{lem}{Lemma}
\usepackage[operators]{cryptocode}
\usepackage{booktabs}

\DeclareMathOperator{\IntD}{IntDiv}
%\DeclareMathOperator{\Pr}{Pr}
\newcommand{\ZZ}{\mathbb{Z}}

RStudio version: 1.2.1335, and below is the sessionInfo()

R> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] kableExtra_1.1.0 forcats_0.4.0    stringr_1.4.0    dplyr_0.8.3      purrr_0.3.2      readr_1.3.1      tidyr_0.8.3      tibble_2.1.3    
 [9] ggplot2_3.2.1    tidyverse_1.2.1 

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5  xfun_0.9          haven_2.1.1       lattice_0.20-38   colorspace_1.4-1  generics_0.0.2    vctrs_0.2.0       htmltools_0.3.6  
 [9] viridisLite_0.3.0 yaml_2.2.0        rlang_0.4.0       pillar_1.4.2      glue_1.3.1        withr_2.1.2       modelr_0.1.5      readxl_1.3.1     
[17] munsell_0.5.0     gtable_0.3.0      cellranger_1.1.0  rvest_0.3.4       evaluate_0.14     knitr_1.24        highr_0.8         broom_0.5.2      
[25] Rcpp_1.0.2        scales_1.0.0      backports_1.1.4   webshot_0.5.1     jsonlite_1.6      hms_0.5.1         packrat_0.5.0     digest_0.6.20    
[33] stringi_1.4.3     grid_3.6.0        cli_1.1.0         tools_3.6.0       magrittr_1.5      lazyeval_0.2.2    crayon_1.3.4      pkgconfig_2.0.2  
[41] zeallot_0.1.0     xml2_1.2.2        lubridate_1.7.4   assertthat_0.2.1  rmarkdown_1.15    httr_1.4.1        rstudioapi_0.10   R6_2.4.0         
[49] nlme_3.1-141      compiler_3.6.0   

I have your setup.

There's a longer, preliminary response, in moderation. In the meantime, I updated to the 2019 repository from 2018 by reinstalling MacTex and had no errors with your example. That could be your case too.

I have your set up and can reproduce the problem, but with the cryptocode.sty file before it gets to pkg.sty.


title: "LaTeX headers"
author: "Richard Careaga"
date: "8/31/2019"
output:
pdf_document:
includes:
in_header: totp_preamble.tex

This is a vanilla LaTeX document with the include in the working directory.

It first fails because cryptocode.sty is not installed (and I need to update my repository to 2019). TexLive purports to do the repository update, but the same message occurs. So, I re-install MacTex, using the package installer. As usual, it's a slow, 20-minute download from Tug and the install takes about 10 minutes after that.

While I'm waiting I try from the terminal

tlmgr search --file --global '/cryptocode.sty'

and get the same error message.

If you are still on 2018, this would explain the inability to find pkg.sty.

In the RMarkdown tab, do you get the following message?

> ==> rmarkdown::render('/Users/rc/projects/demo/latexheader.Rmd',  encoding = 'UTF-8');
  |.................................................................| 100%
  ordinary text without R code


/usr/local/bin/pandoc +RTS -K512m -RTS latexheader.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output latexheader.tex --template /Users/rc/Library/R/3.6/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --pdf-engine pdflatex --include-in-header totp_preamble.tex --variable graphics=yes --variable 'geometry:margin=1in' --variable 'compact-title:yes' 


processing file: latexheader.Rmd
output file: latexheader.knit.md

tlmgr search --file --global '/cryptocode.sty'

tlmgr: Remote repository is newer than local (2018 < 2019)
Cross release updates are only supported with
  update-tlmgr-latest(.sh/.exe) --update
Please see https://tug.org/texlive/upgrade.html for details.
! LaTeX Error: File `cryptocode.sty' not found.

! Emergency stop.
 

Error: Failed to compile latexheader.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See latexheader.log for more info.
In addition: Warning message:
In system2("tlmgr", args, ...) :
  running command ''tlmgr' search --file --global '/cryptocode.sty'' had status 1
Execution halted

I'll report back when I'm finished with the update.

If you are still on 2018, this would explain the inability to find [pgf.sty] .

Thank you. I already have MacTeX 2019 installed with everything up to date. And pgf.sty was already installed (as was cryptocode). So in my case moving to 2019 wasn't applicable or a solution. My pure LaTeX version of what I'm trying to migrate to RMarkdown works just fine, without trying to install packages.

You are correct that the cryptocode package is the thing that loads TiKZ, which in turn loads pgf. So my temporary solution was to not load cryptocode.sty at all, as I only needed it for one macro, which I redefined myself. So I have a work-around, but I'm still confused about why tlmgr thought that pgf was not installed.

So, I re-install MacTex, using the package installer. As usual, it's a slow, 20-minute download from Tug and the install takes about 10 minutes after that.

Yeah. I fully sympathize. I go through this every year in June or July.

My guess is that the problem is buried somewhere deep in pandoc, and there is just so far down this rabbit whole I'm willing to do.

1 Like

Glad you found a way. Because the terminal command

tlmgr search --file --global '/cryptocode.sty'

I'm inclined to think that LaTeX configuration is responsible at the end of the day, since the terminal doesn't pipe through pandoc.

Sort of like owning a Formula One race car, sometimes -- it goes really fast, bit it's high maintenance.

I know why the terminal command failed. It failed (correctly) on a permission error. What I don't know is why the terminal command was ever called. And I do think that that was pandoc.

I'm still curious about my original question, but I've been able to successfully work around it in this particular case.