Skip to content

Latest commit

 

History

History
161 lines (121 loc) · 3.43 KB

File metadata and controls

161 lines (121 loc) · 3.43 KB

Markdown Guide for Python Programmers

Introduction to MyST Markdown

What is MyST Markdown?

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.

Basic Markdown Syntax for Python Documentation

Text Formatting

# 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

Code Blocks

Standard Python Code Block

```python
def hello_world():
    print("Welcome to Python!")
    return None

Highlighted Code Blocks

```{code-block} python
:emphasize-lines: 2,3
def complex_function(x, y):
    # This line will be highlighted
    result = x ** y  # Exponentiation
    return result

Advanced MyST Markdown Features

Directives for Technical Documentation

Notes and Warnings

```{note}
This is an important concept for beginners to understand!
Be careful with mutable default arguments in Python functions!

Code Output Demonstration

```{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))

Inline Roles for Technical Writing

Document References

See {doc}`control-flow` for more information about conditional statements.

Inline Code and Syntax Highlighting

The {py:func}`print()` function is used for output.

Citations and Bibliography

Adding Citations

Refer to {cite}`van1995python` for in-depth Python language details.

```{bibliography}

Interactive Elements

Executable Code Blocks

```{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()

Best Practices for Python Documentation

  1. Use clear, descriptive headings
  2. Leverage code blocks for examples
  3. Use notes and warnings strategically
  4. Include inline code references
  5. Provide context with directives

Example of a Comprehensive Code Example

```{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)

Recommended Tools

  • Jupyter Book
  • VS Code with Markdown Preview
  • Sphinx documentation generator

Learning Resources

  1. MyST Markdown Documentation
  2. Sphinx Documentation
  3. Jupyter Book Guide

Conclusion

Mastering MyST Markdown will help you create professional, interactive, and informative Python programming documentation.