I'm trying to use the LaTeX package gensymb in my R markdown document (PDF output), but it seems to not work. These two examples work:
IN LaTeX as a .tex file compiled with PDFLaTeX:
\documentclass{article}[12pt]
\usepackage{gensymb}
\begin{document}
It is 90 \degree F outside.
\end{document}
As well as this one In RStudio as a .rmd file using knitr and pdfLaTeX:
header-includes:
output:
pdf_document:
fontsize: 12pt
geometry: margin=1in
---
It is 90 $^{\circ}$ F outside.
But the following does not compile in a .rmd file.
header-includes:
- \usepackage{gensymb}
output:
pdf_document:
fontsize: 12pt
geometry: margin=1in
---
It is 90 \degree F outside.
The error from R reports
tlmgr.pl: Local TeX Live (2019) is older than remote repository (2020).
Cross release updates are only supported with
update-tlmgr-latest(.sh/.exe) --update
See https://tug.org/texlive/upgrade.html for details.
! LaTeX Error: File `gensymb.sty' not found.
Any help is greatly appreciated!
The errors suggest that there are two distributions of TeX installed. One of them is not updated to the same version as the repository from which it is trying to get gensymb and therefore fails to download the package.
It is wise to only have one distribution installed to prevent errors or confusion like that.
Related
I cannot compile to a pdf-beamer from a very simple minimal example (below), with no packages.
I click - Knit - Knit to pdf
(Note this is not a duplicate of previous posts, because those all involved using Kable; I am not using it; fresh restart not calling any packages here)
I tried with and without classoption: table
Knit to html works just fine.
Restarted Rstudio; no improvement
---
title: "Untitled"
author: "Test"
date: "20 novembre 2018"
classoption: table
output:
beamer_presentation:
keep_tex: yes
---
# Test nothing
blah
```
Throws error: ! LaTeX Error: Option clash for package xcolor.
I want it to compile a beamer pdf slide show, of course.
I've put the log file here
My default.beamer (stored at /Users/yosemite/.pandoc/templates/default.beamer I think) is linked HERE
I used to be able to render images in r-markdown using a URL with the following code ![](https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark) but I get a file not found error ! LaTeX Error: File https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark' not found.
Am I missing packages? This code still works on some shiny apps published a few month ago.
Below the a working file r-markdown file:
---
title: "Test"
header-includes:
- \usepackage{graphicx}
output:
pdf_document:
latex_engine: xelatex
number_sections: yes
keep_tex: yes
classoption: article
papersize: A4
fontsize: 10pt
geometry: margin=0.9in
linestretch: 1.15
---
## R Markdown
![](https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark)
The LaTeX graphicx package does not include an http client, it is therefore not able to pull the image from the internet. However, a lot of the conversion work from Markdown to LaTeX is performed by pandoc, which can get this image. One just needs to tell pandoc to store all images locally by passing the --extract-media option. This allows LaTeX to find the images when it is invoked by RMarkdown.
---
output:
pdf_document:
pandoc_args: ["--extract-media", "."]
---
The above will store all images in the same directory as the Rmd file. The files will be named using SHA1 hashes, so you might want to use a separate directory for these files instead.
I am new to writing R packages. I'm trying to learn how to make a vignette for my package. I have created a vignettes folder with a file "getting-started.Rmd"
---
title: "WaterML Tutorial"
author: "Jiri Kadlec"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Introduction to the WaterML R package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
## Quick Start
This simple example shows how to get started with the <my R package>.
To build the vignette I use the command:
devtools::build_vignettes()
Then I run Rcmd.exe INSTALL my_package, and to view my vignette I run:
browseVignettes("my_package")
However I only see the vignettes in the html and source format:
As you see in the screenshot, there's no "pdf" option. How do I configure my .Rmd file to create my vignette in the pdf format?
In your header, you are telling R to output only an html vignette in line:
output: rmarkdown::html_vignette
If you want pdf, try:
output: pdf_document
According to R packages:
Output: this tells rmarkdown which output formatter to use. There are many options that are useful for regular reports (including html, pdf, slideshows, …) but rmarkdown::html_vignette has been specifically designed to work well inside packages. See ?rmarkdown::html_vignette for more details.
So you might have a few small problems using a raw pdf.
At this time, rmarkdown does not have a output: rmarkdown::pdf_vignette option
I'm using Rstudio to write an RMarkdown document that I turn into a PDF using MiKTeX on Windows through knitr and pandoc. LaTeX engine is xelatex.
My .Rmd file YAML header:
---
title: "My Title"
author: "Me"
geometry: margin=2cm
output:
pdf_document:
fig_caption: no
fig_height: 4
fig_width: 6
latex_engine: xelatex
html_document:
css: styles.css
keep_md: no
fontsize: 10pt
---
In the text I have
...parameter $\lambda=0.2$ with...
and I get "parameter = 0 2 with" -- both the lambda and even the dot are missing.
This line
mean of $\frac{1}{\lambda}=5$ of the
turns into
EDIT: When I try to add as an experiment (I'm on Windows)
mainfont: Arial
to the YAML header I get a pandoc error
! Undefined control sequence.
\fontspec_calc_scale:n ...ec_tmpb_dim }\fp_div:Nn
\l_fontspec_tmpa_fp {\l_fo...
l.18 \setmainfont{Arial}
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
UPDATE:
Running pdflatex report1.pdf produces a correct PDF.
RStudio runs "C:/Program Files/RStudio/bin/pandoc/pandoc" report1.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output report1.pdf --template "D:\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine xelatex
So it seems the elsewhere recommended engine "xelatex" produces faulty output, while "pdflatex" works. Unfortunately I forgot the reasons given by some sources incl. SO that I followed a few days ago when switching to xelatex, I only remember it was highly recommended to use that with knitr in RStudio rather than pdflatex.
I'm posting this answer to increase the visibility of #user1983395 's comment regarding this error.
I was facing the same error as OP. pdflatex just produced the mentioned error, and xelatex produced an error whenever there was a call to a math formula ( $X_i$ or $$X_i$$ ).
After running C:\Program Files\MiKTeX 2.9\miktex\bin\x64\updmap.exe I was able to generate a pdf both with pdflatex and xelatex. Please notice that you may need to run it as administrator.
I am using knitr, R markdown, and a custom LaTeX file to write a manuscript. The abstract is set as part of the YAML frontmatter. This works great, except that the results that I would like to include in the abstract are generated later in the document.
Having the abstract in the YAML makes some sense to me and I would prefer to keep it this way. Any thoughts on a way to have the abstract take advantage of calculations that happen later in the document?
A brief example:
---
title: 'How do I interpret R objects in YAML that are created in the document?'
author: Jeff Hollister
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
html_document: null
word_document: null
fontsize: 11pt
documentclass: article
abstract: This is a test. Is this `r mean(x)` working?
---
This is a test of outputing a pdf, with R code interpretted in the YAML front mater. Use case
for this would be a manuscript, with abstract as part of YAML, and some of the results in the
abstract being calculated in the body of the Rmd. For instance:
```{r}
x<-rnorm(100)
mn<-mean(x)
mn
```
It's not exactly YAML-related, and limited to latex, but maybe this helps. Sorry, the thread is in German, but maybe the code is clear enought.
You can pick items for the abstract as you create your report; the items are written out to a temporary file similar to method use in bibtex and biblatex, and merged to the start and end (for appendix) in a second step.
As a package, you can download it from here .
Requirements
Install R, knitr, and yaml:
sudo su -
apt-get install pandoc
apt-get install r
r
url <- "http://cran.us.r-project.org"
install.packages('knitr', repos=url)
install.packages('yaml', repos=url)
Create Variables
Separate the variables into a new file (e.g., v.yaml):
title: 'How do I interpret R objects in YAML that are created in the document?'
author: Jeff Hollister
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
html_document: null
word_document: null
fontsize: 11pt
documentclass: article
abstract: This is a test. Is this `r mean(x)` working?
Create Script
Create a script to load knitr, yaml, and the variables (e.g., knitr.sh), when given a file in Markdown format:
#!/bin/bash
R -e \
"library(knitr); library(yaml); v <- yaml.load_file('v.yaml'); knit('$1')"
Reference Variables
Use R statements (inline or otherwise) to reference the source document variables (document.md):
# `r v$title`
Author: `r v$author`
Run Script
Generate a knitr-processed Markdown file by running the script:
./knitr.sh document.md
View Output
The file document.txt (renaming is a problem left for the reader) should contain the following Markdown:
# How do I interpret R objects in YAML that are created in the document?
Jeff Hollister
Addendum
It is fairly trivial with shell script magick to insert the variables at the top of the generated file, should they be needed for processing by pandoc. If using YAML variables for pandoc's templates, I'd recommend skipping that route and using R variables instead.