Session 4: More Quarto for Academics
Tuesday, July 18, 2023
Extensions are a powerful way to modify and extend the behavior of Quarto. Types of extensions include:
Extension Trust
Quarto extensions may execute code when documents are rendered. Therefore, if you do not trust the author of an extension, do not install or use the extension.
Generally safe:
There are a number of ways to include and reuse existing content in Quarto documents. We’ve already covered:
include-in*
YAML options for including LaTex/HTML in header
, before
and after
the body.metadata-files
YAML option for reusing config filesThere’s also:
{{< include _content.qmd >}}
include-code-files
See: quarto.org > Guide > Advanced > Includes
{{< include >}}
shortcode allows you to re-use content across documents.{{< include _snippet.qmd >}}
is equivalent to copying and pasting the text from the _snippet.qmd
file into the main quarto file.Add the shortcode where you want your file to appear:
---
title: "My Document"
---
## Overview
I have some quarto content I want to reuse right here:
{{< include _basics.qmd >}}
## Another Section
More content here...
Files prefixed with underscores (e.g. _basic.qmd
) are ignored when rendering a whole directory of .qmd
files.
Recall that Includes are equivalent to copy and pasting text. Therefore we can also use it to include content from other text based formats (e.g. .txt
, .tex
, .html
, .md
):
Pandoc (and thus Quarto) offers syntax hightlighting in code blocks for over 140 languages, including STATA:
.stata
to the top fence:filename
specifies a name to display above the code lines as shown on the previous slide. This is useful to showing parts of a longer script.Executable R/python code chunks also have syntax highlighting, but don’t have a leading dot:
include-code-files
extensionThe include-code-files
is an Lua Filter extension developed and maintained by the core Quarto team (github.com/quarto-ext) allows you:
To install:
To use the extension add this option to either document or project metadata:
Tip
The include-code-files
extension is already included in the exercises folder.
To use the include-code-files
extension, include the following where you want to display script.do
Which will show the contents of script.do
with syntax highlighting:
You can specify additional options separated by spaces. For example:
```{.stata include="script.do" code-line-numbers="false" filename="script.do"}
```
Note
Currently, not all HTML Code Block options work with the include-code-files
extension (e.g. code-fold
). You may still need to copy and paste code.
day01-exercises
project in Rstudio.replication_in_parts.qmd
.Continue with exercises in replication_in_parts.qmd
15:00