fix: fix equation rendering by changing the toolchain to mathjax (#493)

* docs: update README and build guide

* fix: escape * and _ inside math to prevent markdown emphasis corruption

* fix: configure MathJax to use TeX (Computer Modern) font

* feat: enhance markdown processing with label and figure collection

* fix: remove duplicate bibliography directives from chapter summaries

References are already handled at the chapter level, so the
:bibliography: directives in summary pages are redundant and cause
rendering issues.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anyin233
2026-03-12 06:21:56 +00:00
committed by GitHub
parent ec03af6862
commit 00db02dbfd
26 changed files with 642 additions and 1037 deletions

View File

@@ -5,9 +5,9 @@ import sys
from pathlib import Path
try:
from tools.prepare_mdbook import build_title_cache, parse_bib, rewrite_markdown
from tools.prepare_mdbook import build_title_cache, collect_figure_labels, collect_labels, convert_math_to_mathjax, parse_bib, rewrite_markdown
except ModuleNotFoundError:
from prepare_mdbook import build_title_cache, parse_bib, rewrite_markdown
from prepare_mdbook import build_title_cache, collect_figure_labels, collect_labels, convert_math_to_mathjax, parse_bib, rewrite_markdown
PLACEHOLDER_PREFIX = "[TODO: src = zh_chapters/"
@@ -43,7 +43,25 @@ def main() -> int:
for key, fields in parse_bib(extra_bib).items():
bib_db.setdefault(key, fields)
for chapter in iter_chapters(book.get("items", [])):
chapters = iter_chapters(book.get("items", []))
# Pass 1: collect all :label: directives and figure labels
ref_label_map: dict[str, str] = {}
fig_number_map: dict[str, str] = {}
for chapter in chapters:
source_path = chapter.get("source_path") or chapter.get("path")
if not source_path:
continue
for label in collect_labels(chapter["content"]):
ref_label_map.setdefault(label, source_path)
number = chapter.get("number")
if number:
prefix = ".".join(str(n) for n in number)
for idx, label in enumerate(collect_figure_labels(chapter["content"]), 1):
fig_number_map[label] = f"{prefix}.{idx}"
# Pass 2: rewrite markdown with cross-reference linking
for chapter in chapters:
source_path = chapter.get("source_path") or chapter.get("path")
if not source_path:
continue
@@ -56,7 +74,11 @@ def main() -> int:
bibliography_title=BIBLIOGRAPHY_TITLE,
frontpage_switch_label=FRONTPAGE_SWITCH_LABEL,
frontpage_switch_href=FRONTPAGE_SWITCH_HREF,
ref_label_map=ref_label_map,
current_source_path=source_path,
fig_number_map=fig_number_map,
)
chapter["content"] = convert_math_to_mathjax(chapter["content"])
json.dump(book, sys.stdout, ensure_ascii=False)
return 0