askming
askming

Reputation: 1015

rmarkdown: pandoc: pdflatex not found

When I use the render{rmarkdown} to produce pdf file from .Rmd file on my Mac, an error message says

pandoc: pdflatex not found. pdflatex is needed for pdf output. Error: pandoc document conversion failed

However when I check with

pdflatex -v

I got

pdfTeX 3.1415926-2.4-1.40.13 (TeX Live 2012)
kpathsea version 6.1.0
Copyright 2012 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.5.10; using libpng 1.5.10
Compiled with zlib 1.2.7; using zlib 1.2.7
Compiled with xpdf version 3.03

The pdflatex is installed in my machine.

Can anyone help to tell how can I tell R where to find the pdflatex?

Many thanks!

Upvotes: 85

Views: 116543

Answers (8)

JL Peyret
JL Peyret

Reputation: 12144

This might help a bit, in case you don't have any Latex stuff installed yet.

env: macOS Sierra

  1. from https://tex.stackexchange.com/questions/307483/setting-up-basictex-homebrew

brew cask install basictex

  1. Now you need to figure out where pdflatex is hiding...
(env) jluc@texbin$ pwd
/Library/TeX/texbin
(env) jluc@texbin$ ls | grep pdfla
lrwxr-xr-x   1 user  wheel         6 13 Mar 10:36 pdflatex -> pdftex
(env) jluc@texbin$ ls /Library/TeX/texbin/pdflatex
lrwxr-xr-x  1 user  wheel  6 13 Mar 10:36 /Library/TeX/texbin/pdflatex -> pdftex

/Library/TeX/texbin/pdflatex is what we need, you can't refer to the pdftex symlink and/or use realpath because pandoc specifically wants to see pdflatex

  1. update your command line to point to the appropriate file.

pandoc myfile.md --to=pdf -t latex -o myfile.pdf --latex-engine=/Library/TeX/texbin/pdflatex

Upvotes: 17

Yves
Yves

Reputation: 107

I had a similar issue as I wasn't able to knit pdf file & solved it by installing & running tinitex packages using those commands in the console -- not the terminal

> install.packages("tinytex")

> tinytex::install_tinytex()

Upvotes: 2

LesGoBro
LesGoBro

Reputation: 1

For anyone else looking for a possible solution that don't involve adding or installing more packages, you can try this:

On your console:

set PDFLATEX=C:\Users\your_username\AppData\Local\Programs\MiKTeX\miktex\bin\x64\pdflatex

set MAKEINDEX=C:\Users\your_username\AppData\Local\Programs\MiKTeX\miktex\bin\x64\makeindex

This definition of environmental variables explicitly gives access to two of the executables necessary for generating a PDF for documentation.

Upvotes: 0

rustomax
rustomax

Reputation: 91

As of 2020 (MacOS Catalina) JL Peyret's answer is the most applicable. It should be slightly updated, since the --latex-engine option in pandoc has been deprecated in favor of the new --pdf-engine option:

$ brew install --cask basictex
$ pandoc myfile.md --to=pdf -t latex -o myfile.pdf --pdf-engine=/Library/TeX/texbin/pdflatex

Upvotes: 9

NighttimeDriver50000
NighttimeDriver50000

Reputation: 597

For those using Dunk's answer(For people using UBUNTU) who get a Font <font> at <size> not loadable: Metric (TFM) file not found. error, you also need:

sudo apt-get install texlive-fonts-recommended texlive-latex-recommended

This does unfortunately expand the size of the texlive install considerably, but it is still about half the size of a texlive-latex-extra install.

Upvotes: 25

Eric
Eric

Reputation: 3473

This answer on TexExchange might help.

I found I was having issues with pdflatex "missing" after I upgraded to OS X Mavericks (e.g. when checking package builds in RStudio I was getting an error tools::texi2pdf pdflatex missing message).

  1. Check that /usr/texbin exists.
    In terminal:

    cd /usr/texbin
    
  2. If "No such file or directory" then you will need to create a symbolic link to your installation's texbin. Mine was in /Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin
    In terminal:

    ln -s /Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin /usr/texbin
    
  3. In terminal, check the result of echo $PATH. Make sure that /usr/texbin is present. If it isn't present, then you need to add /usr/texbin to your PATH variable.

If you find yourself having to mess with the PATH variable, installing the latest version of MacTex might be a better solution.

UPDATE: OS X 10.11 El Capitan no longer allows writes to /usr so the latest version of MacTeX (2015) now writes a link to /Library/TeX/texbin instead of /usr/texbin on this system.

Upvotes: 36

Dunk
Dunk

Reputation: 1406

For people using ubuntu who get stranded here a better option (because it is 1/5 the size) is to use:

sudo apt-get install texlive-latex-base

Which I found via https://tex.stackexchange.com/a/128309

Upvotes: 72

dmeu
dmeu

Reputation: 4052

For people that get stranded here because the same error is showing up in their Linux distribution. Get pdflatex in e.g. Ubuntu by installing

sudo apt-get install texlive-latex-extra

its too much software, but needed for example by knitr (rmarkdown-pdf-compilation)

Upvotes: 15

Related Questions