2  Some demonstration of quarto books

2.1 First, a little markdown guide

Hello and welcome! Markdown is a lightweight markup language with plain-text formatting syntax. It can be converted into HTML and other formats. Here’s a quick demonstration of common markdown features.

You can make text bold by wrapping it with two asterisks or underscores. Italics are just as easy! Wrap text with one asterisk or underscore: Italic Text.

2.1.1 Lists

Creating lists is straightforward. There are unordered lists…

  • Unordered list item 1
  • Unordered list item 2
    • Subitem 2.1
    • Subitem 2.2

…and then there are ordered lists:

  1. A first item
  2. A second item
  3. And a last item

2.1.2 Headers

Headers from H1 to H6 are essential for structure. They’re made with #:

# H1 Header
## H2 Header
### H3 Header

2.1.4 Quotes and Code

Quotes are also a default part of the markdown syntax.

This is a blockquote. Use it to highlight important sections.

And so is code. For inline code, use single backticks: Inline code here For longer code, use triple backticks:

def hello_world():
    print("Hello, world!")

2.1.5 Emojis

To insert emojis, simply type :heart:. Use whatever name the emoji has and it will be rendered correspondingly ❤️ Here, I want to write something else. So that I am 😄!

2.2 Tables

Here’s an example of a markdown table using pipe syntax, representing a list of programming languages and their respective release years:

Table 2.1: We can add a table caption. And a reference.
Programming Language Release Year Creator
Python 1991 Guido van Rossum
JavaScript 1995 Brendan Eich
Java 1995 James Gosling
C++ 1985 Bjarne Stroustrup
Ruby 1995 Yukihiro Matsumoto
Swift 2014 Apple Inc.
Go 2009 Robert Griesemer et al

Feel free to use or modify Table 2.1 as needed!

2.3 Mermaid diagrams

This diagram visualizes the fundamental structure of the product catalog without the junction tables, i.e. containing many-to-many relationships.

erDiagram
  CUSTOMER ||--o{ ORDER : places
  ORDER ||--|{ LINE-ITEM : contains
  PRODUCT ||--|{ LINE-ITEM : includes
  CUSTOMER {
    string id
    string name
    string email
    string phone
  }
  ORDER {
    string id
    string date
    string status
  }
  LINE-ITEM {
    string id
    int quantity
    decimal price
  }
  PRODUCT {
    string id
    string name
    string description
  }
Figure 2.2: Example of a simple entity relationship diagram using Mermaid JS.

Here’s a simple example of a sequence diagram using Mermaid JS. This diagram will illustrate a sequence of interactions between two actors, System A and System B, with a message exchange:

sequenceDiagram
    participant SystemA
    participant SystemB
    
    SystemA ->> SystemB: Message 1
    SystemB -->> SystemA: Response 1
    SystemA ->> SystemB: Message 2
    SystemB -->> SystemA: Response 2
Figure 2.3: Example of a simple sequence diagram using Mermaid JS.

In this sequence diagram: - SystemA and SystemB are the participants (systems) involved in the sequence of interactions. - SystemA ->> SystemB: Message denotes a message sent from SystemA to SystemB. - SystemB -->> SystemA: Response denotes a response message sent from SystemB back to SystemA.

This example shows a simple sequence where SystemA sends two messages (Message 1 and Message 2) to SystemB, and SystemB responds with Response 1 and Response 2 respectively.

2.4 Code files

Below is a simple demo Python code that demonstrates a basic program to calculate the factorial of a number using both iterative and recursive methods:

factorial.py
def factorial_iterative(n):
    """Calculate factorial of a number iteratively."""
    result = 1
    for i in range(1, n + 1):
        result *= i
    return result

def factorial_recursive(n):
    """Calculate factorial of a number recursively."""
    if n == 0:
        return 1
    else:
        return n * factorial_recursive(n - 1)

# Input: Number for which factorial is to be calculated
number = 5

# Calculate factorial using iterative method
iterative_result = factorial_iterative(number)
print(f"Factorial of {number} (iterative): {iterative_result}")

# Calculate factorial using recursive method
recursive_result = factorial_recursive(number)
print(f"Factorial of {number} (recursive): {recursive_result}")

Here’s an explanation for the code above.

  • Iterative Method (factorial_iterative):
    • Initializes result to 1.
    • Loops from 1 to n, multiplying result by the loop counter i in each iteration.
    • Returns the final result.
  • Recursive Method (factorial_recursive):
    • If n is 0, returns 1 (base case).
    • Otherwise, returns n multiplied by the factorial of n-1.
  • Main Program:
    • Defines a variable number to hold the value for which the factorial is to be calculated.
    • Calls the iterative and recursive factorial functions and prints the results.

You can run this code in any Python environment to see the output for the factorial of 5 using both methods.