knitr generates HTML figure in LaTeX Markdown - knitr

I have an Rmd file and want to convert it into a PDF with knitr-pandoc-latex. Here's a small example that works as intended:
---
title: "Minimal Working Example"
author: Author Psaroudakis
date: "August 27th 2018"
output: pdf_document
---
```{r boxplot, dev='pdf'}
boxplot(mtcars$disp ~ mtcars$cyl)
```
that is knitted to:
---
title: "Minimal Working Example"
author: Author Psaroudakis
date: "August 27th 2018"
output: pdf_document
---
```r
boxplot(mtcars$disp ~ mtcars$cyl)
```
![plot of chunk boxplot](figure/boxplot-1.pdf)
which can be easily turned into a PDF with pandoc. But if I want to resize the plot with out.width, knitr turns it into HTML code, but I want to create a PDF, not a HTML page!
…
```{r boxplot, dev='pdf', out.width='50%'}
boxplot(mtcars$disp ~ mtcars$cyl)
```
is rendered to:
---
title: "Minimal Working Example"
author: Author Psaroudakis
date: "August 27th 2018"
output: pdf_document
---
```r
boxplot(mtcars$disp ~ mtcars$cyl)
```
<embed src="figure/boxplot-1.pdf" title="plot of chunk boxplot" alt="plot of chunk boxplot" width="50%" type="application/pdf" />
Does anybody have a solution for this? I've tried opts_knit$set(out.format="latex"); but it didn't make any difference. Thank you in advance!

I don't see a problem. When I create your test document, and run
rmarkdown::render("test.Rmd")
(or click on Knit in RStudio), I get the figure at the requested width. Perhaps your unstated method of converting to PDF is the problem?

Related

Get rid of file name and date in VScode markdown

I am very new to markdown. I use VScode editor with Markdown All in One and Markdown PDF extensions.
Let's say I open test.md file and write the following text
### This is my first markdown text
Hello
When I export the text into pdf, using Ctrl+Shift+P - markdown-pdf: Export (pdf), I get the following output:
The question is, how do I get rid of the name and the date in the upper part of the page?
Please refer to Markdown-Pdf's README doc,in the chapter Options,disable the markdown-pdf.displayHeaderFoote may solve your problem.

Can I format tooltip strings in App Designer?

I am working on migrating a GUI from MATLAB GUIDE to App Designer (v2019b). In GUIDE, I could format the tooltip text by supplying an HTML string. This doesn't appear to work in App Designer. Is there any way to format the tooltip text in App Designer?
In particular, I'm looking to bold certain words and add line breaks to the tooltip. Here's an example of the formatting I used in GUIDE:
<html>Here's a description of a Table<br>
<b>Column1: </b> This is a description of Column1.<br>
<b>Column2: </b> This is a description of Column2.<br>
<b>Column3: </b> This is a description of Column3.
For an output that would look like:
Here's a description of a Table
Column1: This is a description of Column1.
Column2: This is a description of Column2.
Column3: This is a description of Column3.

How to make a figure caption in Rmarkdown?

I am thinking about writing my thesis with rmarkdown and latex. I'm getting the hang of how it all works, however, when I try to add a figure (not an R plot) to the text and render it to pdf, the caption and in-text reference dissappear.
This is the code snippet I use to add a figure:
---
title: "Untitled"
output: pdf_document
---
see figure \ref{fig1}.
![picture \label{fig1}](figure1.png)
This is what knitr creates:
This is what pandoc creates:
Question:
How do I make figure captions and in-text references to those figures in Rmarkdown that will display when rendered to pdf?
OR
How do I tell pandoc what Rmarkdown is so it will render R code and plots?
Please see the documentation of R Markdown for PDF output, and in particular, look for fig_caption. Figure captions are turned off by default in R Markdown, and you have to turn them on (fig_caption: true). You can also find this setting from the gear button on the toolbar of RStudio IDE.
Update: please check https://github.com/yihui/knitr/issues/1063.
Question: How do I make figure captions and in-text references to those figures in Rmarkdown that will display when rendered to pdf?
To get the cross-reference in the PDF produce by LaTeX you need to run LaTeX more than once. Some LaTeX IDE does it for you.
knitr is only running LaTeX once and that is the reason that you only get ??. To confirm that this was the problem I ran
library(knitr)
knitr()
in R that returned
see figure \ref{fig1}.
\begin{figure}[htbp]
\centering
\includegraphics{imagem.jpg}
\caption{picture \label{fig1}}
\end{figure}
which is a valid LaTeX code.
How do I tell pandoc what Rmarkdown is so it will render R code and plots?
Pandoc only understand Markdown (not RMarkdown). First you have to call knitr to generate the Markdown from the RMarkdown and after it call Pandoc to convert the Markdown to LaTeX.
I just found a very useful solution here.
First, include the following chunk:
```{r functions, include=FALSE}
# A function for captioning and referencing images
fig <- local({
i <- 0
ref <- list()
list(
cap=function(refName, text) {
i <<- i + 1
ref[[refName]] <<- i
paste("Figure ", i, ": ", text, sep="")
},
ref=function(refName) {
ref[[refName]]
})
})
```
After, we can add the caption of the figure/table in the figure chunk options like:
```{r, fig.cap=paste("Your caption.")}
See that fig.cap works better with paste.
In Rmarkdown
for markdown figures
![caption \label{labelx}](link_to_figure, or path of figure){figure dimensions}
# how to cite markdown figure
\ref{labelx}
for latex figures
Add following in the figure environment of latex which starts with
\begin{figure}
includegraphics[]{/path to figure}
\label{label}
\end{figure}
# how to cite latex
\ref{label}
for bookdown
add chunk names as label names like
{r label2,echo=F}
# to cite by using bookdown use
\#ref(fig:label2)
similarly for tab we cite table as \#ref(tab:table_label)
For captioner package
add a chunk at the top of rmarkdown document
tab_cap <- captioner(prefix = "table")
fig_cap <- captioner(prefix = "figure")
where prefix is the prefix for cross referencing a figure.
add this in chunk options
{r fig_cap("labelforcaptioner","caption for captioner figure"}
note that fig_cap is similar to fig_cap in chunk code for captioner.
and to cite use
`r fig_cap("label4",display='cite')

Emacs org-mode markdown export: #+TITLE option not exported

I use the great org-mode to easily push modifications of README.md to GitHub projects. Markdown export works great, except for the #+TITLE option not being exported to Markdown - which works flawlessly for HTML export.
I want to keep the file name README.org for convenient converting to Markdown, else I could have chosen the title as file name, which displays the title correctly on GitHub.
Any suggestions on how to achieve this?
Based on your question and subsequent comments, you seem to want to achieve three things:
Define a custom title that gets exported as a top-level headline.
Insert the TOC after the title.
The TOC should not include the title.
Custom location for TOC
Inserting the TOC at a custom location is easy, so let's start with that: Add
#+OPTIONS: toc:nil
to the export options at the top of README.org. By itself, this tells org-mode not to include the default TOC when exporting. You can then place the TOC where you want it to go by inserting
#+TOC: headlines
at the desired location. (This method is not specific to Markdown export.)
Custom title that doesn't show up in TOC
Defining a custom title that is not included in the TOC is a bit trickier, but the basic idea is to exclude the title from the TOC by formatting it as a Markdown headline instead of an org headline. As a first step, change README.org to look like this:
#+OPTIONS: toc:nil
# Emacs als Python-Power-Editor für den RasPi
#+TOC: headlines
* Wieso nur ausgerechnet Emacs???
...
Out of the box this won't yield the desired results because org will interpret the title as a comment and by default the Markdown exporter is configured to ignore comments. However, in order to change the default behavior you can
define a custom transcoder for comments in your .emacs:
(defun org-md-comment (comment contents info)
"Transcode COMMENT object into Markdown format.
CONTENTS is nil. INFO is a plist holding contextual information."
(format "# %s" (org-element-property :value comment)))
redefine the Markdown export backend to make use of this transcoder:
(org-export-define-derived-backend 'md 'html
;; ...
:translate-alist '((bold . org-md-bold)
(code . org-md-verbatim)
(comment . org-md-comment) ;; <--- Use custom transcoder
(comment-block . (lambda (&rest args) ""))
;; ...
))
The original definition of the backend can be found in the file ox-md.el; this file is located in the directory of your org-mode installation. You'll need to copy the full definition to your .emacs file and change the line
(comment . (lambda (&rest args) ""))
as shown above.
Results
With these customizations the resulting README.md file looks like this:
# Emacs als Python-Power-Editor für den RasPi
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li>1. Wieso nur ausgerechnet Emacs???</li>
<li>2. Die Maus ist tot, es leben die shortcuts!</li>
<li>3. Auf den Emacs, fertig, los!</li>
</ul>
</div>
</div>
# Wieso nur ausgerechnet Emacs???
...
See http://article.gmane.org/gmane.emacs.orgmode/82634.
The problem is supposed to be fixed. Only waiting for an update of the converter on GitHub site...
This is useful to get what the answer expects but I think it is not the right path to resolve this question. Let me explain it
I think the issue is about exporting options from org-mode to md but I also want to keep my docs in org-mode and this hacks org-mode export option adding another line for title exporting to md headline 1 but not manages the whole thing.
What I expect and I guess this is the important issue is to export orgmode to md properly, I mean:
the title from orgmode to md heading one (#) -as orgmode to html does.
the heading one from orgmode (*) to md heading two (##)
If this issue is not about it I should open a new one :)
Best!

What is the difference between knitHTML and rmarkdown render?

I am using RStudio version 0.98.501, R version 3.0.2 on Windows 7. I have following code written in a .Rmd file:
---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---
Title
========================================================
This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages (click the **Help** toolbar button for more details on using R Markdown).
When you click the **Knit HTML** button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r fig.width=7, fig.height=6}
plot(cars)
```
Literature Review
==================
this is sample text
Hello
------
World!
### Subsection
this is subsection
When I click knitHtml button the created html file DOES NOT contain the table of contents. However when I use following code, it creates the table of contents and change the theme to united:
rmarkdown::render('C:/Users/durraniu/Documents/Trajectory1/knitHtml/test.Rmd')
What is the difference and how can I make knitHtml button work the way the code does?
RStudio version 0.98.501 does not support the rmarkdown package. You have to check out the latest preview version (at this moment, v0.98.894).