open source textbook with Quarto, follow the steps below:
To create an
1: Install Quarto
Step
```sh-g quarto-cli
npm install
```
2: Create a new project
Step
```sh-textbook
quarto create my-textbook
cd my
```
3: Update the `_quarto.yml` configuration file
Step
```yaml"Intro to Psychological Theories"
title: "Your Name"
author:
toc:2
depth: format:
- pdf
- html
- epub
theme:
css: custom.css
accessibility: true
```
4: Create the main table of contents file `toc.yml`
Step
```yaml- chapter1.md
- chapter2.md
- chapter3.md
- bibliography.md
```
5: Create the individual chapters and the bibliography
Step
```sh
touch chapter1.md chapter2.md chapter3.md bibliography.md custom.css
```
6: Fill in the chapter files with content, images, and citations.
Step
in `chapter1.md`:
For example,
```# Chapter 1: Cognitive-Behavioral Therapy {#chap:cognitive-behavioral}
## Introduction
-behavioral therapy (CBT) is a widely-used psychological treatment that focuses on modifying dysfunctional thoughts, emotions, and behaviors[^beck1979]. CBT has been shown to be effective in treating a variety of mental health disorders, such as depression and anxiety[^hofmann2012].
Cognitive
{#fig:cbt-model}
in Figure \@ref(fig:cbt-model), the CBT model posits that our thoughts, emotions, and behaviors are interconnected, and that changing one of these aspects can lead to changes in the others.
As shown
...
## Bibliography
```
7: Add references to the bibliography file `bibliography.md`
Step
```markdown---
references:- id: beck1979
and the emotional disorders
title: Cognitive therapy
author:- family: Beck
given: Aaron T.1979
year:
publisher: International Universities Press
- id: hofmann2012
title: The efficacy of cognitive behavioral therapy
author:- family: Hofmann
given: Stefan G.- family: Asnaani
given: Anu- family: Vonk
given: Imke J. J.- family: Sawyer
given: Alice T.- family: Fang
given: Angela2012
year:
journal: Psychological bulletin138
volume: 6
issue: 964
pages: ---
# Bibliography {-}
(refs)
```
8: Customize the CSS file `custom.css`
Step
```css
body {-family: 'Georgia', serif;
font
}
h1, h2, h3 {#2c3e50;
color:
}
```
9: Build the textbook
Step
```sh
quarto render
```
and EPUB version of your textbook.
This will create a PDF, HTML,
's create 3 assertion tests for the students:
Now, let
1. Test if the table of contents file `toc.yml` has at least 3 chapters:
```pythondef test_toc_has_three_chapters():
with open("toc.yml", "r") as toc_file:
= yaml.load(toc_file, Loader=yaml.SafeLoader)
toc assert len(toc) >= 3
```
2. Test if the bibliography file `bibliography.md` has at least one reference:
```pythondef test_bibliography_has_references():
with open("bibliography.md", "r") as bib_file:
= bib_file.read()
content = re.findall(r"^\s*-\s*id", content, re.MULTILINE)
refs assert len(refs) >= 1
```
3. Test if the `_quarto.yml` configuration file has the required output formats (PDF, HTML, and EPUB):
```pythondef test_output_formats():
with open("_quarto.yml", "r") as config_file:
= yaml.load(config_file, Loader=yaml.SafeLoader)
config assert "pdf" in config["format"]
assert "html" in config["format"]
assert "epub" in config["format"]
```
open source textbook using Quarto, which can be easily updated, maintained, and shared with the community. Quarto can help solve real-world problems in the field of psychological sciences by facilitating the creation of accessible and visually appealing educational materials. These tests can be run using a Python testing framework like `pytest`. With this setup, you have created an
A Conceptual Understanding of Intro to Quarto for Creating Open Source Textbooks
Welcome to this section of the tutorial, where we will dive into the conceptual understanding of Quarto, an innovative tool for creating open source textbooks. As psychological scientists, understanding and sharing knowledge are essential aspects of our work. Quarto can help you create and disseminate your research findings in an accessible and visually appealing way.
What is Quarto?
Quarto is a modern scientific and technical document formatting system that allows you to create documents in various formats, such as HTML, PDF, and even slide presentations. Quarto is designed to be user-friendly and versatile, enabling you to create professional-quality material with minimal effort.
The Building Blocks of Quarto
To better understand how Quarto works, let’s use a metaphor. Imagine you are constructing a house. You have a toolbox filled with different tools, and each tool has a specific purpose. In Quarto, these tools are the different components that come together to create a sophisticated and interactive textbook.
1. The Foundation: Markdown and Code
The foundation of your Quarto “house” is built using Markdown, a lightweight markup language that is easy to read and write. Markdown allows you to add structure and formatting to your text, such as headings, lists, and links, using simple syntax.
In addition to Markdown, you can incorporate code blocks from various programming languages (like Python or R) directly into your document. These code blocks can be executed, and their output (such as data visualizations or statistical analyses) can be displayed within the textbook. This interactive aspect allows readers to better understand and engage with your content.
2. The Framework: YAML Metadata
After laying the foundation, you need to construct the framework of your house. In Quarto, this is achieved using YAML (Yet Another Markup Language) metadata. YAML metadata controls various aspects of your document, such as its title, author information, and the output format. By specifying these details in the YAML header, you have a solid structure to build upon.
3. The Walls: Content Organization
The walls divide the space in your house, creating separate rooms for different purposes. Similarly, Quarto allows you to divide and organize your content using sections and subsections. This helps you create a logical and easy-to-follow structure for your textbook. You can also add cross-references, footnotes, and citations to enhance the readability and context of your content.
4. The Decoration: Themes and Styles
Once the foundation, framework, and walls are in place, you can decorate your house to make it visually appealing. In Quarto, this is accomplished using themes and styles. You can choose from a variety of built-in themes or create your own custom theme to match your branding or preferences. You can also incorporate custom CSS to fine-tune the appearance of your textbook, such as fonts, colors, and layout.
5. The Final Touch: Interactive Elements
The final touch in building your Quarto “house” is adding interactive elements that engage and educate your readers. Quarto supports the integration of various interactive components, such as videos, quizzes, and interactive data visualizations. These elements help make your textbook more dynamic and engaging, allowing readers to actively participate in the learning process.
Conclusion
By understanding the conceptual framework of Quarto, you now have a solid foundation for creating open source textbooks that are both informative and visually appealing. By combining Markdown, YAML metadata, content organization, themes, styles, and interactive elements, you can create a professional-quality textbook that effectively shares your knowledge with the psychological science community.
A Concrete Understanding of the Syntax of Intro to Quarto for Creating Open Source Textbooks
In this section, we will dive into the syntax of Quarto by dissecting an example. This will provide you with a clear understanding of how to create open-source textbooks using Quarto.
Example of Quarto Syntax
Here is a sample Quarto document that includes various elements commonly used in creating open source textbooks:
---
title: "An Introduction to Psychological Sciences"
author: "John Doe"
date: "`r Sys.Date()`"
output: html_document
---
# Chapter 1: Research Methods in Psychological Sciences
## Section 1.1: Experimental Research
Experimental research is a method that aims to establish a cause-and-effect relationship between variables.
### Advantages of Experimental Research
1. Control over variables
2. High internal validity
3. Allows for establishing causal relationships
### Disadvantages of Experimental Research
1. Limited external validity
2. Ethical concerns
3. Practical limitations
## Section 1.2: Observational Research
In observational research, the researcher observes and records the behavior of interest.
### Types of Observational Research
- Naturalistic Observation
- Participant Observation
- Structured Observation
# Chapter 2: Biological Bases of Behavior
## Section 2.1: The Nervous System
The nervous system is divided into two main parts:
1. Central Nervous System (CNS)
2. Peripheral Nervous System (PNS)
### Central Nervous System
The CNS consists of the brain and spinal cord. It is responsible for processing information and controlling behavior.
### Peripheral Nervous System
The PNS connects the CNS to the rest of the body. It is divided into two parts:
1. Somatic Nervous System
2. Autonomic Nervous System
## Section 2.2: The Brain
The brain is the central organ of the human nervous system.
### Major Structures of the Brain
- Cerebrum
- Cerebellum
- Brainstem
### Functions of the Brain
1. Sensory processing
2. Motor control
3. Emotion regulation
4. Cognitive functions
Understanding the Syntax
Now, let’s break down the above example to understand the syntax of Quarto.
YAML Metadata
At the very beginning of the document, the YAML metadata block is enclosed within triple-dashed lines (---
). This block contains important information about the document, such as the title, author, and output format.
---
title: "An Introduction to Psychological Sciences"
author: "John Doe"
date: "`r Sys.Date()`"
output: html_document
---
Headers
Headers are used to create chapters, sections, and subsections. They are denoted by one or more hash symbols (#
), followed by a space and the header text. The number of hash symbols corresponds to the header level (e.g., #
for chapter, ##
for section, and ###
for subsection).
# Chapter 1: Research Methods in Psychological Sciences
## Section 1.1: Experimental Research
### Advantages of Experimental Research
Lists
Ordered (numbered) and unordered (bullet point) lists can be created using hyphens (-
) or numbers followed by a period (1.
), respectively.
### Advantages of Experimental Research
1. Control over variables
2. High internal validity
3. Allows for establishing causal relationships
### Types of Observational Research
- Naturalistic Observation
- Participant Observation
- Structured Observation
Conclusion
By understanding the syntax of Quarto, you can create well-structured open-source textbooks with ease. The example provided in this section demonstrates how to use headers, lists, and metadata in a Quarto document. Experiment with these elements and explore additional Quarto features to create more complex and interactive textbooks.
Example 1: Creating an Open Source Textbook on Psychological Research Methods with Quarto
In this example, let’s create an open-source textbook on Psychological Research Methods using Quarto. We’ll use the following structure for our textbook:
- Introduction
- Experimental Design
- Data Collection
- Data Analysis
- Reporting Results
First, we will install the necessary packages and create our project structure. To do this, open your terminal, and run the following commands:
# Install Quarto
pip install quarto
# Create a new directory for your project
mkdir psych_research_methods
cd psych_research_methods
# Initialize the Quarto project
quarto init
Now, create individual markdown files for each chapter:
touch 01-introduction.qmd
touch 02-experimental_design.qmd
touch 03-data_collection.qmd
touch 04-data_analysis.qmd
touch 05-reporting_results.qmd
Edit _quarto.yml
to include these files in the correct order:
toc:
- 01-introduction.qmd
- 02-experimental_design.qmd
- 03-data_collection.qmd
- 04-data_analysis.qmd
- 05-reporting_results.qmd
Now you can start writing the content of each chapter in the respective markdown files. For instance, in 01-introduction.qmd
, you might write:
# Introduction
Psychological research methods are the backbone of psychological science. In this textbook, we will provide an overview of the most common research methods used in the field, along with practical examples and guidelines for implementing them.
Throughout this textbook, we will cover the following topics:
1. Experimental Design
2. Data Collection
3. Data Analysis
4. Reporting Results
By the end of this textbook, you should have a solid foundation in psychological research methods and be ready to conduct your own studies.
As you write the content, you can use various markup elements to format the text, add images, tables, and even embed code blocks with interactive examples.
For instance, if you want to include an example of a within-subjects experimental design in the 02-experimental_design.qmd
file, you can do this:
# Experimental Design
## Within-Subjects Design
A within-subjects design is a type of experimental design in which each participant experiences all levels of the independent variable. This design is particularly useful for reducing the impact of individual differences among participants.
### Example
Imagine an experiment investigating the effects of background noise (independent variable) on reading comprehension (dependent variable). There are two levels of background noise: quiet and noisy. In a within-subjects design, each participant would read two passages, one in a quiet environment and one in a noisy environment.
Here's a simple representation of this design:
| Participant | Condition 1: Quiet | Condition 2: Noisy |
|-------------|--------------------|--------------------|
| 1 | Passage A | Passage B |
| 2 | Passage B | Passage A |
In this example, we counterbalance the order of the passages to control for potential order effects.
After you have written the content for all chapters, you can build your open-source textbook by running the following command in the terminal:
quarto render
This will create a _site
directory containing the HTML files for your textbook. You can now host your textbook online using a service like GitHub Pages or Netlify.
Example 2: Incorporating Interactive Visualizations with Quarto and Altair
In this example, let’s demonstrate how to create an interactive visualization using Altair, a Python library for declarative data visualization, in a Quarto document.
First, you’ll need to install the Altair library:
pip install altair
Now, let’s say we want to create an interactive scatterplot to visualize the relationship between age and income for a dataset in the 03-data_collection.qmd
file. Add the following code block:
--- {code-cell} python
import altair as alt
import pandas as pd
# Create a sample dataset
= pd.DataFrame({
data 'age': [25, 30, 35, 40, 45, 50, 55, 60, 65, 70],
'income': [35000, 40000, 45000, 55000, 60000, 65000, 70000, 75000, 80000, 85000]
})
# Create an interactive scatterplot
= alt.Chart(data).mark_circle(size=60).encode(
scatterplot ='age',
x='income',
y=['age', 'income']
tooltip
).interactive()
# Display the scatterplot
scatterplot
With this code, you’ve created an interactive
Programming Problem: Creating an Open Source Textbook with Quarto
As a member of the Society for the Improvement of Psychological Sciences, you have been tasked with creating an open source textbook to help students learn about various psychological theories and their applications. Your goal is to create a well-structured and visually appealing textbook that can be easily updated, maintained, and shared with the community.
Using Quarto, create a textbook that includes the following features:
A main table of contents that lists all the chapters and their respective sections.
At least three chapters, each covering a different psychological theory (e.g., cognitive-behavioral therapy, psychoanalysis, and humanistic psychology). Each chapter should have an introduction, a brief history of the theory, its main principles, and a conclusion.
Each chapter should include relevant images, diagrams, or other visual aids to enhance the learning experience.
Include a bibliography at the end of the textbook, listing all the sources used for each chapter.
Make use of Quarto’s cross-referencing capabilities to reference figures, tables, and sections within the textbook.
Use Quarto’s citation capabilities to properly cite the sources used in the textbook.
Create the textbook in such a way that it can be easily converted to multiple output formats (e.g., PDF, EPUB, and HTML).
Incorporate a consistent and attractive design throughout the textbook, making use of Quarto’s theming options and CSS customizations.
Ensure that the textbook is accessible to readers with disabilities, following best practices for accessibility and utilizing Quarto’s accessibility features.
Once you have completed the textbook, share it with your peers for feedback and make any necessary revisions. Discuss how the use of Quarto for creating open source textbooks can help solve real-world problems in the field of psychological sciences.