問題
OCR 轉錄時,AI 回傳的 FigureRegion.bbox 包含圖片在頁面中的歸一化座標 [x, y, width, height](0-1 範圍)。但產生的 LaTeX 使用 \includegraphics{figures/xxx.png} 沒有指定寬度,導致圖片以原始像素大小顯示,遠大於原書排版。
現有資料
已有所需的所有 metadata(不需修改 OCR pipeline):
| 資料 |
來源 |
範例 |
FigureRegion.bbox |
AI response (responses/*.json) |
[0.12, 0.08, 0.68, 0.31] |
PageRecord.width |
manifest.json |
612 (points) |
PageRecord.height |
manifest.json |
792 (points) |
圖片原始寬度 = bbox[2] × pageWidth = 0.68 × 612 = 416pt ≈ 5.78in
實作方案
Phase 1: Normalizer 後處理(不改 pipeline)
在 LaTeXNormalizer.normalizeProject() 中:
- 讀取
manifest.json 和 responses/*.json
- 對每個
\includegraphics{figures/pNNN-figYY.png}:
- 查找對應的 FigureRegion.bbox
- 計算
width = bbox[2] × pageWidth / 72 (inches)
- 或用
extwidth 比例: width = bbox[2] extwidth
- 替換為
\includegraphics[width=0.68 extwidth]{figures/pNNN-figYY.png}
- 冪等:已有
[width=...] 的不重複處理
Phase 2: Pipeline 上游(未來)
修改 PageTranscriber 在生成 per-page tex 時就帶上正確的 width:
- 在
postProcess() 中,crop figure 後計算寬度
- 寫入 tex/page-NNNN.tex 時直接包含
[width=...]
影響範圍
Phase 1:
packages/pdf-to-latex-swift/Sources/PDFToLaTeXCore/LaTeXNormalizer.swift
packages/pdf-to-latex-swift/Tests/PDFToLaTeXCoreTests/LaTeXNormalizerTests.swift
測試驗證
- Hansen 教科書 accumulated.tex 中所有 31 個 \includegraphics 帶有 width 參數
- 編譯後圖片大小接近原書比例
- 冪等性測試
Current Status
Phase: verified
Last updated: 2026-05-25 by /idd-all-chain (multi-root verify)
問題
OCR 轉錄時,AI 回傳的
FigureRegion.bbox包含圖片在頁面中的歸一化座標[x, y, width, height](0-1 範圍)。但產生的 LaTeX 使用\includegraphics{figures/xxx.png}沒有指定寬度,導致圖片以原始像素大小顯示,遠大於原書排版。現有資料
已有所需的所有 metadata(不需修改 OCR pipeline):
FigureRegion.bbox[0.12, 0.08, 0.68, 0.31]PageRecord.width612(points)PageRecord.height792(points)圖片原始寬度 =
bbox[2] × pageWidth= 0.68 × 612 = 416pt ≈ 5.78in實作方案
Phase 1: Normalizer 後處理(不改 pipeline)
在
LaTeXNormalizer.normalizeProject()中:manifest.json和responses/*.json\includegraphics{figures/pNNN-figYY.png}:width = bbox[2] × pageWidth / 72(inches)extwidth比例:width = bbox[2] extwidth\includegraphics[width=0.68 extwidth]{figures/pNNN-figYY.png}[width=...]的不重複處理Phase 2: Pipeline 上游(未來)
修改
PageTranscriber在生成 per-page tex 時就帶上正確的 width:postProcess()中,crop figure 後計算寬度[width=...]影響範圍
Phase 1:
packages/pdf-to-latex-swift/Sources/PDFToLaTeXCore/LaTeXNormalizer.swiftpackages/pdf-to-latex-swift/Tests/PDFToLaTeXCoreTests/LaTeXNormalizerTests.swift測試驗證
Current Status
Phase: verified
Last updated: 2026-05-25 by /idd-all-chain (multi-root verify)