feat: tex-to-docx converter - #57
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tex-to-docx-swiftconverter package for LaTeX → DOCX conversion\篇名,\摘要,\kw,\tc) with styled DOCX output\input{}expansion — no externallatexpandneededmacdoc tex-to-docx input.tex -o output.docxSupported Commands
\篇名{行1}{行2}\摘要{文字}\section{}\subsection{}\subsubsection{}\kw{}\tc{}Test plan
swift build)Closes #56
🤖 Generated with Claude Code