Skip to content

feat: tex-to-docx converter - #57

Merged
kiki830621 merged 7 commits into
mainfrom
feat/tex-to-docx
Mar 15, 2026
Merged

kiki830621 merged 7 commits into
mainfrom
feat/tex-to-docx

Conversation

@kiki830621

Copy link
Copy Markdown
Member

Summary

  • New tex-to-docx-swift converter package for LaTeX → DOCX conversion
  • Handles custom transcript commands (\篇名, \摘要, \kw, \tc) with styled DOCX output
  • Built-in \input{} expansion — no external latexpand needed
  • CLI: macdoc tex-to-docx input.tex -o output.docx

Supported Commands

Command DOCX Output
\篇名{行1}{行2} Centered 24pt title with page break
\摘要{文字} Bordered block with ◆ prefix
\section{} Heading2 + dark background
\subsection{} Heading3 in brown
\subsubsection{} Heading4 in blue + 【】
\kw{} Bold blue keyword
\tc{} Gray timecode

Test plan

  • Build passes (swift build)
  • Convert 輕導讀 main.tex → verify summaries appear in DOCX
  • Verify \input{} expansion works across chapters/

Closes #56

🤖 Generated with Claude Code

New converter package `tex-to-docx-swift` that converts LaTeX transcripts
to styled DOCX with native OOXMLSwift rendering.

Supported commands:
- \篇名{}{} → centered title page with page break
- \摘要{} → bordered quote block with ◆ prefix
- \section{} → Heading2 with dark background
- \subsection{} → Heading3 in brown
- \subsubsection{} → Heading4 in blue with 【】
- \kw{} → bold blue keyword
- \tc{} → gray timecode
- \textbf{}, \emph{}, \textit{} → bold/italic runs
- Built-in \input{} expansion (no latexpand needed)

CLI: `macdoc tex-to-docx input.tex -o output.docx`
The import in MacDoc+Markdown.swift referenced `MDToHTMLSwift` but the
module is actually named `MDToHTML`. This caused an undefined symbols
linker error that blocked the entire binary from building.
- TeXPreambleParser: reads \definecolor, \fontsize, \color from preamble
- TeXWordBuilder resolves colors via preamble color table with fallbacks
- Titlepage heuristic: \begin{titlepage} → centered styled paragraphs
- \fontsize/\color lines → heuristic styled DOCX output
- New rule: heuristic-output.md
- fix: MDToHTMLSwift → MDToHTML import (linker fix)
- matchCommand now accepts optional * suffix (\section*{} and \section{})
- matchPianMing supports multi-line \篇名{line1}{line2}
- Results: Heading2=52, Heading3=146, Heading4=2412, leaked *{=0

Closes #58
TeXPreambleParser.extractText() now strips bare {} after removing
formatting commands, while preserving escaped \{ \} via placeholders.

Closes #59
- TeXPreambleParser.parse() returns full PreambleConfig (colors + fonts + titleformat)
- Brace-depth counting replaces regex for \titleformat (fixes nested {} like \needspace{})
- \definecolor{}{gray}{} support (coverGray)
- xcolor mixing: black!40 → #999999, black!5 → #F2F2F2
- Font mapping: \songti → "Noto Serif TC", CJKmainfont → "凝書體"
- section: 24pt (was 16pt), subsection: 22pt centered (was 16pt left)
- 摘要: Noto Serif TC font, correct border/bg from preamble
- 篇名/kw: colors from preamble \definecolor

Closes #60
Critical fixes:
- convert() streaming method now throws (DOCX is binary, use convertToFile)
- \input{} expansion tracks relative paths for nested includes
- \color{} inline no longer leaks color name as plain text
- \fontsize{}{} inline no longer leaks brace content

Important fixes:
- emitPianMing skips empty line2 paragraph
- kwProps changed from var to let
- Dead variable `remaining` removed from parseTitleFormats
@kiki830621
kiki830621 merged commit afc01d4 into main Mar 15, 2026
1 check passed
@kiki830621
kiki830621 deleted the feat/tex-to-docx branch March 15, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: tex-to-docx converter — LaTeX 逐字稿轉 DOCX

1 participant