挑戰:三個著名的數學公式

根據您在前面幾篇文章中學到的知識,您應該已經能夠編寫相對複雜的 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