Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the R markdown equivalent to LaTeX \texttt?

Tags:

markdown

r

latex

What is the R markdown equivalent to LaTeX \texttt?

With this MWE:

---
title: "A test"
author: "Alessandro"
date: "February 19, 2016"
output: pdf_document
---
```{r, echo=FALSE}
d<-data.frame(product_name=c('d','a','b','c')) # what to write here to get a typewriter font?
```

Product names are: `r sort(d$product_name)`.

I get this pdf:

enter image description here

While I would like to get the output from this .tex file

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}

\title{A test}
\author{Alessandro}

\begin{document}
\maketitle
Product names are: \texttt{a, b, c, d}.

\end{document}

enter image description here

like image 265
Alessandro Jacopson Avatar asked Feb 19 '16 22:02

Alessandro Jacopson


1 Answers

There is no native markdown way of doing this. But when the output format is pdf_document, the rmarkdown equivalent of \texttt is \texttt itself:

Product names are: \texttt{`r sort(d$product_name)`}.

Rmarkdown uses latex under the hood to compile to pdf, so most raw latex command should work as expected.

The same is true for html output :

Product names are: <tt>`r sort(d$product_name)`</tt>.
like image 52
scoa Avatar answered Oct 02 '22 09:10

scoa