YYiki: Examples
2025-08-28 → 2025-12-11
Mathematics and Code Examples
This page demonstrates the rich content support in YYiki Static, including mathematical notation and syntax-highlighted code.
Mathematical Expressions
YYiki Static supports KaTeX for beautiful math rendering.
Inline Math
The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ where $a \neq 0$.
Display Math
The Gaussian integral:
$$\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$$
Euler’s identity:
$$e^{i\pi} + 1 = 0$$
Complex Equations
Maxwell’s equations in differential form:
$$\nabla \cdot \mathbf{E} = \frac{\rho}{\epsilon_0}$$
$$\nabla \cdot \mathbf{B} = 0$$
$$\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}$$
$$\nabla \times \mathbf{B} = \mu_0 \mathbf{J} + \mu_0 \epsilon_0 \frac{\partial \mathbf{E}}{\partial t}$$
Code Examples
Python
def fibonacci(n):
"""Generate Fibonacci sequence up to n terms."""
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
fib_sequence = [0, 1]
for i in range(2, n):
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
return fib_sequence
# Example usage
print(fibonacci(10))
# Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
JavaScript
// Async function to fetch data from an API
async function fetchUserData(userId) {
try {
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Failed to fetch user data:', error);
return null;
}
}
// Usage with async/await
(async () => {
const user = await fetchUserData(123);
console.log(user);
})();
Bash
#!/bin/bash
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check for required tools
for tool in git python3 uv; do
if command_exists "$tool"; then
echo "✓ $tool is installed"
else
echo "✗ $tool is not installed"
exit 1
fi
done
echo "All required tools are installed!"
SQL
-- Create a view for active users with their latest posts
CREATE VIEW active_users_latest_posts AS
SELECT
u.id,
u.username,
u.email,
p.title AS latest_post_title,
p.created_at AS latest_post_date
FROM users u
LEFT JOIN LATERAL (
SELECT title, created_at
FROM posts
WHERE user_id = u.id
AND status = 'published'
ORDER BY created_at DESC
LIMIT 1
) p ON true
WHERE u.active = true
AND u.last_login > NOW() - INTERVAL '30 days';
Combining Math and Code
Here’s an example implementing the quadratic formula in Python:
import math
def solve_quadratic(a, b, c):
"""
Solve quadratic equation ax² + bx + c = 0
Returns tuple of solutions or None if no real solutions
"""
if a == 0:
raise ValueError("'a' cannot be zero for a quadratic equation")
discriminant = b**2 - 4*a*c
if discriminant < 0:
return None # No real solutions
elif discriminant == 0:
x = -b / (2*a)
return (x, x) # One solution (repeated root)
else:
sqrt_discriminant = math.sqrt(discriminant)
x1 = (-b + sqrt_discriminant) / (2*a)
x2 = (-b - sqrt_discriminant) / (2*a)
return (x1, x2)
# Example: solve x² - 5x + 6 = 0
solutions = solve_quadratic(1, -5, 6)
print(f"Solutions: {solutions}") # Output: Solutions: (3.0, 2.0)
The discriminant $\Delta = b^2 - 4ac$ determines the nature of the roots: - If $\Delta > 0$: Two distinct real roots - If $\Delta = 0$: One repeated real root - If $\Delta < 0$: No real roots (complex conjugate pairs)