Using Quarto for Notes and Code

blog
quarto
Author

Yiming Lin

Published

2023-08-26

Inspired by Hamel’s twitter, I am exploring Quarto for compiling my notes into a static website on Github Pages. Some of the features I like about Quarto are:

  1. Flexible Markup: Quarto seamlessly supports both Jupyter Notebooks and Quarto Markdown, providing an optimal environment for crafting intricate technical notes.

  2. Unified Composition: Embracing the essence of literate programming, Quarto empowers you to interweave code and text within a single file. This fusion of elements transpires without the need to forsake the familiarity of your preferred integrated development environment.

  3. Sleek Code Folding: The HTML output generated by Quarto boasts a code folding functionality that proves invaluable for managing lengthy code blocks, ensuring a more organized and digestible reading experience.

  4. Dynamic Code Execution: Quarto’s prowess extends to executing code within the HTML output. This dynamic capability not only facilitates interactive plot creation but also maintains a seamless correspondence between the code itself and its resulting output.

  5. Scholarly Support: With built-in compatibility for LaTeX and seamless integration of citations, Quarto emerges as an exceptional tool for the composition of academic papers.

Code Folding and Dynamic Code Execution

Figure 1 shows a line plot on a polar axis using the foldable code block feature. The code is executed when the post is rendered. This is ideal for keeping the code snippet and the output in the same file.

Code
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()

Figure 1: A line plot on a polar axis
Below is the original tweet from Hamel and the source of inspiration. Shout out to Hamel for sharing his experience with Quarto.

Citation

BibTeX citation:
@online{lin2023,
  author = {Lin, Yiming},
  title = {Using {Quarto} for {Notes} and {Code}},
  date = {2023-08-26},
  url = {https://yiminglin-ai.github.io//blog/posts/post-with-code},
  langid = {en}
}
For attribution, please cite this work as:
Lin, Yiming. 2023. “Using Quarto for Notes and Code.” August 26, 2023. https://yiminglin-ai.github.io//blog/posts/post-with-code.