This guide explains how to use MkDocs to build and serve the documentation locally.
MkDocs is a fast, simple static site generator that's geared towards building project documentation. It takes your markdown documentation files and generates a beautiful, searchable static website.
- Python 3.7 or higher
- pip (Python package manager)
# Install MkDocs with Material theme
pip install mkdocs-material
# Install additional plugins
pip install mkdocs-minify-pluginOr install all at once with the recommended setup:
pip install mkdocs-material mkdocs-minify-plugin pymdown-extensions# Create virtual environment
python -m venv venv
# Activate (Linux/Mac)
source venv/bin/activate
# Activate (Windows)
venv\Scripts\activate
# Install dependencies
pip install mkdocs-material mkdocs-minify-plugin pymdown-extensionsBuild and serve the documentation with live reload:
mkdocs serveThis will start a development server at http://127.0.0.1:8000/ where you can preview the documentation. The server automatically reloads when you make changes to the markdown files.
Options:
# Serve on a different port
mkdocs serve -a localhost:8080
# Serve on all network interfaces
mkdocs serve -a 0.0.0.0:8000
# Enable verbose mode
mkdocs serve --verboseGenerate static HTML files:
mkdocs buildThis creates a site/ directory containing the complete static website.
Options:
# Build with verbose output
mkdocs build --verbose
# Clean build (remove old files first)
mkdocs build --clean
# Build to custom directory
mkdocs build --site-dir custom-outputDeploy documentation directly to GitHub Pages:
mkdocs gh-deployThis builds the documentation and pushes it to the gh-pages branch of your repository.
Options:
# Deploy with custom commit message
mkdocs gh-deploy --message "Update documentation"
# Force push (use with caution)
mkdocs gh-deploy --forceThe documentation is configured in mkdocs.yml at the repository root. Key sections:
site_name: scala-au.id.cxd.math Documentation
site_description: 'A comprehensive Scala library...'
site_author: 'cxd'
site_url: 'https://cxd.github.io/scala-au.id.cxd.math/'The documentation uses the Material for MkDocs theme with:
- Light and dark mode support
- Navigation tabs and sections
- Search functionality
- Code syntax highlighting
- Math equation rendering (MathJax)
The navigation menu is defined in the nav section:
nav:
- Home: Home.md
- Getting Started:
- Installation & Setup: Getting-Started.md
- Quick Start Examples: Quick-Start-Examples.md
# ... more sections- Create a new markdown file in
wiki-docs/ - Add it to the
navsection inmkdocs.yml:
nav:
- Your New Page: Your-New-Page.mdCustom CSS is located in wiki-docs/stylesheets/extra.css. Add your styles there.
Custom JavaScript is in wiki-docs/javascripts/mathjax.js. The MathJax configuration is already set up for rendering mathematical formulas.
Install the plugin and add it to the plugins section in mkdocs.yml:
plugins:
- search
- your-plugin-nameYou can include mathematical equations using LaTeX syntax:
Inline math:
The formula \(E = mc^2\) is famous.Display math:
The normal distribution PDF is:
\[
f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}
\]Syntax highlighting is automatic:
```scala
val normal = Normal(mu = 0.0, sigma = 1.0)
val prob = normal.cdf(1.96)
```Create styled info boxes:
!!! note
This is a note.
!!! warning
This is a warning.
!!! tip
This is a tip.Keep mkdocs serve running while editing for instant preview of changes.
MkDocs will warn you about:
- Broken internal links
- Missing files
- Invalid configuration
The search functionality is automatically built and works offline in the static site.
The Material theme is fully responsive and works great on mobile devices.
If port 8000 is busy:
mkdocs serve -a localhost:8001Check for:
- Invalid YAML in
mkdocs.yml - Missing markdown files referenced in
nav - Broken internal links
Enable verbose mode for details:
mkdocs build --verboseInstall Material theme:
pip install mkdocs-materialEnsure MathJax is loaded in mkdocs.yml:
extra_javascript:
- javascripts/mathjax.js
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.jsCreate .github/workflows/docs.yml:
name: Deploy Documentation
on:
push:
branches:
- main
paths:
- 'wiki-docs/**'
- 'mkdocs.yml'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install dependencies
run: |
pip install mkdocs-material
pip install mkdocs-minify-plugin
- name: Deploy to GitHub Pages
run: mkdocs gh-deploy --force# Install
pip install mkdocs-material mkdocs-minify-plugin
# Preview locally
mkdocs serve
# Build static site
mkdocs build
# Deploy to GitHub Pages
mkdocs gh-deploy
# Get help
mkdocs --help
mkdocs serve --help
mkdocs build --help