MyST (Markedly Structured Text) is an enhanced markdown syntax specifically designed for technical documentation, particularly useful for programming books and tutorials. It extends standard markdown with powerful features that are especially beneficial for coding resources.
# Chapter Title
## Section Heading
### Subsection
**Bold Text** for important concepts
*Italic Text* for emphasis
`inline code` for code snippets
> Blockquote for important notes or quotes```python
def hello_world():
print("Welcome to Python!")
return None```{code-block} python
:emphasize-lines: 2,3
def complex_function(x, y):
# This line will be highlighted
result = x ** y # Exponentiation
return result```{note}
This is an important concept for beginners to understand!Be careful with mutable default arguments in Python functions!
```{code-block} python
:linenos:
:caption: Simple Calculator Function
def add_numbers(a, b):
"""Add two numbers and return the result."""
return a + b
print(add_numbers(5, 3))See {doc}`control-flow` for more information about conditional statements.The {py:func}`print()` function is used for output.Refer to {cite}`van1995python` for in-depth Python language details.
```{bibliography}```{code-cell} python
# This block can be executed interactively
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x))
plt.title("Sine Wave")
plt.show()- Use clear, descriptive headings
- Leverage code blocks for examples
- Use notes and warnings strategically
- Include inline code references
- Provide context with directives
```{code-block} python
:linenos:
:caption: Student Grade Analyzer
def calculate_grade(score):
"""
Determine letter grade based on numeric score.
:param score: Numeric score between 0 and 100
:return: Letter grade
"""
if score >= 90:
return 'A'
elif score >= 80:
return 'B'
elif score >= 70:
return 'C'
elif score >= 60:
return 'D'
else:
return 'F'
# Example usage
student_scores = [85, 92, 78, 65, 45]
grades = [calculate_grade(score) for score in student_scores]
print(grades)- Jupyter Book
- VS Code with Markdown Preview
- Sphinx documentation generator
Mastering MyST Markdown will help you create professional, interactive, and informative Python programming documentation.