3 R markdown
3.1 Headings
Every chapter should have a first-level heading marked by #
. A second-level heading has two of #
, a third-level heading three of them and so on until six. Here’s how to write a first-level heading followed by a second-level heading:
# <first-level heading>
## <second-level heading>
The caption for references must be unnumbered so i did with the corresponding command:
The latter result can be achieved using a shorter form:
3.3 Italics
Text can be turned to italics using asterisks around it:
*<text in italics>*
<text in italics>
3.6 Code
3.6.1 As a block
Code blocks can be marked by three ticks following by braces containing metadata. The first metadata is the language. i’ve used so far r
and bash
:
i keep an empty line at the end of the code block content because if i want to use a keyboard shortcut for commenting out it only works if the last line is empty.
If the language is \(\mathrm{ \LaTeX{} }\) or \(\mathrm{ \LaTeX{} }\) then the language must not only be in lowercase but have a preceding =
[18]:
There are some options that can be used for code blocks or chunks in addition to them mentioned in the general configuration part:
eval
- Shall the code be executed or not or what lines of the code should be executed?
If i want to show a code-block without rendering it, i use a verbatim
block as a wrapper around it:
````{verbatim label = "onecolumn-example", lang = "latex"} # 1
```{=latex eval = FALSE} # 2
\onecolumn # 3
# 4
``` # 5
# 6
```` # 7
# 8
For verbatim
to work, it has to have at least one more backtick than the outermost inner block[19].
3.7 Quoting
For quoting, i use >
at the beginning of each line of the quote.
<the quoted text>
It’s also possible to do a multi-line quote by adding two spaces at the end of each line which means a line break[20]:
<first line of the quote>
<second line of the quote>
Another way of multiline quoting is to inclue >
in front of each row:
> <first line of the quote> # 1
<second line of the quote> # 2
> # 3
> <fourth line of the quote> # 4
# 5
<first line of the quote>
<second line of the quote><fourth line of the quote>
A quote with the author:
> All on konstantne. Siis ma... Midagi läheb sealt läbi, aga siis peab mõtlema, mis, mis kurat sealt läbi läheb. # 1
# 2
`r librarian::shelf(c("tufte")); tufte::quote_footer('--- Tõnu Laas')` # 3
All on konstantne. Siis ma… Midagi läheb sealt läbi, aga siis peab mõtlema, mis, mis kurat sealt läbi läheb.
3.8 Escaping
If a character must be escaped then a backslash can be used right in front of it (example (1)).
*\**
*
The following additional characters must be escaped:
_,
@,
&.
If the number is an ordinal then in Estonian, there is a period after the scalar which the parser recognizes as the period for a list element. For that not happen, the period must be preceded by a backslash (example (2)).
1961\. a sätestati...
1961. a sätestati…
3.9 Non-breaking space
In the example (3), the name will be broken if it does not fit into the line.
The name of one of my companies out of many is MTÜ Eesti Kõrgkoolitennise Liit.
In the example (4), the name will not be broken if it does not fit into the line using  
[21].
The name of one of my companies out of many is MTÜ Eesti Kõrgkoolitennise Liit. # 1
# 2
The name of one of my companies out of many is MTÜ Eesti Kõrgkoolitennise Liit.
In the example (5), the name will not be broken if it does not fit into the line using \
[22].
The name of one of my companies out of many is MTÜ Eesti Kõrgkoolitennise Liit.
Non-breaking spaces do not work with multicols.
3.10 Referencing
3.10.1 Common reference
A target for a common reference:
<label-for-target>} []{#
A link for a common target:
[<link text>](#<label-for-target>)
3.10.2 External reference
3.10.2.1 Preparation and common use cases
For having an external reference, i put its Bib\(\mathrm{ \TeX{} }\) block into references.bib. i seldom create it manually. Instead, i use the help of MyBib[23] where i Start a new project for every project, Add Citation, Download References as Bib\(\mathrm{ \TeX{} }\), copy the lastly added reference from the downloaded file into references.bib so that the items there are listed alphabetically. Another such helper is BibGuru[24].
As there’s a problem to display emojis and they appear seldom then i only use the emoji-able font Symbola that can’t italics nor bold only for strings that contain emojis. External references can contain them. This is why all the external references will be rendered using Symbola. For that, i created a function called render_with_emojis
that can’t handle references directly but over inner reference because of the corresponding bookdown restriction. Therefore, for every record in the list of external references, i also created an inner reference into the end of the file references.Rmd like this:
(ref:<identifier-of-inner-reference-in-snake-case>) @<identifier-of-external-reference-as-is> # 1
# 2
The identifier of the inner reference isn’t allowed to contain underscores. Between every inner reference, at least one empty line must be.
For inline referencing, wherever i wanted to have a reference to that reference record i called render_with_emojis
and fed it with a value for text
as the identifier of the internal reference in parenthesis if the reference is direct and in double parenthesis if indirect:
i use MyBib `r render_with_emojis("((ref:<identifier-of-inner-reference-in-snake-case>))")`. # 1
# 2
`r render_with_emojis("(ref:<identifier-of-inner-reference-in-snake-case>)")` automates creating references. # 3
# 4
As i am using numeric referencing now, the identifier is not textual, so i use the short version for referencing whereas the identifier is the one in the BIB-file as render_with_emojis
does not do the job in this case:
i use MyBib [@<identifier-of-inner-reference-in-snake-case>]. # 1
# 2
@<identifier-of-inner-reference-in-snake-case> automates creating references. # 3
# 4
If the exact location in the source is necessary to refer to then it can be added to the reference part in the short version by separating it from the identifier with a comma and preceding it with p. which is short for page or pages. One can also use the corresponding short in another language. For minutes in a video, the short could be min. The rule:
i use MyBib [@<identifier-of-inner-reference-in-snake-case>(p. <range>)]. # 1
# 2
@<identifier-of-inner-reference-in-snake-case>(p. <range>) automates creating references. # 3
# 4
For example:
A surprising piece of data is this[25(p. 6)].
CRC Handbook of Chemistry and Physics, 95th Edition[25(p. 6)] represents some suprising pieces of data.
We can use a comma instead of parentheses for the page range however that would confuse the reader as in the output commas a also used to separate multiple references.
3.10.2.2 Multiple references
Multiple references can be used with a semicolon[26]:
3.10.2.3 Reference in the caption
Referencing in the caption works just fine if the figure is upright. If the figure is at a different angle the whole caption must be written out as a reference before[27]:
Joonisel \@ref(fig:cities) leheküljel `r render_pageref(reference = "fig:cities")` on näidatud gravitatsioonist põhjustatud kiirendus eri piirkondades Maal. # 1
# 2
Gravitatsioonist põhjustatud kiirendus eri Maa paigus[28]. Gravitatsioonist põhjustatud kiirendus eri Maa paigus[@elert_2019_glenn]. # 3
# 4
```{r label = "cities", echo = FALSE, fig.cap = "Gravitatsioonist põhjustatud kiirendus eri Maa paigus[28].", echo = FALSE, out.extra="angle = 90", out.width=".92\\textheight"} # 5
include_external_graphics("rmd/g.png") # 6
# 7
``` # 8
# 9
Joonisel 3.1 leheküljel on näidatud gravitatsioonist põhjustatud kiirendus eri piirkondades Maal.
![Gravitatsioonist põhjustatud kiirendus eri Maa paigus[28].](rmd/g.png)
Figure 3.1: Gravitatsioonist põhjustatud kiirendus eri Maa paigus[28].
3.11 Tables
Võrdlen tabelis \@ref(tab:base-10-base-1) kümnendsüsteemi arve ühendsüsteemi arvudega. # 1
# 2
| Baas 10 | Baas 1 | # 3
|---------|--------| # 4
| 1 | 1 | # 5
| 2 | 11 | # 6
| 3 | 111 | # 7
| 4 | 1111 | # 8
# 9
: (\#tab:base-10-base-1) Kümnendsüsteemi ja ühendsüsteemi arvud # 10
# 11
Võrdlen tabelis 3.1 kümnendsüsteemi arve ühendsüsteemi arvudega.
Baas 10 | Baas 1 |
---|---|
1 | 1 |
2 | 11 |
3 | 111 |
4 | 1111 |
Kolmendsüsteemis on kasutuses kolm võimalikku erinevat numbrit, nt 0, 1 ja 2. Võrdlen tabelis \@ref(tab:bases-10-2-3) eri baaside arve. # 1
# 2
| Baas 10 | Baas 2 | Baas 3 | # 3
|--------:|-------:|-------:| # 4
| 0 | 0 | 0 | # 5
| 1 | 1 | 1 | # 6
| 2 | 10 | 2 | # 7
| 3 | 11 | 10 | # 8
| 4 | 100 | 11 | # 9
| 5 | 101 | 12 | # 10
| 6 | 110 | 20 | # 11
| 7 | 111 | 21 | # 12
| 8 | 1000 | 22 | # 13
| 9 | 1001 | 100 | # 14
# 15
: (\#tab:bases-10-2-3)Kümnend-, kahend- ja kolmendsüsteemi arvud # 16
# 17
Kolmendsüsteemis on kasutuses kolm võimalikku erinevat numbrit, nt 0, 1 ja 2. Võrdlen tabelis 3.2 eri baaside arve.
Baas 10 | Baas 2 | Baas 3 |
---|---|---|
0 | 0 | 0 |
1 | 1 | 1 |
2 | 10 | 2 |
3 | 11 | 10 |
4 | 100 | 11 |
5 | 101 | 12 |
6 | 110 | 20 |
7 | 111 | 21 |
8 | 1000 | 22 |
9 | 1001 | 100 |
| Second bit | First bit | # 1
|:----------:|:---------:| # 2
| 0 | 0 | # 3
| 0 | 1 | # 4
| 1 | 0 | # 5
| 1 | 1 | # 6
# 7
: (\#tab:base-2)For representing a larger number, more bits on the left are needed. 0 and 1 can still be displayed using two bits while the second bit having 0-s. Once the first bit is full the second bit starts with 1 and the first bit starts over # 8
# 9
Taken from the table \@ref(tab:base-2) there are four combinations altogether possible using two bits. # 10
# 11
Taken from the table 3.3 there are four combinations altogether possible using two bits.
Second bit | First bit |
---|---|
0 | 0 |
0 | 1 |
1 | 0 |
1 | 1 |
3.12 Equations
Equations can be inserted in math mode, id est between double bug signs if in a block or single bug signes if inline:
\[\frac{t_\text{d}}{}\]
The same equation inline: \(\frac{t_\text{d}}{}\).
3.13 Lists
In the example (6), a comment between two list items ends the list and starts a new one[29]. This way, it is possible to create a non-continuous list.
-
A list with holes:
7. Korrutage \qty{4,079e2}{\m} \qty{0,057e-1}{\m}'ga, võttes arvesse olulisi numbreid. # 1 # 2 <!-- --> # 3 # 4 9. Väikeste nurkade $u$ korral on $\mathrm{sin}(u)$ arvväärtus ligikaudu sama, mis $\mathrm{tan}(u)$ arvväärtus. # 5 Leia suurim nurk, mille puhul siinus ja tangens langevad kokku kahe tüvenumbri piires. # 6 # 7
- Korrutage ’ga, võttes arvesse olulisi numbreid.
- Väikeste nurkade \(u\) korral on \(\mathrm{sin}(u)\) arvväärtus ligikaudu sama, mis \(\mathrm{tan}(u)\) arvväärtus. Leia suurim nurk, mille puhul siinus ja tangens langevad kokku kahe tüvenumbri piires.
In the example (7), the list is continuous no matter what identifier is in front of the second item.
-
A continuous list:
7. Korrutage \qty{4,079e2}{\m} \qty{0,057e-1}{\m}'ga, võttes arvesse olulisi numbreid. # 1 # 2 9. Väikeste nurkade $u$ korral on $\mathrm{sin}(u)$ arvväärtus ligikaudu sama, mis $\mathrm{tan}(u)$ arvväärtus. # 3 Leia suurim nurk, mille puhul siinus ja tangens langevad kokku kahe tüvenumbri piires. # 4 # 5
Korrutage ’ga, võttes arvesse olulisi numbreid.
Väikeste nurkade \(u\) korral on \(\mathrm{sin}(u)\) arvväärtus ligikaudu sama, mis \(\mathrm{tan}(u)\) arvväärtus. Leia suurim nurk, mille puhul siinus ja tangens langevad kokku kahe tüvenumbri piires.
3.14 Examples
Examples can be made as seen in the example (8)[29].
3.15 Exercises[27]
::: {.exercise #dynamics-task-20240303-1 name="Kolme vektori suurus ja suund."} # 1
Tee kindlaks kolme vektori # 2
$$\overrightarrow{\bf{V}_1} = 4,0 \hat{\bf{i}} - 8,0 \hat{\bf{j}},$$ # 3
$$\overrightarrow{\bf{V}_2} = \hat{\bf{i}} + \hat{\bf{j}} \text{ ja}$$ # 4
$$\overrightarrow{\bf{V}_3} = -2,0 \hat{\bf{i}} + 4,0 \hat{\bf{j}}$$ # 5
suurus ja suund! # 6
# 7
Tee kindlaks $\overrightarrow{\bf{V}_1} - \overrightarrow{\bf{V}_2} + \overrightarrow{\bf{V}_3}$. # 8
::: # 9
Exercise 3.1 (Kolme vektori suurus ja suund.) Tee kindlaks kolme vektori \[\overrightarrow{\bf{V}_1} = 4,0 \hat{\bf{i}} - 8,0 \hat{\bf{j}},\] \[\overrightarrow{\bf{V}_2} = \hat{\bf{i}} + \hat{\bf{j}} \text{ ja}\] \[\overrightarrow{\bf{V}_3} = -2,0 \hat{\bf{i}} + 4,0 \hat{\bf{j}}\] suurus ja suund!
Tee kindlaks \(\overrightarrow{\bf{V}_1} - \overrightarrow{\bf{V}_2} + \overrightarrow{\bf{V}_3}\).