```{r}
#| include: false
#| label: setup

library(emoji)
```



# YAML 

## 

The overall appearance and behavior of the document is specified in the YAML: 

::: {.callout-note collapse="true"}

## HTML default YAML

````
---
title: "Untitled"
format: html
editor: visual
---
````
:::


. . . 

::: {.callout-note collapse="true"}

## PDF default YAML

````
---
title: "Untitled"
format: pdf
editor: visual
---
````
:::

## Source vs. Visual




:::{.panel-tabset}

## Editor
```{r}
knitr::include_graphics("img/q_source.png")
```




## Visual
```{r}
knitr::include_graphics("img/q_visual.png")
```

:::


## YAML: `T`able `o`f `C`ontents (ToC) {footer="false" .smaller}


```{markdown}
#| echo: true
---
title: "My quarto file"
author: "Jane Doe"
date: today
format: 
  html:
    self-contained: true     # 1
    toc: true                # 2   
    toc-title: My contents   # 3
    toc-location: left       # 4
lang: it                     # 5
---
```

1. Allows for the sharing of the hmtl file without requiring for external files

2. Put Table of Contents

3. Define the title of the ToC

4. Location of the ToC (`left`, `right`, `body`)

5. Define the language of the documents



## Themes

The default theme of the document can be modified with the predefined [themes](https://quarto.org/docs/output-formats/html-themes.html)

```{markdown}
#| echo: true
---
title: "My quarto file"
author: "Jane Doe"
date: today
format: 
  html:
    self-contained: true     
    toc: true                   
    toc-title: My contents   
    toc-location: left
    theme: superhero  # 1
    fontsize: 32px    # 2 customization
lang: it                     
---
```


1. Define the theme 

3. Define the font size (other options are available)

## Day vs night 

```{markdown}
#| echo: true
---
format: 
  html:
    theme:
     light: minty
     dark: superhero
---
```

:::{.panel-tabset}

## Day 

```{r}
#| fig-align: center
#| out-width: 100%

knitr::include_graphics("img/light.png")
```


## Night

```{r}
#| fig-align: center
#| out-width: 100%

knitr::include_graphics("img/dark.png")
```


:::

# Markdown formatting 

## Headings  {footer="false"}

```{markdown}
#| echo: true
#| eval: true

# First level
```

Section 

```{markdown}
#| echo: true
#| eval: true

## Second level
```

Subsection

```{markdown}
#| echo: true
#| eval: true

### Third level
```

Sub-subsection

```{markdown}
#| echo: true
#| eval: true

#### Fourth level
```

Paragraph

```{markdown}
#| echo: true
#| eval: true

##### Fifth level
```

I frankly have never used that

```{markdown}
#| echo: true
#| eval: true

##### Sixth level
```

I have no idea


## Text Formatting




**Markdown syntax: Font**


```{markdown}
#| eval: true
#| echo: true
*italics*, **bold**, ***bold italics*** 
```


Output

*italics*, **bold**, ***bold italics***


. . . 

**Markdown syntax: Scripts**


```{markdown}
#| eval: false
#| echo: true
textsuperscirpt^2^, textunderscript~2~
```


Output


textsuperscirpt^2^, textunderscript~2~

. . . 


**Markdown syntax: In line code**

```{markdown}
#| eval: false
#| echo: true
`this is myinline code`
```

Output


`this is myinline code`




## Links and images 


```{markdown}
#| echo: true
#| eval: false

<https://github.com/>
```

<https://github.com/>

. . . 

<br>

```{markdown}
#| echo: true
#| eval: false

My link is [here](https://github.com/)
```


My link is [here](https://github.com/)

. . . 

<br> 

```{markdown}
#| echo: true
#| eval: false

![This is an image](img/picture.jpg)
```


![This is an image](img/picture.jpg)

## Lists {footer=false}


:::: {.columns}

:::{.column width=50%}

```{markdown}
#| echo: true
#| eval: false

* Main Unordered List
  + First sub-item
  + Second sub-item 
    - It's getting weird
```

<br>

<br>

```{markdown}
#| echo: true
#| eval: false

1. Main ordered list
2. Second item
   i) First sub-item 1
      A.  First sub-sub-item 1
```


<br>


<br>


```{markdown}
#| echo: true
#| eval: false

- [ ] First things first 1
- [ ] Second things second 2
```




:::

:::{.column width=50%}

* Main Unordered List
  + First sub-item
  + Second sub-item 
    - It's getting weird
    

1. Main ordered list
2. Second item
   i) First sub-item 1
      A.  First sub-sub-item 1
<br>      
      

- [ ] First things first 1
- [ ] Second things second 2
:::


:::: 

## Math 

In-line math: 

```{markdown}
#| echo: true
#| eval: false

This is an in-line equation $y = \beta_0 + \beta_1 X + \varepsilon$

```


This is an in-line equation $y = \beta_0 + \beta_1 X + \varepsilon$

. . . 

Math math: 

```{markdown}
#| echo: true
#| eval: false

This is an  equation $$z = \dfrac{\bar{x} -\mu}{\sigma}$$

```

This is an  equation $$z = \dfrac{\bar{x} -\mu}{\sigma}$$


## References

::: {.panel-tabset}

## YAML 

Define the path of the bib file in the YAML

```{markdown}
#| echo: true
[...]
bibliography: references.bib
```



## `.bib` file 

```{r}
#| echo: true
#| eval: false
#| code-line-numbers: "|1,9,17|"
@Manual{rsoft,
    title = {R: A Language and Environment for Statistical Computing},
    author = ,
    organization = {R Foundation for Statistical Computing},
    address = {Vienna, Austria},
    year = {2025},
    url = {https://www.R-project.org/}
}
@Book{ggplot,
    author = {Hadley Wickham},
    title = {ggplot2: Elegant Graphics for Data Analysis},
    publisher = {Springer-Verlag New York},
    year = {2016},
    isbn = {978-3-319-24277-4},
    url = {https://ggplot2.tidyverse.org}
}
@article{epifania2024,
  title={A guided tutorial on linear mixed-effects models for the analysis of accuracies and response times in experiments with fully crossed design.},
  author={Epifania, Ottavia M and Anselmi, Pasquale and Robusto, Egidio},
  journal={Psychological Methods},
  year={2024},
  publisher={American Psychological Association}, 
  doi={https://doi.org/10.1037/met0000708}
}
```


## Citation keys



| Key                                                                 |  Output                                                   |
|----------------------------------------------------------------------|--------------------------------------------------------------------|
| `@ggplot` does this|Wickman (2016) does this|
| `ggplot2 is an interesting package [@ggplot2]`                       | ggplot2 is an interesting package (Wickman, 2016)                  |
| `bla bla bla [@epifania2024; @ggplot2]`                              | bla bla bla (Epifania et al., 2024; Wickman, 2016)                 |


:::

. . . 

To call a reference: 

```{markdown}
#| echo: true

@citaton-key
```



# Publish your HTML document (with GitHub)

## GitHub pages 

Navigate to your GitHub repository online: 

```{r}
#| fig-align: center
#| out-width: 90%
knitr::include_graphics("img/pages-git.png")
```

## It worked! 


```{r}
#| fig-align: center
#| out-width: 90%
knitr::include_graphics("img/pages.png")
```

(take some time, be patient)

## `README.md` 


This file handles the generation of the website

It works with basic markdown syntax 

::: {.panel-tabset}
## `README.md` 

```{r}
#| fig-align: center
#| out-width: 110%
knitr::include_graphics(path = "img/readme.png")
```

## Site appearance
```{r}
#| fig-align: center
#| out-width: 110%
knitr::include_graphics(path = "img/site.png")
```

:::


## Links

They create the index to the pages we want to display in our website 

::: {.callout-warning}

The links **must** link to the directory of the html file in the subfolder of the project!
:::

. . . 

Let's say we want to create a link to `my_file.html` that is inside the
`files` subfolder: 

```{markdown}
#| eval: false
#| echo: true

[My presentation](files/my_file.html)
```

Don't forget to save the changes in the `README.md` file 

## `commit` + `push`


```{r out.width="70%"}
knitr::include_graphics("img/commit1.png")
```

## 

```{r out.width="70%"}
knitr::include_graphics("img/commit2.png")
```

Don't forget to push!

## Check

<br>

```{r out.width="80%"}
knitr::include_graphics("img/check-commit.png")
```


## Your turn!

Inside your R project for this school: 

* Create a new HMTL quarto document that must contain:
   + 3 sections (level I heading), each with a subsection (level II heading)
   + Place a picture with a caption in one of the subsection
   + Place an unordered list 

* Render the document in HTML 

* Create the link to your newly created document in the `README.md`

* Commit & push the `.qmd` and `.html` of your newly created document

* Commit & push the `.md` and `.html` of the `README` file 




# Layout

## 

By default, the HTML document is set to take all the space in the page

```{markdown}
#| echo: true
#| eval: false
format: 
  html:
    page-layout: full
```



```{r}
#| eval: true
#| fig-align: center
knitr::include_graphics("img/basic-layout.png")
```


## Document layout 

::: {.panel-tabset}

## A document

```{r}
knitr::include_graphics("img/adavanced-layout.png")
```


## Code

```{markdown}
#| eval: false
#| echo: true
format: 
  html: 
   toc: true
   toc-location: left
   grid:
    sidebar-width: 300px
    body-width: 900px
    margin-width: 300px
    gutter-width: 1.5rem
```


:::


## Margins 

You can place anything in the margins of the documents!


```{markdown}
#| eval: false
#| echo: true

:::{.column-margin}
I want this picture displayed in the margin 


![](img/peacock.png)
:::
```

```{r}
#| fig-align: center
#| out-width: 90%
knitr::include_graphics("img/margins.png")
```

## Even references 

:::{.panel-tabset}

## Output

```{r}
#| out-width: 100%
#| fig-align: center

knitr::include_graphics("img/margin-ref.png")
```


## Code


YAML:  
```{markdown}
#| echo: true
citation-location: margin
```

Citation: 

```{markdown}
#| echo: true


`ggplot2` is an R [@rsoft] package developed by [@ggplot]. @epifania2024 published an interesting paper on Linear Mixed Effects Models. 

```


:::

## Custom layout with grid 

The page layout is based on a 12-unit (or 12-column) grid system, which can be used to divide the space accordingly: 


:::{.panel-tabset}

## Code

```{markdown}
#| echo: true
#| eval: false
::: {.grid}

::: {.g-col-4}

First column, 4/12 of the total width

:::

::: {.g-col-8}

Second column, 8/12 of the total width 

:::

:::
```



## Output

```{r}
#| out-width: 80%
#| fig-align: center
knitr::include_graphics("img/grid.png")
```


:::


## Columns

::: {.panel-tabset}

## Code

```{markdown}
#| echo: true
#| eval: false
:::: {.columns}


::: {.column width="50%"}

This is my first column!

:::

::: {.column width="50%"}

And this is the second column
:::

::::
```

## Output


:::: {.columns}

::: {.column width="50%"}

This is my first column!

:::

::: {.column width="50%"}

And this is the second column
:::

::::

:::

(Best for HMTL presentation)

## tabset: code



```{markdown}
#| echo: true
#| eval: false
::: {.panel-tabset}

## Aim

Here I present the aim of the study 

## Methods

Here I present the methods used to pursue the aim

## Results

And here I present the results

:::
```


## tabset: output

::: {.panel-tabset}


## Aim

Here I present the aim of the study 

## Methods

Here I present the methods used to pursue the aim

## Results


And here I present the results

::: 

## Callout

:::{.panel-tabset}

## Output

::: {.callout-note}
To say something general
:::

::: {.callout-tip}
## I'm a title!

Maybe a tip :)
:::

::: {.callout-caution}
## Pay attention!

Please pay attention to whatever it is written here
:::


::: {.callout-warning}
Just saying you should be careful
:::

## Code

```{markdown}
#| echo: true
#| eval: false

::: {.callout-note}
To say something general
:::

::: {.callout-tip}
## I'm a title!

Maybe a tip :)
:::

::: {.callout-caution}
## Pay attention!

Please pay attention to whatever it is written here
:::


::: {.callout-warning}
Just saying you should be careful
:::
```


:::

## Collapsing & Other amenities

:::{.panel-tabset}

## Output 

::: {.callout-warning collapse="true"}

## Look at me!!

I collapse (Actually you can't see the callout collapsing, just copy & paste in your file)

:::


::: {.callout-tip icon="false"}
## I'm not an icon

I removed the icon from this specific callout. If you want to remove the icons from **all** the blocks, go in the YAML, and on a new line (not indented): 

```{markdown}
#| echo: true
callout-icon: false
```

:::


## Code


```{markdown}
#| echo: true

::: {.callout-warning collapse="true"}

## Look at me!!

I collapse (Actually you can't see the callout collapsing, just copy & paste in your file)

:::


::: {.callout-tip icon="false"}
## I'm not an icon

I removed the icon from this specific callout. 

If you want to remove the icons from **all** the blocks, go in the YAML: 


:::
```


:::






## Your turn

From the previous document:

* In one of the sections, create a grid dividing the space in 3 intervals of different width 
* Place a picture in each of the three intervals
* In a subsection: 
  + Create a panel tabset with 3 tabs (like Introduction, Methods, Results)
  + Add a picture in the margin of the document
* Go grazy with the callout
