title: Tex Live - How to use in R Studio
body: <p>I need to compile a PDF from my code. I first tried by installing tinytex. Unfortunately, tinytex couldn't compile and the error I got was "pdflatex not found". I looked through the bin directory of tinytex folder and there was no pdflatex.exe there.</p>
  
  <p>So, I uninstalled tinytex, and instead have now installed the full Tex Live 2020 from tug.org. Now, I can see that there is a pdflatex.exe in the bin directory of tex live.</p>
  
  <p>I am not able to figure out how to use tex live in R Studio. How do I link it to R, and what functions/ commands do I enter in R console for compilation. I have not been able to find anything related in the instructions in the tug site/ generally on Google.</p>
  
  <p>I am on Windows 10.</p>
  
  <p>Appreciate any help.</p>
  
  <p>Thanks.    </p>
  
  <p><strong>Update:</strong></p>
  
  <p>I set up the path to the bin directory of texlive in Windows-Advanced System Settings, and tried to compile a PDF from markdown again. Unfortunately, while the texlive path is now captured by R environment, compilation still does not work. The log created reads as follows:</p>
  
  <pre><code>! fmtutil: fmtutil is using the following fmtutil.cnf files (in precedence order):
  ! fmtutil: fmtutil is using the following fmtutil.cnf file for writing changes:
  ! fmtutil:   c:/users/h a/.texlive2020/texmf-config/web2c/fmtutil.cnf
  ! fmtutil [INFO]: writing formats under c:/users/h a/.texlive2020/texmf-var/web2c
  ! fmtutil [INFO]: did not find entry for byfmt=pdflatex, skipped
  ! fmtutil [INFO]: total formats: 0
  ! fmtutil [INFO]: exiting with status 0
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! kpathsea: Running mktexfmt pdflatex.fmt
  
  ! The command name is C:\texlive\2020\bin\win32\mktexfmt 
  </code></pre>
  
  <p>The runtime log in RStudio is as follows:</p>
  
  <pre><code>! fmtutil: fmtutil is using the following fmtutil.cnf files (in precedence order):
  ! fmtutil: fmtutil is using the following fmtutil.cnf file for writing changes:
  ! fmtutil:   c:/users/h a/.texlive2020/texmf-config/web2c/fmtutil.cnf
  ! fmtutil [INFO]: writing formats under c:/users/h a/.texlive2020/texmf-var/web2c
  ! fmtutil [INFO]: did not find entry for byfmt=pdflatex, skipped
  ! fmtutil [INFO]: total formats: 0
  ! fmtutil [INFO]: exiting with status 0
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! fmtutil: fmtutil is using the following fmtutil.cnf file for writing changes:
  ! fmtutil:   c:/users/h a/.texlive2020/texmf-config/web2c/fmtutil.cnf
  ! fmtutil [INFO]: writing formats under c:/users/h a/.texlive2020/texmf-var/web2c
  ! fmtutil [INFO]: did not find entry for byfmt=pdflatex, skipped
  ! fmtutil [INFO]: total formats: 0
  ! fmtutil [INFO]: exiting with status 0
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! fmtutil:   c:/users/h a/.texlive2020/texmf-config/web2c/fmtutil.cnf
  ! fmtutil [INFO]: writing formats under c:/users/h a/.texlive2020/texmf-var/web2c
  ! fmtutil [INFO]: did not find entry for byfmt=pdflatex, skipped
  ! fmtutil [INFO]: total formats: 0
  ! fmtutil [INFO]: exiting with status 0
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! fmtutil [INFO]: writing formats under c:/users/h a/.texlive2020/texmf-var/web2c
  ! fmtutil [INFO]: did not find entry for byfmt=pdflatex, skipped
  ! fmtutil [INFO]: total formats: 0
  ! fmtutil [INFO]: exiting with status 0
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! fmtutil [INFO]: did not find entry for byfmt=pdflatex, skipped
  ! fmtutil [INFO]: total formats: 0
  ! fmtutil [INFO]: exiting with status 0
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! fmtutil [INFO]: total formats: 0
  ! fmtutil [INFO]: exiting with status 0
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! fmtutil [INFO]: exiting with status 0
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! Running the command C:\texlive\2020\bin\win32\fmtutil-user.exe
  
  ! kpathsea: Running mktexfmt pdflatex.fmt
  
  ! The command name is C:\texlive\2020\bin\win32\mktexfmt
  
  Error: LaTeX failed to compile a.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See a.log for more info.
  Execution halted
  </code></pre>
  
  <p><strong>Update 2</strong></p>
  
  <p>Ok. So I don't know how, but fmtutil -sys -all did the trick. Looks like bad installation. Not sure. Able to make the pdfs now, but code text wrapping is so tacky. Used knittr options setting, but it fails at places.</p>