R
code chunk using knitr::asis_output
and output: asis
producing enclosing container (.cell-output-display
)
#6874
-
DescriptionConsider a
and this
Rendering this using The detrimental effect of that become apparent if one adds the following to
which references this file:
Rendering as above now produces tight Can anyone hint at whether this is a bug, given that How might I overcome this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
What's that? It's invalid markup Could you simplify your example? is the Also you are mixing several things such as You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````qmd
---
title: "Reproducible Quarto Document"
format: html
---
This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.
```{r}
plot(cars)
```
The end.
```` |
Beta Was this translation helpful? Give feedback.
-
I am wondering if we are correctly doing the right thing in Quarto for ---
output:
pdf_document:
keep_md: true
header-includes: |
\usepackage{enumitem}
\setlist[description]{nosep,style=multiline,leftmargin=3.5cm,font=\normalfont\textsf}
---
```{r, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
First Name:
: **Some**
Family Name:
: **One**
```{r, results='asis'}
cat(paste0("Date of Birth:\n", ": Date"))
```
Email:
: [[email protected]](mailto:[email protected])
First Name:
: **Some**
Family Name:
: **One**
```{r}
requireNamespace("knitr")
knitr::asis_output(paste0(
"Date of Birth:\n",
": Date"))
```
Email:
: [[email protected]](mailto:[email protected])
There shouldn't be any difference 🤔 Also regarding this example, why not prefer inline chunk in this case ?
|
Beta Was this translation helpful? Give feedback.
-
On September 21, 2023 1:56:01 PM UTC, Christophe Dervieux ***@***.***> wrote:
I am wondering if we are correctly doing the right thing in Quarto for `output_asis`... it should be equivalent to `output: asis` like in R Markdown context.
````markdown
---
output:
pdf_document:
keep_md: true
header-includes: |
\usepackage{enumitem}
\setlist[description]{nosep,style=multiline,leftmargin=3.5cm,font=\normalfont\textsf}
---
```{r, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
First Name:
: **Some**
Family Name:
: **One**
```{r, results='asis'}
cat(paste0("Date of Birth:\n", ": Date"))
```
Email:
: ***@***.******@***.***)
First Name:
: **Some**
Family Name:
: **One**
```{r}
requireNamespace("knitr")
knitr::asis_output(paste0(
"Date of Birth:\n",
": Date"))
```
Email:
: ***@***.******@***.***)
````markdown
There should be any difference 🤔
Also regarding this example, why not prefer inline chunk in this case ?
````
First Name:
: **Some**
Family Name:
: **One**
`r paste0("Date of Birth:\n", ": Date")`
Email:
: ***@***.******@***.***)
````
Thanks for picking this up. You are right, of course, with the advise to Inline in this case, but it is just a reproducible example to a more complex real world application, where conditional chunk inclusion comes in really Handy.
|
Beta Was this translation helpful? Give feedback.
-
On September 21, 2023 2:47:19 PM UTC, Christophe Dervieux ***@***.***> wrote:
> but it is just a reproducible example to a more complex real world application, where conditional chunk inclusion comes in really Handy.
I understand. I would love to see this real example !
It's actually my CV, which uses multiple interlocking profiles that govern chunk inclusion: 2 alternative languages, a long version and a one page resume, elements that cater to peculiarities of different application environments (private address yes or no, inclusion of trusted colleagues as reference yes or no, inclusion of earlier successful selection process yes or no) etc.
Other comment when generating markdown, especially using chunks (as they are closer to block content). When needing to mix raw markdown and computed content using a chunk (when inline not possible), it is sometimes best to use `knit_child` using external document, or template string.
* https://bookdown.org/yihui/rmarkdown-cookbook/knit-expand.html
* https://bookdown.org/yihui/rmarkdown-cookbook/child-document.html
This allows to write Markdown context mixing R code, possibly inline, but write the inclusion of this in a chunk so that some options can be applied (like conditional insertion).
As Markdown can be really sensible to syntax (like new line or other content in list), insuring that the whole block comes together is best. Because using a chunk (which is block element really), in the middle of another block markdown content like List can be tricky.
Anyhow, several solutions as always, just sharing experience.
Interesting. I shall explore.
|
Beta Was this translation helpful? Give feedback.
Could you try the following? (I don't have access to a proper LaTeX installation right now)