Then the Body: Text Formatting
Quarto uses Pandoc markdown for text formatting. This is a simple, plain text format that is easy to write and read in any text editor.
Duration: 3 hours (180 minutes)
If you want to use GitHub as a Dropbox-like service, you need to commit and push your changes.
main
branch. That should be the case for most of your work..do
, .R
, .m
, .jl
).txt
files, .md.
files, .qmd
files..tex
, .bib
, etc.csv
)
Consider adding a .gitignore
file to your repository to exclude:
.bak
, .swp
, .log
, .aux
).RData
, .pyc
)bib
files for all your references.Is an open-source scientific and technical publishing system
You can use plain text markdown in your favorite editor.
Create dynamic content with Python, R, Julia, and Observable.
Publish reproducible, production quality articles, presentations, dashboards, websites, blogs, and books in HTML, PDF, MS Word, ePub, and more.
Write using Pandoc markdown would allow you to including equations (LaTeX), citations (Zotero), crossrefs, figures panels, callouts, advanced layout, and more.
When you render a .qmd
file with Quarto, the executable code blocks are processed by Jupyter
, and the resulting combination of code, markdown, and output is converted to plain markdown
. Then, this markdown is processed by Pandoc
, which creates the finished
format.
In VSC, create a new file: Quarto
document.
Save it in the folder where you have your data and code.
Add or modify the YAML header for document metadata. This tells Quarto how to render the document, who wrote it, other relevant information.
Document Body: Markdown for text formatting (plain text), with minimal formatting.
You can include images, links, tables, citations, etc. But also code chunks for running and displaying analysis. In some cases (R
), you can also add In-line code for dynamic text
Quarto also has a visual editor option. This is more user-friendly for first timers, and has a more WYSIWYG feel.
It does allow for more advanced features including Citations!
Since Visual Editor is simpler to use, lets cover the basics of using plain text Quarto in VSC.
YAML is not necessary for Quarto, but it is useful for metadata and formatting. It typically would include:
For a template, you can use the following template.qmd
For more options see YAML PDF Options
Quarto uses Pandoc markdown for text formatting. This is a simple, plain text format that is easy to write and read in any text editor.
# Heading 1
## Heading 2
### Heading 3
italics, bold, bold italics
strikeout, code
superscript2, subscript2
Lists:
- Item 1
- Item 2
- Subitem 1
- Subitem 2
Lists:
1. item 4
1. item 5
1. item 5
2. ds
Lists:
Lists:
Quarto supports various types of content for the creation of academic writting.
This include: equations, tables, images, footnotes, references and cross-references.
We will see how to include these in your document.
Quarto supports LaTeX equations. You can include them in your document using the standard LaTeX syntax, for inline equations: $...$
, and for display equations: $$...$$
.
For example, the theory of relativity can be expressed as (\(E=mc^2\))$E=mc^2$
. But also as:
\[E = \frac{{m \cdot c^2}}{{\sqrt{1 - \frac{{v^2}}{{c^2}}}}} \]
Display equations can be cross-referenced. For that you need to add a label to the equation, and then reference it in the text.
For example:
\[E = mc^2 \qquad(1)\]
You can reference this equation as @eq-emc2
which renders Equation 1.
More complex equations can be created using LaTeX syntax.
For Quarto, you can keep track of Tables and Figures. However, you can use “anything” as a figure or table.
The simplest approach is the following:
Quarto will not Care what is the content. A “Table” could be containing a figure, and a “Figure” could be a table.
And you can reference them as @tbl-mytable
and @fig-myfig
. Quarto will take care of the numbering.
You can add tables 4 different ways:
R
, kable
and gt
will render tables in HTML and PDF.Column 1 | Column 2 | Column 3 |
---|---|---|
Data | Data | Data |
Data | Data | Data |
This are notes for the table
Crossreference:
Table 1 shows nothing.
The table is included in table_markdown.txt
and is rendered in the document.
This wont render in HTML, but will render in PDF.
There are two ways to include HTML tables in Quarto:
If you are in a pinch, you can use a figure (from a well formated Excel file) as a table.
When producing tables for PDF, you may notice that tables do not always render where expected.
LaTeX is trying to optimize the layout of the document.
To force a table to render where you want, you can use the tbl-pos="H"
attribute.
As with tables, you can include figures in your document using the following syntax:
:::{#fig-myfig1}
![](transition-git.jpg){width=50% fig-align="center"}
This are notes for the Figure
And this the title
:::
You can use .png
, .jpg
, .svg
, .pdf
, and other image formats, with few restrictions.
Works across all formats.
This are notes for the Figure
::::
Footnotes should not be used excessively, but they can be useful for additional information or references.
To add a footnote, use the following syntax:
This is a footnote[^1]. But this too ^[This is another footnote].
[^1]: This is the text of the footnote.
This is a footnote1. But this too 2.
Quarto supports citations using the @key
syntax. It you cite a reference, it will be included in the bibliography.
First, you need to include a .bib
file with your references in the YAML header.
According to @smith2021
, this citation works. However not everyone likes it [@doe2021]
. However [@smith2021; @doe2021]
works too.
According to Smith (2021), this citation works. However not everyone likes it (Doe 2021). However (Smith 2021; Doe 2021) works too.
If you are using Visual Editor (cntrl+shift+F4
), you can add citations by using cntrl+shift+F8
.
This will open a search box where you can search for the reference you want to cite. And then add it to the text.
Quarto will add the reference.bib
file to the YAML header, and will add the information to the bibliography.
To render your document you have two options:
Press the Botton on the upper right corner of the VSC window. This creates a preview of the document, and you can see how it looks. This also renders one format at a time.
Use the terminal. You can use the terminal to render the document in multiple formats at once.
Just type: quarto render path_name/file.qmd
and it will render the document in the formats specified in the YAML header.
This is one more thing we never really learn, but it is important! Declutter your projects!
Good Organization will make it easy to find things, and to share your work with others.
root-project/
├── data/
│ ├── raw/ <- Depending on size: full raw data or instructions to get it.
│ ├── processed/ <- Stores your cleaned data
│ ├── final/ <- Opt: Stores the final Data for analysis
│ └── doc/ <- Opt: Manuals, dictionaries, codebooks, etc.
├── code/ <- Will contain all code files: Try to keep "Small" files (specific tasks).
│ ├── 01-setup.do <- Setup file (installing packages, setting up directories, etc.)
│ ├── 02-cleaning.do <- Cleaning file (data cleaning and preprocessing)
| ├── 03-analysis.do <- Analysis file (main analysis script)
| ├── 04-visuals.do <- Opt: Visualizations file and (creating plots and figures)
├── results/
│ ├── figures/ <- All the figures you have created.
│ ├── tables/ <- All the tables you have created.
│ └── other/ <- .ster, .log, etc
├── reports/
│ ├── proposal/ <- OPT: Include the proposal and any feedback you have received.
│ ├── papers/ <- May include the Raw tex (Qmd, Tex, bib) and the PDF
│ └── presentations/ <- If you have any presentations, include them here.
└── README.md <- A readme file with instructions on how to understand the project.
ssc
, net
renv
, packrat
, checkpoint
pip
, conda
ssc
or net
to install additional packages.We will go over the repository for a mock-up project, created exclusively for this course.
The repository contains all the elements we have discussed: data, code, documents, and more.
This is a simple example, but it illustrates how you can structure your own projects for reproducibility and transparency.
Assume the project to be a -mock- academic paper. Its not meant to be a real paper.
Repository: https://github.com/friosavila/rm-example
Questions? Feedback?