挑战:三个著名的数学公式

根据您在前面几篇文章中学到的知识,您应该已经能够编写相对复杂的 MathML 公式了。本次挑战将为您提供一个实践的机会。

一篇小型数学文章

目标是使用 HTML 和 MathML 重写以下数学文章。

Screenshot of the PDF output generated by XeLaTeX

虽然您不需要熟悉 LaTeX,但了解它生成的 LaTeX 源代码可能会很有用。

latex
\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

To solve the cubic equation $t^3 + pt + q = 0$ (where the real numbers
$p, q$ satisfy ${4p^3 + 27q^2} > 0$) one can use Cardano's formula:

\[
  \sqrt[{3}]{
    -\frac{q}{2}
    +\sqrt{\frac{q^2}{4} + {\frac{p^{3}}{27}}}
  }+
  \sqrt[{3}]{
    -\frac{q}{2}
    -\sqrt{\frac{q^2}{4} + {\frac{p^{3}}{27}}}
  }
\]

For any $u_1, \dots, u_n \in \mathbb{C}$ and
$v_1, \dots, v_n \in \mathbb{C}$, the Cauchy–Bunyakovsky–Schwarz
inequality can be written as follows:

\[
  \left| \sum_{k=1}^n {u_k \bar{v_k}} \right|^2
  \leq
  {
    \left( \sum_{k=1}^n {|u_k|} \right)^2
    \left( \sum_{k=1}^n {|v_k|} \right)^2
  }
\]

Finally, the determinant of a Vandermonde matrix can be calculated
using the following expression:

\[
  \begin{vmatrix}
  1 & x_1 & x_1^2 & \dots & x_1^{n-1} \\
  1 & x_2 & x_2^2 & \dots & x_2^{n-1} \\
  1 & x_3 & x_3^2 & \dots & x_3^{n-1} \\
  \vdots & \vdots & \vdots & \ddots & \vdots \\
  1 & x_n & x_n^2 & \dots & x_n^{n-1} \\
  \end{vmatrix}
  = {\prod_{1 \leq {i,j} \leq n} {(x_i - x_j)}}
\]

\end{document}

起始点

要开始此评估,您可以依赖我们常规的 HTML 模板。默认情况下,它使用 UTF-8 编码,为 <body><math> 标签提供特殊 Web 字体(具有与 LaTeX 输出相似的外观和感觉)。目标是用实际的 MathML 内容替换问号 ???

html
<!doctype html>
<html lang="en-US">
  <head>
    <meta charset="utf-8" />
    <title>Three famous mathematical formulas</title>
    <link
      rel="stylesheet"
      href="https://fred-wang.github.io/MathFonts/LatinModern/mathfonts.css" />
  </head>
  <body class="htmlmathparagraph">
    <p>
      To solve the cubic equation ??? (where the real numbers ??? satisfy ???)
      one can use Cardano's formula: ???
    </p>

    <p>
      For any ??? and ???, the Cauchy–Bunyakovsky–Schwarz inequality can be
      written as follows: ???
    </p>

    <p>
      Finally, the determinant of a Vandermonde matrix can be calculated using
      the following expression: ???
    </p>
  </body>
</html>

提示和技巧

  • 首先插入空的 <math> 标签,并决定它们是否应具有 display="block" 属性。
  • 检查使用的文本并查找其 Unicode 字符(“−”、“ℂ”、“∑”等)。
  • 分析每段文本的语义(变量?运算符?数字?)并确定每个文本应使用的正确令牌元素。
  • 查找高级结构(分数?根号?下标/上标?矩阵?)并确定每个结构应使用的正确 MathML 元素。
  • 不要忘记使用 <mrow> 来组合子表达式。
  • 注意可伸缩和大型运算符!
  • 使用 W3C 验证器来捕获 HTML/MathML 标记中的意外错误。
  • 如果您卡住了,或者意识到手动编写 MathML 是多么痛苦,请随时使用工具来帮助 编写 MathML,例如 TeXZilla