-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.qmd
640 lines (422 loc) · 11.9 KB
/
index.qmd
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
---
title: Markdown, Pandoc and Quarto
subtitle: a modern ecosystem for typesetting and publishing
author:
- name: Julien Vitay
email: julien.vitay@informatik.tu-chemnitz.de
url: https://julien-vitay.net
affiliation: Chemnitz University of Technology
affiliation-url: https://tu-chemnitz.de
orcid: 0000-0001-5229-2349
bibliography: references.bib
csl: assets/frontiers.csl
qrcode: https://julien-vitay.net/quarto-presentation
footer: Tutorial on Markdown, Pandoc and Quarto
---
# Why Markdown? {#sec-introduction}
* The two main approaches to generating documents (reports, slides, etc) are Office suites (MS, Google, Libre...) and LaTeX.
:::columns
:::column
:::callout-note
## Office
*Pros:*
+ WYSIWYG
+ Collaboration (review mode, google doc)
*Cons:*
+ Version conflicts.
+ Reproducibility.
+ Math equations and bibliography are not great.
:::
:::
:::column
:::callout-tip
## LaTeX
*Pros:*
+ Beautiful documents (but not beamer slides).
+ Reproducibility.
*Cons:*
+ Horrible markup language.
+ Compilation is slow.
+ Only outputs pdf (no video in your slides).
:::
:::
:::
* Both are additionally not great at generating html $\rightarrow$ third ecosystem.
# 1 - Markdown {#sec-markdown}
# Basic Markdown syntax
* Markdown is a markup language (as html, tex, wiki, rst...) initially developed to write basic documents (e.g. README files or blocks in Jupyter notebooks).
:::columns
:::column
**Latex**
```latex
\textbf{Bold text} \textit{Italic text} \verb?Verbatim?
\begin{itemize}
\item Item 1
\item Item 2
\end{itemize}
\begin{enumerate}
\item Item 1
\item Item 2
\end{enumerate}
\section{First header}
\subsection{Second header}
\subsubsection{Third header}
\href{https://julien-vitay.net}{My website}
\url{https://julien-vitay.net}
```
:::
:::column
**Markdown**
```markdown
**Bold text** *Italic text* `Verbatim`
* Item 1
* Item 2
1. Item 1
2. Item 2
# First header
## Second header
### Third header
[https://julien-vitay.net](My website)
<https://julien-vitay.net>
```
:::
:::
# Images
:::columns
:::column
**Latex**
```latex
\includegraphics{img/ai.png}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.5\textwidth]{img/ai.png}
\caption{The logo of the lab.}
\label{fig:mesh1}
\end{figure}
```
![](img/ai.webp){fig-align=center width=50%}
:::
:::column
**Markdown**
```markdown
![](img/ai.webp)
![The logo of the lab.](img/ai.webp){width=50%}
```
![The logo of the lab.](img/ai.webp){#fig-logolab width=50%}
:::
:::
# Tables
:::columns
:::column
**Latex**
```latex
\begin{tabular}{|ccc|}
\hline
Column 1 & Column 2 & Column 3 \\
\hline \hline
item 11 & item 12 & item 13 \\
\hline
item 21 & item 22 & item 23 \\
\hline
\end{tabular}
```
:::
:::column
**Markdown**
```markdown
| Column 1 | Column 2 | Column 3 |
| -------- | -------- | -------- |
| item 11 | item 12 | item 13 |
| item 21 | item 22 | item 23 |
```
<br>
**Rendered**
| Column 1 | Column 2 | Column 3 |
| -------- | -------- | -------- |
| item 11 | item 12 | item 13 |
| item 21 | item 22 | item 23 |
: {.table .table-striped .table-hover .bordered}
:::
:::
<br>
See <https://www.tablesgenerator.com/markdown_tables> for easier design of tables.
# Code blocks
:::columns
:::column
**Latex**
```latex
\begin{lstlisting}
import numpy as np
import ANNarchy as ann
P = ann.Population(geometry=1000, neuron=ann.Izhikevich)
E = P[:800] ; I = P[800:]
EI = ann.Projection(pre=E, post=P, target='exc')
EI.connect_all_to_all(weights=ann.Uniform(0.0, 0.5))
IE = ann.Projection(pre=I, post=P, target='inh')
IE.connect_all_to_all(weights=ann.Uniform(0.0, 1.0))
ann.compile()
ann.simulate(1000.0, measure_time=True)
\end{lstlisting}
```
:::
:::column
**Markdown**
````markdown
```python
import numpy as np
import ANNarchy as ann
P = ann.Population(geometry=1000, neuron=ann.Izhikevich)
E = P[:800] ; I = P[800:]
EI = ann.Projection(pre=E, post=P, target='exc')
EI.connect_all_to_all(weights=ann.Uniform(0.0, 0.5))
IE = ann.Projection(pre=I, post=P, target='inh')
IE.connect_all_to_all(weights=ann.Uniform(0.0, 1.0))
ann.compile()
ann.simulate(1000.0, measure_time=True)
```
````
:::
:::
Code blocks with syntax highlighting are available for many languages: python, cpp, latex, java, html, etc.
# Equations
* Both LaTeX and Markdown use the same mathematical description for equations, both inline and as blocks, using the `$$` environment:
```markdown
The firing rate $r_j (t)$ of the $j$-th neuron in the population follows the following equation:
$$
\tau \, \dfrac{d r_j(t)}{dt} + r_j(t) = \sum_{i=1}^N w_{i, j} \, r_i (t)^+ + B_j
$$
```
The firing rate $r_j (t)$ of the $j$-th neuron in the population follows the following equation:
$$
\tau \, \dfrac{d r_j(t)}{dt} + r_j(t) = \sum_{i=1}^N w_{i, j} \, r_i (t)^+ + B_j
$$ {#eq-neuron}
# 2 - Pandoc {#sec-pandoc}
# Pandoc
* Many tools are available to produce documents (html, pdf) from Markdown files, sometimes using modifications of the syntax (e.g. Github-flavoured Markdown).
* [Pandoc](https://pandoc.org) is an amazing converter from Markdown to many other formats (html, latex, docx, odt, wiki) and back, with its own extension of the Markdown syntax and templates.
```bash
pandoc file.md --template=nature.tex -o file.pdf
```
```{=html}
<iframe width="1500" height="500" src="https://pandoc.org/"></iframe>
```
:::footer
<https://pandoc.org>
:::
# Cross-references
* As `\label{}` and `\ref{}` in LaTeX, Pandoc's markdown allows the use of **cross-references** in documents.
* The label must be preceded by the type of the object, e.g. `sec-`, `fig-`, `eq-`, `tbl-`.
* `#` is for the label, `@` for the call, including the prefix (Figure, Equation).
```markdown
# Introduction {#sec-introduction}
![The logo of the lab.](img/ai.webp){#fig-logolab width=50%}
$$
\tau \, \dfrac{d r_j(t)}{dt} + r_j(t) = \sum_{i=1}^N w_{i, j} \, r_i (t)^+ + B_j
$$ {#eq-neuron}
@sec-introduction, @fig-logolab, @eq-neuron
```
renders the refs as:
@sec-introduction, @fig-logolab, @eq-neuron
* The prefix (Figure, etc) can be modified in a parameter file, for example for internationalization.
# Bibliography
* Pandoc can use bibtex files to generate the bibliography automatically.
* The path to the bib file and the CSL style can be declared as a variable in the CLI or in the YAML preamble of the file:
```markdown
---
title: Markdown, Pandoc and Quarto
subtitle: a modern ecosystem for typesetting and publishing
author: Julien Vitay
bibliography: references.bib
csl: frontiers.csl
---
@Vitay2015 introduced ANNarchy [@Scholl2022]
```
> @Vitay2015 introduced ANNarchy [@Scholl2022]
* Any citation style can be used when available at <https://citationstyles.org>.
* The references are automatically added at the end of the document.
# Divs
::: columns
::: column
* Divs allow to apply a CSS class or a LaTeX environment on some content.
* Three colons (`:::`) start and stop the div, using curly braces or directly the tag if there is only one.
* Examples with callouts:
```markdown
::: {.callout-note}
Content
:::
or simply
::: callout-warning
Content
:::
```
::: {.callout-note appearance=default}
Content
:::
::: {.callout-warning appearance=default}
Content
:::
:::
::: column
* Two columns (especially for slides)
```markdown
::: columns
::: column
* Content of left column
:::
::: column
* Content of second column
:::
:::
```
* Footer:
```markdown
::: footer
Footer only for this slide
:::
```
::: footer
Footer only for this slide
:::
* Divs are mostly for html, but some are also available for pdf.
:::
:::
# 3 - Quarto
# Quarto
* `pandoc` can convert any `.md` file into any format, but writing the right template can be quite cumbersome.
* [Quarto](https://quarto.org) is a publishing platform based on pandoc that allows to quickly get beautiful websites / books / articles / presentations (reveal.js) ...
* Jupyter notebooks can even be used to generate (live) html pages and pdfs. The quarto file format is `.qmd`.
```{=html}
<iframe width="1500" height="500" src="https://quarto.org/"></iframe>
```
:::footer
<https://quarto.org>
:::
# Python code
* You can call Python / R / Julia code directly from a quarto document, and render the result, such as a Matplotlib plot:
::: columns
::: column
````python
```{{python}}
#| label: fig-polar
#| fig-cap: "A line plot on a polar axis"
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```
````
:::
::: column
```{python}
#| label: fig-polar
#| fig-cap: "A line plot on a polar axis"
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```
:::
:::
# Video extension
* Quarto has extensions to use special (javascript) libraries, e.g. for videos:
{{< video https://youtu.be/wo9vZccmqwc width="1000" aspect-ratio="16x9" >}}
# _quarto.yml
* The configuration of a quarto project can be done in the yaml preamble of a `.qmd` file, or at the project-level in the `_quarto.yml` file:
```yaml
project:
type: website
output-dir: ../docs
website:
title: "Website"
navbar:
background: black
pinned: true
right:
- text: "Slides"
file: slides/presentation.html
- icon: github
href: https://github.com/vitay/quarto-website
aria-label: GitHub
sidebar:
style: "docked"
logo: img/tuc.png
search: true
contents:
- text: "About"
file: index.qmd
- section: "Tutorial"
contents:
- Test.qmd
page-footer:
center: |
Copyright Julien Vitay <julien.vitay@informatik.tu-chemnitz.de> - Chemnitz University of Technology
format:
html:
theme: [sandstone, ../assets/webpage.scss]
page-layout: full
smooth-scroll: true
html-math-method: katex
bibliography: references.bib
csl: ../assets/frontiers.csl
highlight-style: github
code-line-numbers: false
```
# Reveal.js slides
* `Reveal.js` (<https://revealjs.com/>) is a javascript library allowing to create a slide deck in html+css+js.
* `pandoc/quarto` is able to generate reveal.js slides from Markdown files.
* Template at <https://github.com/vitay/quarto-presentation>
```{=html}
<iframe width="1000" height="500" src="https://julien-vitay.net/quarto-presentation"></iframe>
```
# Websites
* Websites are only in html and can comprise multiple pages, with a sidebar and topbar for navigation.
* Template at <https://github.com/vitay/quarto-website>
* Example at <https://github.com/ANNarchy/ANNarchy.github.io> and <https://annarchy.github.io/>
```{=html}
<iframe width="1500" height="600" src="https://annarchy.github.io"></iframe>
```
# Books / theses
* Books are websites with a focus on generating a nice pdf, such as a textbook or a thesis.
* Template at <https://github.com/vitay/quarto-thesis>
* Demo at <https://julien-vitay.net/quarto-thesis> and <https://julien-vitay.net/habilitation>
```{=html}
<iframe width="1500" height="500" src="https://julien-vitay.net/habilitation"></iframe>
```
# Article / reports
* Articles / reports are single documents that can be exported to html and pdf (through LaTeX).
* With the right LaTeX pandoc template, you can submit to any journal and have a html version of it.
* Template at <https://github.com/vitay/quarto-report>
* Demo at <https://julien-vitay.net/quarto-report>
```{=html}
<iframe width="1500" height="500" src="https://julien-vitay.net/quarto-report"></iframe>
```
# Publishing quarto
* `quarto` is html-centric, it generates html files in the `docs/` directory (or anywhere).
* The html pages can be hosted on github for free.
* To visualize a preview:
```bash
quarto preview .
````
* To render the files:
```bash
quarto render .
````
* To push it to github:
```bash
quarto publish gh-pages
```
# References