Unable to knit pdf, receiving tinytex error with failed tlmgr search - r

Using
- RStudio Version 1.2.1335
- R version
I am able to knit the R markdown file to HTML and Word, but fail with PDF. I keep receiving the same error message telling me that it is unable to locate the "Palatino" font.
The file is successfully processed (all chunks run).
I have tried re-installing and resetting Miktex and Tinytex, as well as R itself. I am pretty new to this, so I am unsure how to proceed. Should I install TexLive?
This is the header of the file I am trying to run:
--
title: "Assignment 1"
fontsize: 11pt
header-includes: \usepackage{fancyhdr}
geometry: "left=.5in,right=.5in,top=1in,bottom=1in"
output:
pdf_document:
latex_engine: xelatex
md_extensions: +inline_notes
number_sections: no
word_document: default
mathfont: Palatino
monofont: Courier
mainfont: Palatino
sansfont: Helvetica
subtitle: \textbf{Due Wednesday, 11 September 2019 (beginning of class)}
fontfamily: mathpazo
---
And this is the error I continue to receive, without rendering of a PDF file:
output file: PBHLTH252-Assignment-1_post.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS PBHLTH252-Assignment-1_post.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+inline_notes --output PBHLTH252-Assignment-1_post.tex --template "C:\Users\UYser\Documents\R\win-library\3.6\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --pdf-engine xelatex --variable graphics=yes --lua-filter "C:/Users/UYser/Documents/R/win-library/3.6/rmarkdown/rmd/lua/pagebreak.lua" --variable "compact-title:yes"
tlmgr search --file --global "/Palatino."
! Package fontspec Error: The font "Palatino" cannot be found.
! kpathsea: Running mktextfm Palatino
! The command name is C:\Users\UYser\AppData\Roaming\TinyTeX\bin\win32\mktextfm
! kpathsea: Appending font creation commands to missfont.log.
Error: Failed to compile PBHLTH252-Assignment-1_post.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See PBHLTH252-Assignment-1_post.log for more info.
In addition: Warning message:
In parse_packages(logfile, quiet = c(TRUE, FALSE, FALSE)) :
Failed to find a package that contains Palatino.
Execution halted
I tried following this thread, https://github.com/yihui/tinytex/issues/81, with no success:
Running this suggested code
tinytex::tlmgr_search("/Palatino[.](tfm|afm|mf|otf)")
results in:
package repository http://ctan.math.illinois.edu/systems/texlive/tlnet (not verified: gpg unavailable)
Running this one
tinytex::tlmgr_install("multirow")
gives me the following error:
tlmgr install Palatino.
'afm' is not recognized as an internal or external command,
operable program or batch file.
tlmgr update --self
tlmgr.pl: package repository http://ctan.math.illinois.edu/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr.pl: no self-updates for tlmgr available.
tlmgr install Palatino.
'afm' is not recognized as an internal or external command,
operable program or batch file.
Any help is appreciated!

It looks like you got the template from a Mac user while you are on Windows. The fontnames are different there. Instead of Palatino you could use Palatino Linotype. I am not sure if Helvetica and Courier will work. If not, you could use Arial and Courier New.
However, that sounds like a rather ugly font combination. Palatino is a very fine font, but neither Helvertica/Arial nor Courier (New) fit well. Besides, I don't think that normal Palatino fonts are set-up to be used for math. You could use Asana Math instead, which comes with MikTeX/TinyTeX.

I used to have similar problems. My solution sounds naive (or silly), but it worked perfectly for me. Instead of debugging, in RStudio:
install rticles package
start a new R Markdown file
choose one of journal article templates such as PNAS Journal Article, Springer Journal Article, or Elsevier Journal Article...
knit the template.
Then, it will be trying to automatically install missing LaTeX packages...
You may want to try a few journal templates. It worked for me, and I hope this will solve your problem as well. Enjoy it!

Related

Running R tikzDevice with tinytex: Help troubleshooting `! LaTeX Error: File `tikz.sty' not found`

I am trying to generate a tikz plot using R/ggplot2 via the tikzDevice package. I've had to wade through many errors as I figured out how to install R and tinytex on my docker image, but I've run into the following error which has simply stumped me.
When I run the code that generates my plot, this is the error I get:
Error in getMetricsFromLatex(TeXMetrics, verbose = verbose) :
TeX was unable to calculate metrics for:
\char77
Run the following commands for diagnosis:
tikzTest()
tikzTest("\\char77")
Common reasons for failure include:
* The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
* The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.
The TeX and log files used for the calculation can help diagnose the
problem. If these files are missing, rerun the plot and make sure to
keep the R session open.
TeX file: tikzStringWidthCalc.tex
Log file: tikzStringWidthCalc.log
Calls: <Anonymous> ... descentDetails.text -> grid.Call -> <Anonymous> -> getMetricsFromLatex
Execution halted
And the output of tikzDevice::tikzTest() is as follows:
Active compiler:
/home/jovyan/.TinyTeX/bin/x86_64-linux/pdflatex
pdfTeX 3.141592653-2.6-1.40.23 (TeX Live 2021)
kpathsea version 6.3.3
Measuring dimensions of: A
Running command: '/home/jovyan/.TinyTeX/bin/x86_64-linux/pdflatex' -interaction=batchmode -halt-on-error -output-directory '/tmp/RtmpLhckyy/tikzDevice29a5e00452e' 'tikzStringWidthCalc.tex'
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (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{tikz}
\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.23 (TeX Live 2021) (preloaded format=pdflatex 2022.3.16) 16 MAR 2022 23:30
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**tikzStringWidthCalc.tex
(/tmp/RtmpLhckyy/tikzDevice29a5e00452e/tikzStringWidthCalc.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-02-24> (/home/jovyan/.TinyTeX/texmf-dist/tex/latex/base/article.cls
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class
(/home/jovyan/.TinyTeX/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2021/10/04 v1.4n Standard LaTeX file (size option)
)
\c#part=\count185
\c#section=\count186
\c#subsection=\count187
\c#subsubsection=\count188
\c#paragraph=\count189
\c#subparagraph=\count190
\c#figure=\count191
\c#table=\count192
\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:
235 strings out of 480236
3181 string characters out of 5895451
287032 words of memory out of 5000000
18278 multiletter control sequences out of 15000+600000
469259 words of font info for 28 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
34i,0n,38p,138b,36s stack positions out of 5000i,500n,10000p,200000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
As you can see I am using tinytex, but I have installed the recommended packages for this setup as described in the tinytex documentation (i.e., I've already ran tlmgr install pgf preview xcolor).
I've read every post I could possibly find on this subject but am coming up empty. Any tips to help me troubleshoot this problem would be greatly appreciated.
it would help if you had a minimum reproducible example to check on our end.
This said, the message LaTeX Error: File `tikz.sty' not found. suggests that a possible solution would be for you to throw:
library(tinytex)
tlmgr_search('/tikz.sty') # search for tikz.sty
tlmgr_install('pgf') # install the psnfss package
tlmgr_update() # update everything
since tlmgr_search('/tikz.sty') gives you
tlmgr search --file --global "/tikz.sty"
tlmgr.pl: package repository https://ctan.mirror.garr.it/mirrors/ctan/systems/texlive/tlnet
pgf:
texmf-dist/tex/latex/pgf/frontendlayer/tikz.sty
but then you already installed pgf... that's where tikz.sty lives.

tinytex in r: Font fplmri at 600 not found after tex live 2019 update, how to fix it?

I am using R markdown with tinytex to write my thesis. Some of the templates I'm using has used the mathpazo package. After the Tex Live 2019 update, the tinytex on my computer couldn't use mathpazo: it looks for "/fplmri[.](tfm|afm|mf|otf)", then installs mathpazo, finds out mathpazo is already installed, looks for "/fplmri[.](tfm|afm|mf|otf)" again, and can't find it, then stops.
This problem arises whenever the mathpazo package is used and math symbols are written.
I tried to compare the local mathpazo with the index online, the local copy seems complete to me. I tried to remove mathpazo and reinstall it using tinytex. That did not work either. I tried to use lualatex and xelatex instead of pdfTeX. They did not help/
This is the minimum sample I've written. There's basically nothing except I added mathpazo and wrote a math symbol...
(I have one backtick omitted in the sample below because StackOverflow uses backticks to decide which lines are in the code chunk. I don't know how to keep the backtick for the setup chunk and it still looks good)
---
title: "mini sample"
output: pdf_document
header-includes:
- \usepackage{mathpazo}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
``
$\epsilon$
The errors messages are as follow
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/W32TeX) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
name = fplmri, rootname = fplmri, pointsize =
mktexmf: empty or non-existent rootfile!
Cannot find font fplmri in map file(s).
kpathsea: Running mktexmf fplmri.mf
The command name is C:\Users\yangy\AppData\Roaming\TinyTeX\bin\win32\mktexmf
Cannot find fplmri.mf .
I try ps2pk --> gsftopk --> ttf2pk --> hbf2gf.
ps2pk cannot be used.
I try gsftopk.
gsftopk.exe fplmri 600
gsftopk cannot be used.
Next I try ttf2pk.
ttf2pk.exe -q fplmri 600
ttf2pk failed.
Finally I try hbf2gf.
hbf2gf.exe -q -p fplmri 600
All trials failed.
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 fplmri
The command name is C:\Users\yangy\AppData\Roaming\TinyTeX\bin\win32\mktexpk
kpathsea: Appending font creation commands to missfont.log.
tlmgr search --file --global "/fplmri[.](tfm|afm|mf|otf)"
Trying to automatically install missing LaTeX packages...
tlmgr install mathpazo
tlmgr.pl: package repository http://mirror.aarnet.edu.au/pub/CTAN/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr.pl install: package already present: mathpazo
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/W32TeX) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
name = fplmri, rootname = fplmri, pointsize =
mktexmf: empty or non-existent rootfile!
Cannot find font fplmri in map file(s).
kpathsea: Running mktexmf fplmri.mf
The command name is C:\Users\yangy\AppData\Roaming\TinyTeX\bin\win32\mktexmf
Cannot find fplmri.mf .
I try ps2pk --> gsftopk --> ttf2pk --> hbf2gf.
ps2pk cannot be used.
I try gsftopk.
gsftopk.exe fplmri 600
gsftopk cannot be used.
Next I try ttf2pk.
ttf2pk.exe -q fplmri 600
ttf2pk failed.
Finally I try hbf2gf.
hbf2gf.exe -q -p fplmri 600
All trials failed.
kpathsea: Running mktexpk --mfmode / --bdpi 600 --mag 1+0/600 --dpi 600 fplmri
The command name is C:\Users\yangy\AppData\Roaming\TinyTeX\bin\win32\mktexpk
kpathse
The last few lines in the log file shows
!pdfTeX error: pdflatex.exe (file fplmri): Font fplmri at 600 not found
Is there anything I can do to fix it?
Just ran into a similar issue I was able to fix with:
install.packages("knitr")
install.packages("rticles")
install.packages("tinytex")
tinytex::reinstall_tinytex()

Missing XeLateX when trying to use NBconvert (to PDF) on Windows

Jupyter's default export to PDF, like the command-line NBconvert tool, are telling me that I can't convert my notebook to PDF because the PDF conversion goes via xelatex. The error message refers me to this help page, so I installed MiKTeX. I have a xelatex folder in AppData\Local\Programs\MiKTeX 2.9\tex, but I'm not sure what exactly I should add to my PATH.
If it's helpful, here is some of the code in nbconvert's pdf.py:
def run_latex(self, filename):
"""Run xelatex self.latex_count times."""
def log_error(command, out):
self.log.critical(u"%s failed: %s\n%s", command[0], command, out)
return self.run_command(self.latex_command, filename,
self.latex_count, log_error)

Knitr2pdf does not work for.Rmd file, use rmarkdown::render()

In a previous question knitr2pdf eclipse : how to configure?, I tried to set up eclipse to work with knitr2pdf, Yihui Xie was kind enough to give me a very prompt answer . Now I'm stuck one step further.
here is my file
---
title: "knit2pdf test"
author: "cedric"
date: "27/10/2017"
output: pdf_document
---
```{r}
plot(rnorm(1:10))
```
When running this file, I get the following answer
knit2pdf(input= "C:/workspace/p/example_scripts/test_knit2pdf.Rmd")
processing file: C:/workspace/p/example_scripts/test_knit2pdf.Rmd
|................................ | 50%
ordinary text without R code
|.................................................................| 100%
label: unnamed-chunk-1
output file: test_knit2pdf.md
Error: running 'texi2dvi' on 'test_knit2pdf.md' failed
LaTeX errors:
! Emergency stop
*** (job aborted, no legal \end found)
! ==> Fatal error occurred, no output PDF file produced!
! ==> Fatal error occurred, no output PDF file produced!
In addition: Warning message:
running command '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\texify.exe" --quiet --pdf "test_knit2pdf.md" --max-iterations=20 -I "C:/Program Files/R/R-3.4.2/share/texmf/tex/latex" -I "C:/Program Files/R/R-3.4.2/share/texmf/bibtex/bst"' had status 1
I've tried to find questions reporting a similar problem, Using knit2pdf with Rmd files the answer was to try to use render instead of knit2pdf which is not what I want. This is not a problem with eclipse, but me failing to run the knit2pdf properly. Manually running the command knit2pdf("test_knit2pdf.Rmd") gets the same error. Again, maybe someone will have run into a similar problem and will be able to help me, is my file badly formed, have I missed something ?
To process a Rmd document using rmarkdown::render() the following steps are necessary
Install pandoc
Edit windows path, system environment variables, copy path to pandoc which is located there C:\Users\me\AppData\Local\Pandoc
Go to eclipse, Run > External Tools > External Tools Configurations
Click on wikitext + R document processing
In the dropdown menu, topright, named load Preset example, click the PDF using Rmarkdown, single steps. In 2/ produce output everything is configured to produce pdf as output.
I followed this excellent post https://www.r-bloggers.com/processing-rmarkdown-documents-with-eclipse-and-statet/ which helped me a lot.
Now I can run by clicking on the render_markdown button in eclipse and get
rmarkdown::render(input= "C:\\workspace\\p\\example_scripts\\testmd.Rmd", output_format= "pdf_document", output_file= "C:\\workspace\\p\\example_scripts\\testmd.pdf", encoding= "UTF-8")
processing file: testmd.Rmd
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-1
|.................................................................| 100%
ordinary text without R code
output file: testmd.knit.md
"C:/Users/me/AppData/Local/Pandoc/pandoc" +RTS -K512m -RTS testmd.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc2806c2b6c59.pdf --template "C:\PROGRA~1\R\R-34~1.2\library\RMARKD~1\rmd\latex\DEFAUL~3.TEX" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"
Output created: C:\workspace\p\example_scripts\testmd.pdf

Error in creating PDF file from R Markdown (Failed with error 43)

I am trying to create a PDF file using R Markdown. I received error 43 when I ran it. I tried create word file and HTML using R Markdown and it works fine. Only the PDF file does not work.
processing file: Test_New.Rmd
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-1 (with options)
List of 1
$ tidy: logi TRUE
|.................................................................| 100%
ordinary text without R code
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS
Test_New.utf8.md --to latex --from
markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --
output Test_New.pdf --template/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine /usr/local/bin/pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
output file: Test_New.knit.md
dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib
Referenced from: /usr/local/bin/pdflatex
Reason: image not found
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted
My code on R Markdown is the following.
---
title: "Test R Markdown"
author: "Sam Ng"
date: "September 1, 2017"
output:
pdf_document: default
html_document: default
word_document: default
---
# 1. R commands
Testing R commands
```{r,tidy=TRUE}
vector=c(1,2,3) # Create a new vector with three entries
max(vector) # Returns the maximum of a vector
min(vector) # Returns the minimum of a vector
```
I spent hours trying to resolve this. I installed Miktex, but was unable to get the packages directly from the package manager due to sitting behind a firewall at work. I finally was able to resolve this using the following steps:
Install Miktex
Create a folder to install Miktex packages, e.g. "C:\miktex_pkgs"
Go to the CTAN package archive and download the following .tar.lzma files:
-fancyvrb
-framed
-microtype
-miktex-zzdb1-2.9
-miktex-zzdb2-2.9
-mptopdf
-titling
-upquote
-url
Move the above .tar.lzma files to the "C:\miktex_pkgs" folder
Set your packages to download from the local repository: "C:\miktex_pkgs". To do this, go to:
"Miktex Settings" - this is an application
Click Packages
Change Package Repository to "C:\miktex_pkgs"
Go to "Miktex Package Manager" application and install the following packages by right-click, install:
List item
fancyvrb
framed
microtype
mptopdf
titling
upquote
url

Resources