-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquarto-guide.qmd
More file actions
executable file
·755 lines (557 loc) · 13.8 KB
/
quarto-guide.qmd
File metadata and controls
executable file
·755 lines (557 loc) · 13.8 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
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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
---
title: "Quarto Guide for Beginners"
subtitle: "Everything you need to know to get started with Quarto"
author: "Documentation Team"
date: today
format:
html:
toc: true
toc-depth: 3
code-fold: false
code-tools: true
---
## What is Quarto?
**Quarto** is an open-source scientific and technical publishing system built on Pandoc. It allows you to create dynamic documents that combine:
- **Narrative text** (written in Markdown)
- **Code** (Python, R, Julia, Observable JS)
- **Code outputs** (plots, tables, results)
- **Equations, citations, cross-references**
Think of Quarto as a powerful tool to create everything from simple documents to complex websites, presentations, and books.
### Key Benefits
- **Multiple outputs from one source** - Write once, publish to HTML, PDF, Word, PowerPoint
- **Language agnostic** - Works with Python, R, Julia, and more
- **Reproducible** - Code and narrative in the same document
- **Professional** - Publication-quality output
## File Types and Formats
### Source Files
#### .qmd Files (Quarto Markdown)
The primary file type for Quarto documents:
```markdown
---
title: "My Document"
format: html
---
## Introduction
This is a Quarto document with **markdown** formatting.
```{python}
# You can include code
print("Hello from Python!")
```
```
#### .ipynb Files (Jupyter Notebooks)
Quarto can directly render Jupyter notebooks:
- Keep your existing notebook workflow
- Add Quarto features through cell metadata
- Render notebooks to any format
#### .md Files (Plain Markdown)
Standard Markdown files can be rendered by Quarto, though they lack code execution capabilities.
### Output Formats
Quarto can generate:
| Format | Extension | Use Case |
|--------|-----------|----------|
| HTML | .html | Websites, interactive documents |
| PDF | .pdf | Print publications, reports |
| Word | .docx | Microsoft Word documents |
| PowerPoint | .pptx | Presentations |
| Reveal.js | .html | Interactive HTML presentations |
| EPUB | .epub | E-books |
| Markdown | .md | GitHub, other platforms |
## Creating Different Types of Documents
### Basic Document
Simplest Quarto document:
```yaml
---
title: "My First Document"
author: "Your Name"
date: today
format: html
---
## Section 1
Content goes here.
```
### Multi-Format Document
Output to multiple formats:
```yaml
---
title: "Multi-Format Document"
format:
html:
toc: true
code-fold: true
pdf:
documentclass: article
docx:
reference-doc: template.docx
---
```
### Presentation (PowerPoint)
```yaml
---
title: "My Presentation"
format:
pptx:
slide-level: 2
---
# Section Title
## Slide 1
- First point
- Second point
## Slide 2
More content here.
```
**Important:** Level 1 headers (`#`) create section dividers, Level 2 headers (`##`) create new slides.
### Presentation (Reveal.js)
```yaml
---
title: "Interactive Presentation"
format:
revealjs:
theme: dark
transition: slide
---
```
### Website/Book
Requires a `_quarto.yml` configuration file (covered below).
## YAML Front Matter
Every `.qmd` file starts with YAML front matter between `---` markers. This controls document behavior.
### Essential YAML Options
```yaml
---
title: "Document Title" # Required
subtitle: "Optional subtitle" # Optional
author: "Author Name" # Optional
date: today # or "2024-01-15"
format: html # Output format
---
```
### Format-Specific Options
#### HTML Options
```yaml
format:
html:
toc: true # Table of contents
toc-depth: 3 # How many header levels
code-fold: false # Collapsible code
code-tools: true # Code display options
theme: cosmo # Visual theme
css: styles.css # Custom CSS
```
#### PDF Options
```yaml
format:
pdf:
documentclass: article
geometry:
- margin=1in
toc: true
number-sections: true
```
#### PowerPoint Options
```yaml
format:
pptx:
reference-doc: template.pptx # Custom template
slide-level: 2 # Which heading creates slides
incremental: true # Bullets appear one by one
```
## The _quarto.yml Configuration File
The `_quarto.yml` file controls **project-level settings** for websites and books.
### Basic Website Configuration
```yaml
project:
type: website
website:
title: "My Website"
navbar:
left:
- href: index.qmd
text: Home
- href: about.qmd
text: About
```
### Sidebar Navigation
For documentation sites with a sidebar:
```yaml
website:
sidebar:
style: "docked"
search: true
contents:
- href: index.qmd
text: Welcome
- section: "Getting Started"
contents:
- guide1.qmd
- guide2.qmd
- section: "Advanced"
contents:
- advanced1.qmd
```
### Adding Files to Navigation
#### Adding a Single Document
```yaml
website:
sidebar:
contents:
- href: new-document.qmd
text: "Display Name"
```
#### Adding a Section with Multiple Documents
```yaml
website:
sidebar:
contents:
- section: "Section Name"
contents:
- doc1.qmd
- doc2.qmd
- text: "Custom Name"
href: doc3.qmd
```
#### Adding External Links
```yaml
website:
sidebar:
tools:
- icon: github
href: https://github.com/your/repo
text: "GitHub"
```
### Global Format Settings
Apply settings to all documents:
```yaml
format:
html:
theme: cosmo
css: styles.css
toc: true
code-copy: true
```
## Working with Code
### Code Blocks
````markdown
```python
# Python code
import pandas as pd
data = pd.read_csv('file.csv')
print(data.head())
```
````
### Executable vs. Non-Executable Code
By default, code blocks in `.qmd` files are **executable**. To display code without running:
````markdown
```{python}
#| eval: false
# This code is shown but not executed
```
````
### Inline Code
Execute code inline: `` `{python} 2 + 2` ``
Output: 4
### Code Options
```python
#| echo: false # Hide code, show output
#| eval: false # Show code, don't run
#| warning: false # Hide warnings
#| message: false # Hide messages
#| label: fig-plot # For cross-references
#| fig-cap: "Caption" # Figure caption
```
## Markdown Essentials
### Headers
```markdown
# Level 1
## Level 2
### Level 3
```
### Text Formatting
```markdown
**bold**
*italic*
***bold italic***
`code`
~~strikethrough~~
```
### Lists
```markdown
- Unordered list
- Second item
- Nested item
1. Ordered list
2. Second item
1. Nested item
```
### Links and Images
```markdown
[Link text](https://url.com)

{#fig-id width=50%}
```
### Tables
```markdown
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| Data 1 | Data 2 | Data 3 |
| Data 4 | Data 5 | Data 6 |
```
### Cross-References
```markdown
See @fig-plot for details.
{#fig-plot}
See @tbl-results for the data.
| Col 1 | Col 2 |
|-------|-------|
| A | B |
: Results {#tbl-results}
```
## Rendering Documents
### Command Line
```bash
# Render a single document
quarto render document.qmd
# Render to specific format
quarto render document.qmd --to pdf
# Render entire project
quarto render
# Preview with live reload
quarto preview
# Publish
quarto publish gh-pages
```
### From RStudio or VS Code
- **RStudio**: Click the "Render" button
- **VS Code**: Click "Preview" or use the Quarto extension
### Render Options
Control rendering in YAML:
```yaml
execute:
echo: true # Show code
warning: false # Hide warnings
error: true # Show errors
cache: true # Cache results
```
## Special Features
### Callout Blocks
```markdown
::: {.callout-note}
This is a note callout.
:::
::: {.callout-warning}
This is a warning!
:::
::: {.callout-important}
This is important information.
:::
```
### Tabsets
```markdown
::: {.panel-tabset}
## Tab 1
Content for tab 1
## Tab 2
Content for tab 2
:::
```
### Columns Layout
```markdown
::: {.columns}
::: {.column width="50%"}
Left column content
:::
::: {.column width="50%"}
Right column content
:::
:::
```
### Diagrams (Mermaid)
````markdown
```{mermaid}
graph LR
A[Start] --> B[Process]
B --> C[End]
```
````
## What Quarto Cannot Do
### Limitations
1. **No Real-Time Collaboration**
- Not like Google Docs
- Use Git for version control instead
2. **Limited WYSIWYG**
- Must render to see final output
- Not a visual editor (though RStudio has visual mode)
3. **LaTeX Required for PDF**
- Must install LaTeX distribution for PDF output
- Can be large download (several GB)
4. **Code Must Be Installed**
- Python/R/Julia must be installed separately
- Need required packages installed
5. **No Dynamic Forms**
- Cannot create user input forms in HTML output
- Use Shiny for interactive applications
6. **Processing Speed**
- Large projects can be slow to render
- Use caching to speed up
7. **Not a Database**
- Cannot query data directly in document
- Must load data first with code
8. **Limited Styling Control**
- HTML/CSS knowledge needed for custom designs
- PDF styling requires LaTeX knowledge
## Best Practices
### Project Organization
```
my-project/
├── _quarto.yml # Project config
├── index.qmd # Homepage
├── guide1.qmd # Content files
├── guide2.qmd
├── images/ # Images folder
│ ├── logo.png
│ └── diagram.svg
├── data/ # Data folder
│ └── dataset.csv
├── scripts/ # Helper scripts
│ └── utils.py
└── _site/ # Generated output (don't edit)
```
### File Naming
- Use lowercase, hyphens for spaces: `my-document.qmd`
- Be descriptive: `serverless-monitoring.qmd` not `doc1.qmd`
- Group related files: `tutorial-1.qmd`, `tutorial-2.qmd`
### YAML Best Practices
```yaml
---
# Put most important info first
title: "Clear, Descriptive Title"
subtitle: "Helpful subtitle"
author: "Author Name"
date: today
# Group related options
format:
html:
toc: true
theme: cosmo
# Use comments
execute:
echo: true # Show code by default
---
```
### Code Best Practices
1. **Use meaningful labels**: `{#fig-scatter}` not `{#fig-1}`
2. **Set global options** in YAML instead of repeating
3. **Cache expensive computations**: `cache: true`
4. **Organize code** into separate scripts if complex
5. **Test frequently** - render often to catch errors early
## Common Issues and Solutions
### Issue: "File not found"
**Problem:** Referenced image or data file not found
**Solution:** Use relative paths from the `.qmd` file location
```markdown
# Good

# Bad (absolute paths break portability)

```
### Issue: Code not executing
**Problem:** Code block shown but not running
**Solution:** Check code block syntax
````markdown
# Correct (with braces)
```{python}
print("Hello")
```
# Wrong (no braces - just displays)
```python
print("Hello")
```
````
### Issue: Links not working in rendered site
**Problem:** Cross-references broken after rendering
**Solution:** Use `.qmd` extension in links - Quarto converts automatically
```markdown
# Correct
[See guide](guide.qmd)
# Incorrect
[See guide](guide.html)
```
### Issue: Changes not showing
**Problem:** Made changes but don't see them in preview
**Solution:**
- Refresh browser (hard refresh: Cmd+Shift+R or Ctrl+Shift+R)
- Stop and restart `quarto preview`
- Check if file is saved
### Issue: Table of contents not showing
**Problem:** TOC enabled but not visible
**Solution:** Need at least 2 headers for TOC to appear
```markdown
---
format:
html:
toc: true
---
## First Section
Content
## Second Section
More content
```
## Quick Reference
### Common Quarto Commands
```bash
quarto render # Render project
quarto render file.qmd # Render single file
quarto preview # Live preview
quarto create project # New project wizard
quarto check # Check installation
quarto --help # Help
```
### Common YAML Settings
```yaml
title: "Title"
author: "Name"
date: today
format: html
toc: true
number-sections: true
code-fold: true
theme: cosmo
```
### Format Options Quick Reference
```yaml
# Multiple formats
format:
html: default
pdf: default
docx: default
# Or with options
format:
html:
theme: cosmo
pdf:
documentclass: article
```
## Next Steps
### Learning Resources
- **Official Docs**: [https://quarto.org/docs/guide/](https://quarto.org/docs/guide/)
- **Gallery**: [https://quarto.org/docs/gallery/](https://quarto.org/docs/gallery/)
- **Examples**: Browse `_site/` in this project for rendered examples
### Practice Exercises
1. Create a simple `.qmd` document with text and headers
2. Add a code block that creates a simple plot
3. Render to HTML, PDF, and Word
4. Create a presentation with 5 slides
5. Add your document to the website navigation
### Getting Help
- Check the [Quarto documentation](https://quarto.org)
- Search [GitHub Issues](https://github.com/quarto-dev/quarto-cli/issues)
- Ask on [Quarto Discussions](https://github.com/quarto-dev/quarto-cli/discussions)
---
## Summary
**Quarto is powerful** for creating reproducible, multi-format documents. Key takeaways:
✅ **Files**: Create `.qmd` files with YAML + Markdown + Code
✅ **Formats**: Output to HTML, PDF, Word, PowerPoint, and more
✅ **Configuration**: Use `_quarto.yml` for project-level settings
✅ **Navigation**: Add files to sidebar in `_quarto.yml`
✅ **Rendering**: Use `quarto render` or IDE buttons
✅ **Limitations**: Know what Quarto can't do (real-time collab, dynamic forms)
✅ **Best Practices**: Organize files, use clear names, test often
**Ready to create?** Start with a simple document and experiment!