Hello World
A quick tour of what's possible with MDX and Next.js
This is my first blog post using MDX and Next.js.
What is MDX?
MDX lets you use JSX in your markdown content. You can import components and export metadata.
Here's some example code:
function greeting(name) {
return `Hello, ${name}!`;
}Syntax Highlighting Demo
Here are snippets in Python, TypeScript, and Rust:
def fibonacci(n: int) -> list[int]:
"""Generate the first n Fibonacci numbers."""
if n <= 0:
return []
sequence = [0, 1]
while len(sequence) < n:
sequence.append(sequence[-1] + sequence[-2])
return sequence[:n]
print(fibonacci(10))interface User {
id: string;
name: string;
email: string;
}
async function fetchUser(id: string): Promise<User | null> {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) return null;
return response.json();
}fn main() {
let numbers: Vec<i32> = (1..=10).collect();
let squared: Vec<i32> = numbers.iter().map(|x| x * x).collect();
println!("Squared: {:?}", squared);
}You can also use React components directly in your MDX:
Interactive Components
MDX also supports interactive React components. Here's a counter to prove it works:
Count: 0
Custom MDX Components
This blog includes several custom components to enhance content.
Callout Boxes
Use callouts to highlight important information:
This is an informational callout. Great for tips and extra context.
This is a warning callout. Use it to alert readers about potential issues.
Pro tip: You can customize the title by passing the title prop.
A simple note for additional context that doesn't need special emphasis.
Collapsible Sections
Use collapsible sections for optional details:
This content is hidden by default. It's useful for:
- Long explanations that might overwhelm readers
- Optional configuration details
- Advanced topics for interested readers
Here's some code inside a collapsible:
const config = {
theme: 'dark',
language: 'en'
};Code Copy Button
Hover over any code block to see the copy button appear in the top-right corner. Try it on the code blocks above!
Math with KaTeX
Write math inline like or , or use display mode for larger equations:
The quadratic formula:
Matrices work too:
Sidenotes
Sidenotes are great for tangential information that doesn't interrupt the main flow.*On large screens, I appear in the margin. On smaller screens, tap the asterisk to expand. They're commonly used in academic writing and technical documentation to provide additional context without breaking the reader's focus.
Edward Tufte popularized this style in his books on data visualization.*Tufte's "The Visual Display of Quantitative Information" is a classic in the field. The idea is that readers can choose to engage with supplementary material without losing their place in the main text.
Citations
For academic references, use the citation system. You can cite inline: Vaswani et al. (2017) introduced the transformer architecture. Or use parenthetical style: The transformer revolutionized NLP (Vaswani et al., 2017).
A references section automatically appears at the end of the post.
Footnotes
For more traditional references, use footnotes.[1] They work well for citations, sources, and longer explanations that would be too disruptive as sidenotes.[2]
You can reference the same source multiple times throughout your text, and readers can jump between the reference and the footnote section at the bottom.
Footnotes
Footnotes have been used in scholarly writing since at least the 12th century, though their modern form emerged with the printing press.
↩The choice between sidenotes and footnotes often comes down to content length and reader preference. Sidenotes work best for brief asides, while footnotes are better for longer explanations or formal citations.
↩References
- Vaswani, Shazeer, Parmar, Uszkoreit, Jones, Gomez, Kaiser, & Polosukhin (2017). Attention Is All You Need. NeurIPS.