I am trying to get some greek characters into the rownames of a table in rmarkdown knitting to pdf. I am using knitr, pander and MacTex. It seems like pander accepts some unicode characters but not others. When i use \u2013 (emdash) it works.
---
title: "Untitled"
author: "Llew Mills"
date: "24 June 2016"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.width=12, fig.height=8, fig.path='Figs/',
echo=FALSE, warning=FALSE, message=FALSE, dev = 'pdf')
```
``` {r stuff}
library(pander)
m1 <- rnorm(12,8,3)
m2 <- rnorm(12,4,5)
m3 <- rnorm(12,5,1)
mR <- rep("gene \u2013", 12)
df <- data.frame(mR,m1,m2,m3)
pander(df, justify = "right", style = "simple")
```
However if instead of that unicode character I use the unicode for gamma \u03B3 i get the error message ! Package inputenc Error: Unicode char \u8:γ not set up for use with LaTeX.
Does anyone know if there is a list of unicode characters that are compatible with LaTex, or alternatively a way to get latex to accept all unicode characters?
I think it's an issue with your locale/console settings and not really a pander issue, as this seems to work fine in a console with support for Unicode chars:
But pdflatex indeed sucks with Unicode chars, you might better try eg xelatex.
PS: sorry for posting this comment as an answer, but this was the easiest way to add an image
Related
The alternative is to use Roman numerals, for which a package is
available. I am using the LaTeX catchfile package and the \input{}
command to associate a title in a set of TITLE files with \section{}
commands in a set of DOCUMENT files.
I would like to have a file of catchfile definitions, with records
such as:
\CatchFileDef{\t-001}{title-001.tex}{}
\CatchFileDef{\t-002}{title-002.tex}{}
\CatchFileDef{\t-003}{title-003.tex}{}
But LaTeX does not allow numerical labels such as "\title-003".
Roman numerals are workable:
\CatchFileDef{\ti}{title-001.tex}{}
\CatchFileDef{\tii}{title-002.tex}{}
\CatchFileDef{\tiii}{title-003.tex}{}
but are ugly in comparison with:
\CatchFileDef{\tzerozeroone}{title-001.tex}{}
\CatchFileDef{\tzerozerotwo}{title-002.tex}{}
\CatchFileDef{\tzerozerothree}{title-003.tex}{}
On possibility to convert digits into their corresponding words is the numspell package:
\documentclass{article}
\usepackage{numspell}
\usepackage{pgffor}
\begin{document}
\foreach \x in {0,...,9}{
\foreach \y in {0,...,9}{
\foreach \z in {0,...,9}{
\x\y\z : \numspell{\x}\numspell{\y}\numspell{\z}
}}}
\end{document}
In an hour or two, using Emacs, I created a look up table which solved the problem. The English spelling of Arabic numerals appears to be less prone to error than is the use of Roman numerals.
This question already has answers here:
Germany quotation marks broken in tinytex/rmarkdown - even when using package `csquotes`
(2 answers)
Closed 2 years ago.
What I want:
I'd like to have German quotation marks in my TeX-PDF via rmarkdown and tinytex on MacOS (Catalina). See for example:
The problem:
It used to work following the guidelines as proposed here. But now, it stopped working. I only get English quotation marks, but not German ones:
What I tried, without success:
I updated my R packages
I updated TeX packages
I checked that the TeX package "csquotes" is installed
I changed the language from "de" to "de-De"
R-Code:
---
title: "German quotation marks"
output: pdf_document
---
"Das ist sehr schön", sagte sie.
The R Markdown package used to provide its own template, which used csquotes.sty. Nowadays the default pandoc template is used, which does not seem to use csquotes. You can call for it manually, though:
---
title: "German quotation marks"
output:
pdf_document:
keep_tex: yes
lang: de-DE
header-includes:
- \usepackage{csquotes}
---
"Das ist sehr schön", sagte sie.
Result:
Edit: Problem solved. It turns out I had some missing packages, and rmarkdown doesn't give a very good error message for this. If anyone else has this problem, you have to use the "keep_tex" option in the yaml. You can then see in the tex file all of the required tex packages.
I'm on Windows 7. I have the latest Miktex, R, rmarkdown, rstudio.
When I try to produce a new rmarkdown document and output to pdf, it fails.
It seems to be a font encoding which is missing. I've tried searching the internet for omxenc.dfu and uenc.dfu files, but it turned up nothing. I was going to post this in the latex exchagne, but I can produce latex documents fine without using rmarkdown.
Any help would be great!
Here's the rmarkdown
---
title: "Untitled"
author: "Triceraflops"
date: "19 März 2018"
output: pdf_document
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for
authoring HTML, PDF, and MS Word documents. For more details on using R
Markdown see <http://rmarkdown.rstudio.com>.
And here's the output of the R Markdown console
"C:/Users/triceraflops/Documents/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS missing-encoding.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output missing-encoding.tex --template "C:\Users\triceraflops\Documents\R\win-library\3.4\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"
output file: missing-encoding.knit.md
Output created: missing-encoding.pdf
Error in tools::file_path_as_absolute(output_file) :
file 'missing-encoding.pdf' does not exist
Calls: <Anonymous> -> <Anonymous>
In addition: Warning messages:
1: running command '"pdflatex" -halt-on-error -interaction=batchmode
"missing-encoding.tex"' had status 1
2: In readLines(logfile) :
incomplete final line found on 'missing-encoding.log'
Execution halted
And finally here's the last part of the output log file where it fails.
Now handling font encoding OMX ...
... no UTF-8 mapping file for font encoding OMX
Now handling font encoding U ...
... no UTF-8 mapping file for font encoding U
defining Unicode char U+00A9 (decimal 169)
defining Unicode char U+00AA (decimal 170)
defining Unicode char U+00AE (decimal 174)
defining Unicode char U+00BA (decimal 186)
defining Unicode char U+02C6 (decimal 710)
defining Unicode char U+02DC (decimal 732)
defining Unicode char U+200C (decimal 8204)
defining Unicode char U+2026 (decimal 8230)
defining Unicode char U+2122 (decimal 8482)
defining Unicode char U+2423 (decimal 9251)
Does R Markdown have a similar construct to LaTex's "newcommand"? I would like to be able to define things like \var to be \mathrm{Var} to avoid the extra typing in math mode. If not, what do people do to reduce repetition in typesetting equations in markdown?
Use \newcommand{\var}{\mathrm{Var}} exactly like you would in LaTeX:
---
title: "Untitled"
author: "An Author"
date: "January 15, 2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\newcommand{\var}{\mathrm{Var}}
## R Markdown
This is an R Markdown document. $\var+2$ Markdown is a simple formatting syntax for
authoring HTML, PDF, and MS Word documents. For more details on using R Markdown
see <http://rmarkdown.rstudio.com>.
Note that in order for it to be processed correctly in the output, you'll have to use $...$.
I'm using bookdown and need to have something that works consistently across pdf, html, and docx output. None of the above solutions worked for my case. Here is the hack I settled on:
preamble.tex
\usepackage{amsthm}
\DeclareMathOperator*{\argmin}{argmin}
\newcommand{\var}{\mathrm{Var}}
YAML Header:
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
toc: no
bookdown::word_document2:
reference_docx: template.docx
bookdown::gitbook:
split_by: none
documentclass: article
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
---
<!--- For HTML Only --->
`r if (!knitr:::is_latex_output()) '
$\\DeclareMathOperator*{\\argmin}{argmin}$
$\\newcommand{\\var}{\\mathrm{Var}}$
'`
<!--- For DOCX Only --->
`r if (!knitr:::is_latex_output() & !knitr:::is_html_output()) '
\\DeclareMathOperator*{\\argmin}{argmin}
\\newcommand{\\var}{\\mathrm{Var}}
'`
# Prerequisites
This is a _sample_ book written in **Markdown**.
To get around the requirement of \DeclareMathOperator needing to be in the preamble, use \operatorname:
\newcommand{\Var}{\operatorname{Var}}
$\Var(X)$
(\operatorname handles spacing better than \mathrm)
To use \newcommand properly in HTML output, your LaTeX should be in-line with single $ or in double $$. This applies to environments like \begin{align*} too.
---
title: "Test"
author: "qwr"
date: "January 22, 2019"
output: html_document
---
\newcommand{\Var}{\operatorname{Var}}
$\Var(X)$
$$
\begin{align*}
\Var[Y] &= x \\
&= 3
\end{align*}
$$
I had issues with the above solution when outputting as a beamer presentation, particularly when using the equation mode ($$.$$ rather than $.$). Putting the new commands in a separate file fixed the issue for me.
---
title: Title
author: Author
date: "8/22/2018"
output:
beamer_presentation:
includes:
in_header: preamble.tex
---
Where preamble.tex contains your user defined command(s)
\newcommand{\var}{\mathrm{Var}}
Then you can use the command both inline ($\var$) and in equation mode ($$\var$$)
You can also put other stuff in preamble.tex like frame numbering, etc.
I am trying to edit the latex file generated by RStudio but it seems the file generated by RStudio does not compile out of the box.
Here is the template rmarkdown (edited a little as I want to show code in my slides)
---
title: "Untitled"
author: "SN248"
date: "April 17, 2016"
output:
beamer_presentation:
keep_tex: true
theme: "CambridgeUS"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
Some code
```{r eval=FALSE, echo=TRUE}
install.packages("mypackage")
library(mypackage)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=TRUE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Note, that I added keep_tex: true to get the intermediate tex file, the generated tex file is pasted below:
\begin{frame}[fragile]{R Markdown}
This is an R Markdown document. Markdown is a simple formatting syntax
for authoring HTML, PDF, and MS Word documents. For more details on
using R Markdown see \url{http://rmarkdown.rstudio.com}.
Some code
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{install.packages}\NormalTok{(}\StringTok{"mypackage"}\NormalTok{)}
\KeywordTok{library}\NormalTok{(mypackage)}
\end{Highlighting}
\end{Shaded}
\end{frame}
\begin{frame}[fragile]{Including Plots}
You can also embed plots, for example:
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{plot}\NormalTok{(pressure)}
\end{Highlighting}
\end{Shaded}
\includegraphics{Untitled_files/figure-beamer/pressure-1.pdf}
Note that the \texttt{echo\ =\ FALSE} parameter was added to the code
chunk to prevent printing of the R code that generated the plot.
\end{frame}
I noticed that the generated tex file does not compile out of the box. So, I added the necessary bits (i.e., package listings for code highlighting) so that it compiles
\documentclass[hyperref={pdfpagelabels=false}]{beamer}
\usepackage{lmodern}
\usepackage{listings}
\usetheme{CambridgeUS}
\begin{document}
...
\end{document}
I am still not able to compile this tex file as the bit begin{Shaded} does not compile, I get the following error:
LaTeX Error: Environment Shaded undefined
My question is, how to generate tex file from RStudio which compiles out of the box. If not, which packages should I use to compile the tex code (especially to show code with highlighting) shown below
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{install.packages}\NormalTok{(}\StringTok{"mypackage"}\NormalTok{)}
\KeywordTok{library}\NormalTok{(mypackage)}
\end{Highlighting}
\end{Shaded}
Just to give some context, I am trying to compile the tex file so that I can add sections and subsections in the tex code, I am not sure how to do that in the rmarkdown file.
Thank you very much for your help.
SN248
I can see that you are using RMarkdown and want to generate a stand alone .tex file that can be compiled without knitr.
I do the same thing with SWeave. As SWeave is a latex document with R code, you can easily compile it once SWeave is run and figures are created.
For Example, I have created this document in RStudio and compile it in Rstudio.
\documentclass{article}
\title{Best title ever}
\author{XTriMa, PhD}
\begin{document}
\maketitle
\tableofcontents
\section{Method} \label{intro}
Let me make two vectors with random numbers and plot them.
<<>>=
x<-runif(100)
y <- x^(sin(x))
plot(x, y)
#
\end{document}
My folder looks like this
figure test.log test.Rnw test.tex
test-concordance.tex test.pdf test.synctex.gz test.toc
Now if you run
$pdflatex test.tex
It works as you intended. However command "latex" will not work as it can not work with pdf graphics in figures.
Advantage: I can work with R and latex very efficiently and get rid of intermediate software/clients like RStudio and Sweav.