Macro Reference

Examples Library

Ready-to-use code examples for LaTeX formulas and Mermaid diagrams. Copy any example into the macro editor and customize it for your use case.


LaTeX Formula Examples

1. Quadratic Formula

The solution to ax^2 + bx + c = 0:

LaTeX source (paste into LaTeX Block macro):

x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

Result: renders the quadratic formula centered on the page.


2. Definite Integral

A common calculus example - the integral of x from 0 to 1:

LaTeX source:

\int_0^1 x^2 \, dx = \left[ \frac{x^3}{3} \right]_0^1 = \frac{1}{3}

Tips:

  • Use \, for thin space before dx
  • Use \left[ and \right] for auto-sized brackets

3. Matrix

A 3×3 identity matrix:

LaTeX source:

\begin{pmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{pmatrix}

Variants:

  • \begin{pmatrix} - parentheses
  • \begin{bmatrix} - square brackets
  • \begin{vmatrix} - vertical bars (determinant)

4. Multi-line Aligned Derivation

Show step-by-step algebra with aligned equals signs:

LaTeX source:

\begin{aligned}
(a + b)^2 &= (a + b)(a + b) \\
          &= a^2 + ab + ba + b^2 \\
          &= a^2 + 2ab + b^2
\end{aligned}

Tips:

  • Use &= to align at the equals sign
  • Use \\\\ for line breaks inside aligned

5. Machine Learning - Precision & Recall

Document ML metrics with labeled equations:

LaTeX source:

\begin{aligned}
\text{Precision} &= \frac{TP}{TP + FP} \\[6pt]
\text{Recall}    &= \frac{TP}{TP + FN} \\[6pt]
F_1               &= 2 \cdot \frac{\text{Precision} \cdot \text{Recall}}{\text{Precision} + \text{Recall}}
\end{aligned}

Tip: \\[6pt] adds extra vertical space between lines.


Mermaid Diagram Examples

6. Flowchart - Decision Process

A simple decision flowchart with styled nodes:

Mermaid source (paste into Diagrams macro):

flowchart TD
    Start([Start]) --> Input[/Receive Request/]
    Input --> Valid{Valid Input?}
    Valid -->|Yes| Process[Process Request]
    Valid -->|No| Reject[Return Error]
    Process --> DB[(Save to DB)]
    DB --> Respond[/Send Response/]
    Reject --> Respond
    Respond --> End([End])

    style Start fill:#E3FCEF,stroke:#00875A
    style End fill:#E3FCEF,stroke:#00875A
    style Reject fill:#FFEBE6,stroke:#DE350B

7. Sequence Diagram - API Authentication

Show a login flow across frontend, API, and database:

Mermaid source:

sequenceDiagram
    participant U as User
    participant F as Frontend
    participant A as API
    participant D as Database

    U->>F: Submit credentials
    F->>A: POST /auth/login
    activate A
    A->>D: SELECT user WHERE email=?
    activate D
    D-->>A: User record
    deactivate D
    A->>A: Verify password hash
    A-->>F: JWT token
    deactivate A
    F->>U: Redirect to dashboard

    Note over U,D: Full authentication flow

8. Entity Relationship Diagram

Model a simple order management schema:

Mermaid source:

erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ ORDER_ITEM : contains
    PRODUCT ||--o{ ORDER_ITEM : "included in"

    CUSTOMER {
        int id PK
        string name
        string email
    }
    ORDER {
        int id PK
        int customer_id FK
        date order_date
        string status
    }
    ORDER_ITEM {
        int id PK
        int order_id FK
        int product_id FK
        int quantity
        float unit_price
    }
    PRODUCT {
        int id PK
        string name
        float price
        int stock
    }

9. Gantt Chart - Project Timeline

Track phases and milestones across a project:

Mermaid source:

gantt
    title Q1 Product Launch Timeline
    dateFormat YYYY-MM-DD
    section Discovery
    Requirements       :done, req, 2024-01-01, 2024-01-10
    Design Review      :done, design, 2024-01-10, 2024-01-20
    section Development
    Backend API        :active, api, 2024-01-20, 2024-02-15
    Frontend UI        :ui, 2024-01-28, 2024-02-20
    section QA
    Testing            :test, 2024-02-15, 2024-03-01
    Bug Fixes          :fix, 2024-03-01, 2024-03-10
    section Launch
    Staging Deploy     :staging, 2024-03-10, 2024-03-15
    Production Release :milestone, prod, 2024-03-15, 1d

Tips for Using Examples

TipDetail
Start with a sampleUse the Samples dropdown in the editor to load a base example
Copy from this libraryPaste any source above into the editor Source panel
Customize incrementallyChange one thing at a time and save to verify rendering
Use the error panelIf something breaks, the red error panel shows what failed
Fullscreen for large diagramsUse the fullscreen viewer control for complex Mermaid charts