Embedding fonts in html kitted R markdown Presentation - rstudio

When I create a html Presentation with slidy (Rmarkdown and Rstudio) and knit it to an html, any latex equation are not displayed properly if I am offline.
How can I change that?
---
title: "MinimalExample"
author: "keks"
date: "9 9 2019"
output: slidy_presentation
---
## R Markdown
$\pi = \frac{ a }{ b }$
```{r}
plot(seq(1,19))
```
Here is a minimal example, where the $xyz$ Equation is only properly shown, if I am online.

Related

How do I format ${date} in Pandoc HTML output?

I have a LaTeX document that I convert to HTML using Pandoc. My template references the $date$ variable like so:
$if(date)$
<p>$date$</p>
$endif$
As usual, the value of $date$ is the ISO formatted date (e.g., 2022-06-17 for today). I want to format it so that it has a human-readable format, so that I can get this output:
<p>17 Jun 2022</p>
Usually, one can achieve this using format strings (for the above example: %d %b %Y). Is there a way to do that for the Pandoc's output?
A simple Lua filter can achieve this.
The following filter code is adapted from Setting the date in the metadata from the Pandoc documentation.
-- filters/date-format.lua
function Meta(meta)
if meta.date then
local format = "(%d+)-(%d+)-(%d+)"
local y, m, d = pandoc.utils.stringify(meta.date):match(format)
local date = os.time({
year = y,
month = m,
day = d,
})
local date_string = os.date("%d %b %Y", date)
meta.date = pandoc.Str(date_string)
return meta
end
end
---
# test.md
title: My Title
date: 2022-06-18
---
<!-- templates/date.html -->
$if(date)$
<p>$date$</p>
$endif$
Compile with the command pandoc --data-dir=. --template=date --lua-filter=date-format.lua test.md -o test.html.
The output should be <p>18 Jun 2022</p>.

How to insert two images in the same line, one with left one with right alignment

I have two same size images, and I would like to insert in for knitting to a PDF document, one with left one with right alignment.
I have used
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Testing
![](meme.jpg){width=5%, align="left"} ![](meme.jpg){width=5%,align="right"}
but it does not seem to work.
What am I doing wrong?
Markdown does not include alignment but you can use LaTeX's \hfill:
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Testing
![](meme.jpg){width=5%} \hfill ![](meme.jpg){width=5%}

How to display ggplotly plots with dynamically created tabs and for-loops?

I have R markdown document and I want to dynamically create tabs with ggplotly graphics inside them
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(ggplot2)
library(plotly)
```
```{r}
fig=ggplot(cars)+geom_point(aes(speed, dist))
```
# level 1
## level 2{.tabset .tabset-pills}
```{r echo=FALSE, results='asis'}
for (h in 1:3){
cat("###", h,'{-}', '\n\n')
ggplotly(fig)
cat( '\n\n')
}
```
I understand that it is different from normal ggplot graph and I looked at the solutions here: enter link description here but It did not work for me
Following this post this can be achieved like so:
Edit: Following this post I added two functions to pass the fig.width and fig.height to ggplotly.
Edit 2: Added the code to additionally use plotly::subplots.
---
title: test
date: "20 5 2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(ggplot2)
library(plotly)
```
```{r, echo=FALSE}
# Get the current figure size in pixels:
get_w <- function() {
with(knitr::opts_current$get(c("fig.width", "dpi", "fig.retina")),
fig.width*dpi/fig.retina)
}
get_h <- function() {
with(knitr::opts_current$get(c("fig.height", "dpi", "fig.retina")),
fig.height*dpi/fig.retina)
}
```
```{r}
fig <- ggplot(cars) +
geom_point(aes(speed, dist))
```
# level 1
## level 2 {.tabset .tabset-pills}
```{r, include=FALSE}
htmltools::tagList(ggplotly(fig))
```
```{r echo=FALSE, results='asis', fig.width=4, fig.height=4}
fig <- ggplotly(fig, width = get_w(), height = get_h())
for (h in 1:3) {
cat("###", h, '{-}', '\n\n')
print(htmltools::tagList(plotly::subplot(fig, fig, nrows=2, heights = c(0.1, 0.9))))
cat( '\n\n')
}
```
found a solution from this link too, this doesn't call for HTML, just markdown.
---
date: "20 5 2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(ggplot2)
library(plotly)
```
```{r}
fig <- ggplot(cars) +
geom_point(aes(speed, dist))
```
## Results {.tabset}
### 1
We show a scatter plot in this section.
```{r}
ggplotly(fig)
```
### 2
We show the data in this tab.
```{r}
ggplotly(fig)
```

Change line spacing for RMD abstract?

Is it possible to change the line spacing for the abstract specified in my YAML header to single space, while leaving the rest of the document in double space? My YAML is below:
output: pdf_document
number_sections: true
title: |
| My Title
author:
- Me
header-includes:
- \usepackage{setspace}\doublespacing
- \usepackage{float}
abstract: "My abstract"
keywords: "My keywords"
date: "`r format(Sys.time(), '%B %d, %Y')`"
geometry: margin=1in
fontsize: 12pt
spacing: double
fig_caption: yes
indent: true
---
I've tried wrapping the abstract like so, but it did not work:
abstract:
- \usepackage{setspace}\singlespacing
"My abstract"
- \end{singlespacing}
The abstract is automatically wrapped, so it is enough to use \singlespacing before it:
---
output: pdf_document
number_sections: true
title: |
| My Title
author:
- Me
header-includes:
- \usepackage{setspace}\doublespacing
- \usepackage{float}
abstract: \singlespacing My abstract which has to be long enough to take multiple
lines otherwise one does not see the effect of single-spacing.
keywords: "My keywords"
date: "`r format(Sys.time(), '%B %d, %Y')`"
geometry: margin=1in
fontsize: 12pt
fig_caption: yes
indent: 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>.
Result:

Compile an .Rnw with greek text to pdf

I tried it using the commented out code without success. Can somebody help?
\documentclass[a4paper]{article}
%\usepackage[english,greek]{babel}
%\latintext
\title{Sweave Example 1}
\author{George Dontas}
\begin{document}
\maketitle
In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:
%\greektext
Αυτό είναι κείμενο στα Ελληνικά
%\latintext
<<eval=TRUE,echo=TRUE,warning=FALSE,message=FALSE,error=FALSE>>=
data(airquality)
kruskal.test(Ozone ~ Month, data = airquality)
#
which shows that the location parameter of the Ozone distribution varies significantly from month to month. Finally we
include a boxplot of the data:
\begin{center}
<<eval=TRUE,echo=FALSE,results='hide',warning=FALSE,message=FALSE,error=FALSE>>=
boxplot(Ozone ~ Month, data = airquality)
#
\end{center}
\end{document}
The problem here is not the R but matter of getting latex to play well with Greek. With hat tip to this answer, perhaps the easiest solution is to switch to XeLaTeX compilation and rewrite your file as
\documentclass[a4paper]{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\newfontfamily\greekfont[Script=Greek]{Linux Libertine O}
\newfontfamily\greekfontsf[Script=Greek]{Linux Libertine O}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{greek}
\title{Sweave Example 1}
\author{George Dontas}
\begin{document}
\maketitle
Ελληνικό κείμενο
In this example we embed parts of the examples from the
\texttt{kruskal.test} help page into a \LaTeX{} document:
...
and so on as before. Then compile with XeLaTeX (latexmk -xelatex file.Rnw will do that).

Resources