LaTeX

Claude:

1. 数学公式测试

行内公式

这是一个简单的行内公式 \(E = mc^2\),以及更复杂的 \(\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}\)

块级公式

傅里叶变换:

\[ \mathcal{F}(\omega) = \int_{-\infty}^{\infty} f(t) e^{-i\omega t} dt \]

麦克斯韦方程组:

\[ \begin{align} \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} \end{align} \]

矩阵运算:

\[ \begin{pmatrix} a & b \\ c & d \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} ax + by \\ cx + dy \end{pmatrix} \]

分段函数:

\[ f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x^2 & \text{if } x < 0 \end{cases} \]

求和与极限:

\[ \lim_{n \to \infty} \sum_{i=1}^{n} \frac{1}{n^2 + i^2} = \frac{\pi}{4} \]

复杂积分:

\[ \oint_C \frac{e^z}{z(z-1)} dz = 2\pi i \left(\text{Res}_{z=0} + \text{Res}_{z=1}\right) \]

2. 代码块测试

C++ 代码示例

#include <iostream>
#include <vector>
#include <algorithm>

template<typename T>
class SmartPointer {
private:
    T* ptr;
    size_t* ref_count;

public:
    explicit SmartPointer(T* p = nullptr) 
        : ptr(p), ref_count(new size_t(1)) {}

    ~SmartPointer() {
        if (--(*ref_count) == 0) {
            delete ptr;
            delete ref_count;
        }
    }

    T& operator*() const { return *ptr; }
    T* operator->() const { return ptr; }
};

int main() {
    std::vector<int> nums = {5, 2, 8, 1, 9};
    std::sort(nums.begin(), nums.end());

    for (const auto& num : nums) {
        std::cout << num << " ";
    }
    return 0;
}

Python 代码

def fibonacci_generator(n):
    """生成斐波那契数列的前 n 项"""
    a, b = 0, 1
    for _ in range(n):
        yield a
        a, b = b, a + b

# 使用列表推导式
fib_list = [x for x in fibonacci_generator(10)]
print(fib_list)

JavaScript 代码

const quickSort = (arr) => {
    if (arr.length <= 1) return arr;

    const pivot = arr[Math.floor(arr.length / 2)];
    const left = arr.filter(x => x < pivot);
    const middle = arr.filter(x => x === pivot);
    const right = arr.filter(x => x > pivot);

    return [...quickSort(left), ...middle, ...quickSort(right)];
};

3. 混合内容测试

算法复杂度分析

快速排序的平均时间复杂度为 \(O(n \log n)\),其递推关系可表示为:

\[ T(n) = 2T\left(\frac{n}{2}\right) + O(n) \]

根据主定理(Master Theorem),当 \(a = 2\), \(b = 2\), \(f(n) = n\) 时:

\[ T(n) = \Theta(n \log n) \]

物理公式与代码结合

薛定谔方程描述了量子系统的演化:

\[ i\hbar\frac{\partial}{\partial t}\Psi(\mathbf{r},t) = \hat{H}\Psi(\mathbf{r},t) \]

其中哈密顿算符 \(\hat{H} = -\frac{\hbar^2}{2m}\nabla^2 + V(\mathbf{r})\)

数值求解示例:

// 使用有限差分法求解一维薛定谔方程
void solve_schrodinger_1d(
    std::vector<double>& psi,
    const std::vector<double>& V,
    double dx, double dt, double hbar, double m
) {
    const double alpha = hbar * dt / (2.0 * m * dx * dx);
    // 实现细节...
}

4. 表格与公式结合

算法 平均复杂度 最坏复杂度 空间复杂度
快速排序 \(O(n \log n)\) \(O(n^2)\) \(O(\log n)\)
归并排序 \(O(n \log n)\) \(O(n \log n)\) \(O(n)\)
堆排序 \(O(n \log n)\) \(O(n \log n)\) \(O(1)\)
冒泡排序 \(O(n^2)\) \(O(n^2)\) \(O(1)\)

5. 嵌套列表与公式

  1. 线性代数基础
  2. 向量空间:一个集合 \(V\) 及其上的加法和标量乘法运算
  3. 内积空间:定义了内积 \(\langle \mathbf{u}, \mathbf{v} \rangle\) 的向量空间
  4. 范数:\(\|\mathbf{x}\| = \sqrt{\langle \mathbf{x}, \mathbf{x} \rangle}\)

  5. 特征值分解

  6. 对于方阵 \(A\),若存在 \(\mathbf{v} \neq \mathbf{0}\) 使得: \(\(A\mathbf{v} = \lambda\mathbf{v}\)\)
  7. \(\lambda\) 是特征值,\(\mathbf{v}\) 是对应的特征向量

  8. 应用示例

// 计算矩阵的特征值(简化版本)
Eigen::MatrixXd A(3, 3);
A << 1, 2, 3,
     4, 5, 6,
     7, 8, 9;

Eigen::EigenSolver<Eigen::MatrixXd> solver(A);
std::cout << "特征值:\n" << solver.eigenvalues() << std::endl;

6. 引用块与公式

定理(柯西-施瓦茨不等式)

对于任意向量 \(\mathbf{u}, \mathbf{v} \in \mathbb{R}^n\),有:

\[ |\langle \mathbf{u}, \mathbf{v} \rangle| \leq \|\mathbf{u}\| \cdot \|\mathbf{v}\| \]

等号成立当且仅当 \(\mathbf{u}\)\(\mathbf{v}\) 线性相关。

证明思路:构造二次函数 \(f(t) = \|\mathbf{u} - t\mathbf{v}\|^2 \geq 0\),展开后利用判别式 \(\Delta \leq 0\) 即可证明。

7. 复杂的数学表达式

贝叶斯定理:

\[ P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)} = \frac{P(B|A) \cdot P(A)}{\sum_{i} P(B|A_i) \cdot P(A_i)} \]

泰勒级数展开:

\[ f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n = f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \cdots \]

常用函数的展开:

\[ \begin{aligned} e^x &= \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots \\ \sin(x) &= \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n+1}}{(2n+1)!} = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \cdots \\ \cos(x) &= \sum_{n=0}^{\infty} \frac{(-1)^n x^{2n}}{(2n)!} = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \cdots \end{aligned} \]

8. 希腊字母和特殊符号测试

常用希腊字母:\(\alpha, \beta, \gamma, \delta, \epsilon, \zeta, \eta, \theta, \lambda, \mu, \pi, \rho, \sigma, \tau, \phi, \chi, \psi, \omega\)

大写希腊字母:\(\Gamma, \Delta, \Theta, \Lambda, \Xi, \Pi, \Sigma, \Phi, \Psi, \Omega\)

特殊运算符:\(\nabla, \partial, \infty, \forall, \exists, \in, \notin, \subset, \supset, \cup, \cap, \emptyset\)

箭头符号:\(\rightarrow, \leftarrow, \Rightarrow, \Leftarrow, \leftrightarrow, \Leftrightarrow\)

9. 多行对齐公式

\[ \begin{align} (a + b)^3 &= (a + b)(a + b)^2 \\ &= (a + b)(a^2 + 2ab + b^2) \\ &= a^3 + 2a^2b + ab^2 + a^2b + 2ab^2 + b^3 \\ &= a^3 + 3a^2b + 3ab^2 + b^3 \end{align} \]

10. 组合内容压力测试

在机器学习中,我们经常需要优化损失函数。对于线性回归,损失函数为:

\[ L(\mathbf{w}) = \frac{1}{2n}\sum_{i=1}^{n}(y_i - \mathbf{w}^T\mathbf{x}_i)^2 + \frac{\lambda}{2}\|\mathbf{w}\|^2 \]

其梯度为:

\[ \nabla L(\mathbf{w}) = -\frac{1}{n}\sum_{i=1}^{n}(y_i - \mathbf{w}^T\mathbf{x}_i)\mathbf{x}_i + \lambda\mathbf{w} \]

实现代码:

#include <Eigen/Dense>

Eigen::VectorXd gradient_descent(
    const Eigen::MatrixXd& X,
    const Eigen::VectorXd& y,
    double lambda,
    double learning_rate,
    int iterations
) {
    int n = X.rows();
    int d = X.cols();
    Eigen::VectorXd w = Eigen::VectorXd::Zero(d);

    for (int iter = 0; iter < iterations; ++iter) {
        Eigen::VectorXd predictions = X * w;
        Eigen::VectorXd errors = y - predictions;
        Eigen::VectorXd gradient = -(X.transpose() * errors) / n + lambda * w;
        w -= learning_rate * gradient;
    }

    return w;
}

这套测试内容涵盖了:
- ✓ 行内和块级公式
- ✓ 复杂数学符号
- ✓ 多种编程语言代码高亮
- ✓ 表格、列表、引用块
- ✓ 公式与文本的混合排版
- ✓ 多行对齐公式
- ✓ 矩阵、求和、积分等复杂表达式

这些内容应该能充分测试你的博客程序对 LaTeX 和 Markdown 的渲染能力!