-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path4-2_basic_markdown.qmd
More file actions
203 lines (160 loc) · 7.52 KB
/
Copy path4-2_basic_markdown.qmd
File metadata and controls
203 lines (160 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Basic Markdown {.unnumbered}
### Markdown
Quatro files consist of code and markdown. We have discussed how to code in the previous chapters and will discuss markdown here. Markdown is a specific kind of markup language. What we mean by that is that the text in the document also indicates how it should be formatted in the result (For example if we surround a word by double asterikses (like so \*\*bold\*\*) it will **bold** in the resulting output. Below we will discuss the different types of markup that you can use.
#### Basic Formatting
```{r echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(tibble)
library(knitr)
tt <- tribble(~Syntax, ~Output,
"\\*italics\\*", "*italics*",
"\\*\\*bold\\*\\*", "**bold**",
"\\*\\*\\*bold italics\\*\\*\\*", "***bold italics***",
"subscript\\~2\\~", "subscript~2~",
"superscript\\^2\\^", "superscript^2^",
"\\~\\~crossed out\\~\\~", "~~crossed out~~",
"\\`code\\`", "`code`",
)
kable(tt)
```
#### Headings
+--------------------+-----------------------------------+
| Syntax | Output |
+====================+===================================+
| ``` | # Header 1 {.heading-output} |
| # Header 1 | |
| ``` | |
+--------------------+-----------------------------------+
| ``` | ## Header 2 {.heading-output} |
| ## Header 2 | |
| ``` | |
+--------------------+-----------------------------------+
| ``` | ### Header 3 {.heading-output} |
| ### Header 3 | |
| ``` | |
+--------------------+-----------------------------------+
| ``` | #### Header 4 {.heading-output} |
| #### Header 4 | |
| ``` | |
+--------------------+-----------------------------------+
| ``` | ##### Header 5 {.heading-output} |
| ##### Header 5 | |
| ``` | |
+--------------------+-----------------------------------+
| ``` | ###### Header 6 {.heading-output} |
| ###### Header 6 | |
| ``` | |
+--------------------+-----------------------------------+
```{=html}
<style type="text/css">
.heading-output {
border-bottom: none;
margin-top: 0;
margin-bottom: 0;
}
</style>
```
#### Links
```{r echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(tibble)
library(knitr)
tt <- tribble(~Syntax, ~Output,
" <https://www.erasmusmc.nl> ", " <https://www.erasmusmc.nl>",
" \\[EMC\\](https://www.erasmusmc.nl) ", " [EMC](https://www.erasmusmc.nl)"
)
kable(tt)
```
#### Images
```{r echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(tibble)
library(knitr)
tt <- tribble(~Syntax, ~Output,
" !\\[Caption\\](Logo.svg) ", "  ",
' !\\[Caption\\](Logo.svg) "hovertext"', '  ',
' !\\[Caption\\](Logo.svg){fig-alt="Alt text"} ', ' {fig-alt="Alt text"} '
)
kable(tt)
```
It is also possible to include images in links.
#### Lists
+------------------------------------+---------------------------------+
| Markdown Syntax | Output |
+====================================+=================================+
| ``` | - item 1 |
| * item 1 | |
| * item 2 | - item 2 |
| + sub-item 1 | |
| + sub-item 2 | - sub-item 1 |
| - sub-sub-item 1 | |
| ``` | - sub-item 2 |
| | |
| | - sub-sub-item 1 |
+------------------------------------+---------------------------------+
| ``` | - item 2 |
| * item 2 | |
| | Part of item (Extra spaces) |
| Part of item (Extra spaces) | |
| ``` | |
+------------------------------------+---------------------------------+
| ``` | 1. ordered list |
| 1. ordered list | |
| 2. item 2 | 2. item 2 |
| i) sub-item 1 | |
| ii) sub-item 2 | i) sub-item 1 |
| A. etc. | ii) sub-item 1 |
| ``` | |
| | ``` |
| | A. etc. |
| | ``` |
+------------------------------------+---------------------------------+
#### Tables
There are multiple ways to make tables
The easiest way is to use a so called pipe-table like this:
```
| foo| bar | Left align | Right Align | Center |
|----|-------|:-----------|------------:|:------:|
| 1 | 2 | 1 | 2 | 1|
| 3 | 4 |3 | 4 | 4 |
: an optional caption
```
The result is:
| foo | bar | Left align | Right Align | Center |
|-----|-----|:-----------|------------:|:------:|
| 1 | 2 | 1 | 2 | 1 |
| 3 | 4 | 3 | 4 | 4 |
: an optional caption
The first and last pipe character at each row are optional, the ones separating the columns are not although they do not have to be aligned. The header cannot be omitted. The relative width is determined by the number of dashes.
An alternative way to specify the relative column widths is by including the attribute after the caption, like this:
``` markdown
: an optional caption {tbl-colwidths="[40,15,15,15,15]"}
```
Sometimes it is easiest to directly make the tables from R code.
#### Source code
You can use delimited blocks with three backticks to use source code formatting. The syntax:
\`\`\`\`
foo \<- bar
\`\`\`\`
Becomes:
```
foo <- bar
```
It is possible to add an R to indicate the R language is used and apply apropriate highlighting:
```` markdown
``` R
foo <- bar
```
````
Becomes:
``` r
foo <- bar
```
#### Math
You can use TeX like syntax to format equations. Inline formulas are delimeted by single \$s and display math uses double \$\$s.
```{r echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(tibble)
library(knitr)
tt <- tribble(~Syntax, ~Output,
" \\$a^2=b^2+c^2\\$", " $a^2=b^2+c^2$ ",
' \\$\\$a^2=b^2+c^2\\$\\$', ' $$a^2=b^2+c^2$$ '
)
kable(tt)
```