0

This is a new user of R.

TikzDevice and ggplot2 have been installed in R Studio on MacBook Air.

An error occurred when trying to run the blue code in the screenshot.

I tried to use tikzTest() to check the error. The error was ! LaTeX Error: File 'tikz.sty' not found. The full output of tikzTest() is after the screenshot.

Just wondering how to fix this error?

P.s. I've installed MacTex but could not find tikz.sty in packages or updates.

Much appreciated if some solutions could be provided.

enter image description here

tikzTest()

Active compiler:
    /usr/local/bin/pdflatex
    pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2021)
    kpathsea version 6.3.3

Measuring dimensions of: A
Running command: '/usr/local/bin/pdflatex' -interaction=batchmode -halt-on-error -output-directory '/var/folders/1t/bjl9jstj6zl4gx_lxwkfvxqw0000gn/T//RtmpuavW7G/tikzDevice13b806c1dd9fc' 'tikzStringWidthCalc.tex'
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode

TeX was unable to calculate metrics for:

A

Contents of TeX file tikzStringWidthCalc.tex:

\documentclass[10pt]{article}

\usepackage{tikz}

\usepackage[active,tightpage,psfixbb]{preview}

\PreviewEnvironment{pgfpicture}

\setlength\PreviewBorder{0pt}

\usepackage[T1]{fontenc}

\usetikzlibrary{calc}

\batchmode
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt, outer sep=0pt, scale=1] (TeX) {A};
\path let \p1 = ($(TeX.east) - (TeX.west)$),
    \n1 = {veclen(\x1,\y1)} in (TeX.east) -- (TeX.west)
    node{ \typeout{tikzTeXWidth=\n1} };
\end{tikzpicture}
\end{document}

Contents of log file tikzStringWidthCalc.log:

This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=pdflatex 2021.4.30)  14 MAY 2021 22:22
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**tikzStringWidthCalc.tex

(/var/folders/1t/bjl9jstj6zl4gx_lxwkfvxqw0000gn/T//RtmpuavW7G/tikzDevice13b806c
1dd9fc/tikzStringWidthCalc.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18> (/Users/waterqi/Library/TinyTeX/texmf-dist/te
x/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/Users/waterqi/Library/TinyTeX/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2020/04/10 v1.4m Standard LaTeX file (size option)
)
\c@part=\count179
\c@section=\count180
\c@subsection=\count181
\c@subsubsection=\count182
\c@paragraph=\count183
\c@subparagraph=\count184
\c@figure=\count185
\c@table=\count186
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)

! LaTeX Error: File `tikz.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name: 
! Emergency stop.
<read *> 
         
l.4 ^^M
        
Here is how much of TeX's memory you used:
 220 strings out of 480954
 2975 string characters out of 5906449
 280518 words of memory out of 5000000
 17541 multiletter control sequences out of 15000+600000
 403430 words of font info for 27 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 44i,0n,50p,138b,36s stack positions out of 5000i,500n,10000p,200000b,80000s

!  ==> Fatal error occurred, no output PDF file produced!
> 
2
  • 1
    What exactly did you install in order to run LaTeX with RStudio. Sometimes we see it installing BasicTeX which is a minimalistic LaTeX installation, which I assume does not include tikz. – daleif May 14 at 12:58
  • Hi Daleif, I installed TinyTeX and TikzDevice in R studio. I also installed MacTex in a different location on the same laptop. – Water May 15 at 5:12
0

You have the TinyTeX¹ distribution which does not necessarily include everything. The documentation for TinyTeX offers this advice:

If you compile a LaTeX document and run into an error message like this:

! LaTeX Error: File `times.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

It basically indicates a missing LaTeX package. Do not panic.

It then suggests running tlmgr from a command line to identify the needed package:

tlmgr search --global --file "/tikz.sty"

(the / at the beginning of the file name is to make sure you don't get all the files that end with tikz.sty but rather just the one with that actual name). This will give you output that has the lines:

pgf:
    texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty

the pgf on the first line is the name of the package you need to install. You can now, at your command line, type:

tlmgr install pgf

Files will be downloaded and afterwards all should be well.


  1. Important note: MacTeX is a different installation than TinyTeX. MacTeX is a full TeX-live distribution which would include all the packages. It takes a while to download and a lot of space to install. TinyTeX is a subset of TeX-live which does not include all the packages and installs to a different location.
4
  • Thank you very much, Don. I tried tlmgr_search('/tikz.sty') and get tlmgr: package repository ctan.math.illinois.edu/systems/texlive/tlnet (not verified: gpg unavailable) pgf: texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty Then, I tried tlmgr install pgf, but get Error: unexpected symbol in "tlmgr install" Not sure how to solve this issue. Much appreciated if some solutions are available. – Water May 15 at 5:07
  • This answer might be helpful: tex.stackexchange.com/a/578950/202780 – Don Hosek May 15 at 5:15
  • It might also be the case that, if you installed tinytex more than a month or so ago, you're bumping into the annual texlive freeze. and you may need to update everything: try tlmgr update --self --all then tlmgr path add then fmtutil-sys --all – Don Hosek May 15 at 5:17
  • Thanks Don. The tex.stackexchange.com/a/578950/202780 works :) – Water May 15 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.