สร้างเอกสารด้วย LaTeX ผ่าน Claude AI

May 2026  ·  Peerapat A  ·  ← Agentic AI

Writing LaTeX Documents with Claude AI

Bottom Line Up Front: XeLaTeX is required to render Thai fonts (like TH Sarabun New) properly. By combining a custom document class with Claude AI and a clear CLAUDE.md instruction file, you can easily generate professional, reusable Thai enterprise reports.

LaTeX is still my go-to for any serious document — especially when it needs to look professional, handle Thai text correctly, and be reusable across projects. In this post I walk through how I built template-doc, a custom LaTeX template for Thai-language enterprise reports, and how Claude became an essential part of that workflow.

The Problem with Thai in LaTeX

Standard LaTeX (pdflatex) cannot render Thai script. You need XeLaTeX, which supports Unicode and OpenType fonts natively. The template is built around the TH Sarabun New font — a clean, readable Thai typeface — loaded via fontspec. Getting Thai hyphenation, line-breaking, and mixed Thai-English spacing right took real iteration, and that is where having Claude as a pair was invaluable.

Project Structure

The repository follows a modular layout to keep large documents manageable:

template-doc/
├── main.tex              # Entry point — includes all sections
├── easreport.cls         # Custom document class (Thai fonts, headers, layout)
├── conf/
│   └── latexmkrc         # Build config: XeLaTeX engine, out/ output dir
├── sections/             # One .tex file per section
│   ├── title.tex
│   ├── togaf.tex
│   ├── a_vision.tex
│   ├── b_business.tex
│   ├── c_system.tex
│   ├── d_technology.tex
│   ├── e_opportunities.tex
│   ├── f_migration.tex
│   ├── g_security_er.tex
│   ├── overview.tex
│   ├── security.tex
│   └── install.tex
├── figures/              # Images referenced in sections
└── assets/               # Watermark and other assets

Each section is an independent .tex file included via \input{} in main.tex. This makes it easy to draft one section at a time with Claude without touching the whole document.

The Custom Class: easreport.cls

The heart of the template is easreport.cls — a custom document class that extends the standard article class. It bundles everything needed for professional Thai-language technical reports:

  • fontspec + xunicode — Unicode font management for Thai script
  • TH Sarabun New — primary font configured for Thai and Latin text
  • microtype — advanced typographic enhancements
  • geometry — A4 page with 1" top/bottom and 0.7" side margins
  • fancyhdr — header and footer with organization name, document title, and page numbers
  • tabularx, booktabs, longtable — professional table formatting
  • hyperref — clickable links with hidden borders
  • hyphenat + ragged2e — hyphenation control for mixed Thai-English content

The class also defines custom metadata commands — \docversion, \docdate, \authorname — so every document carries consistent version tracking without manual header edits.

Building the PDF

The build uses latexmk with a project-local config file:

# Build PDF
latexmk -r conf/latexmkrc main.tex

# Clean build artifacts
latexmk -r conf/latexmkrc -C main.tex

conf/latexmkrc sets XeLaTeX as the engine and routes all output to the out/ directory. The compiled PDF appears at out/main.pdf. Build artifacts (.aux, .log, .toc) are gitignored so the repository stays clean.

How I Work with Claude on LaTeX

The repository includes a CLAUDE.md file that gives Claude the context it needs to produce correct, compilable LaTeX every time. Without this, AI-generated LaTeX often uses the wrong engine, missing packages, or incompatible commands.

Key rules in CLAUDE.md:

  • Always target XeLaTeX — pdflatex will fail because fontspec is required for Thai
  • Use \[ ... \] or align environments for display math, not $$
  • Escape special LaTeX characters when they appear as literal text
  • Prefer semantic markup: \emph{} over \textit{}
  • Place \microtypecontext{spacing=nonadjacent} in the preamble when using microtype with Thai fonts
  • Use \sloppy / \fussy in sections to control Thai text line-breaking

Practical Workflow

My day-to-day flow when writing a section with Claude:

  1. Open a section file — e.g., sections/d_technology.tex
  2. Describe the content to Claude in plain language — what the section covers, what diagrams exist in figures/
  3. Claude drafts the LaTeX — using the class's custom commands, correct Thai font handling, and proper table/figure environments
  4. Build and review — latexmk -r conf/latexmkrc main.tex and open out/main.pdf
  5. Iterate — paste compilation errors back to Claude for targeted fixes

The modular section structure is key here. Claude only needs to see one .tex file at a time, which keeps the context focused and the output accurate.

Gotchas Worth Knowing

  • XeLaTeX is mandatory. Running pdflatex will immediately fail on \usepackage{fontspec}. Always confirm the engine in your build config.
  • TH Sarabun New must be installed. On macOS/Linux, install it as a system font before building. CI environments often need an explicit font installation step.
  • microtype + Thai needs a config line. Add \microtypecontext{spacing=nonadjacent} to suppress warnings and prevent spacing conflicts with Thai characters.
  • Line-breaking Thai text is tricky. Use \sloppy generously in sections with dense Thai prose to avoid overfull hbox warnings.

Why This Approach Works

Pairing LaTeX's precision with Claude's natural language interface removes the friction of remembering every command and environment. I describe what I need in Thai or English, Claude generates correct LaTeX against a well-defined template, and I compile immediately to verify. The CLAUDE.md file acts as a standing contract between me and the AI — no repeated explanations, no wrong engine, no missing packages.

The template is open on GitHub at nuboat/template-doc. Clone it, add your own sections, and point Claude at your CLAUDE.md — you will be producing professional Thai-language PDFs in minutes.

Note: This blog post was written with Claude Code using the template-doc repository as source material.

สร้างเอกสารด้วย LaTeX ผ่าน Claude AI

สรุปประเด็นสำคัญ (BLUF): การพิมพ์ภาษาไทยใน LaTeX ต้องใช้ XeLaTeX ควบคู่กับฟอนต์ TH Sarabun New การนำ custom document class มาทำงานร่วมกับ Claude AI และไฟล์ CLAUDE.md จะช่วยให้คุณสร้างรายงานระดับองค์กรภาษาไทยที่ดูเป็นมืออาชีพได้อย่างรวดเร็ว

LaTeX ยังคงเป็นเครื่องมือคู่ใจของผมสำหรับ document ใดๆ ที่มีความสำคัญ — โดยเฉพาะเมื่อมันจำเป็นต้องดูมีความเป็น professional, สามารถจัดการกับภาษาไทยได้อย่างถูกต้อง, และสามารถนำกลับมาใช้ใหม่ (reusable) ข้าม projects ได้ ในบทความนี้ ผมจะพาทุกคนไปดูว่าผมสร้าง template-doc ขึ้นมาได้อย่างไร, ซึ่งเป็น custom LaTeX template สำหรับ enterprise reports ภาษาไทย, และ Claude กลายมาเป็นส่วนสำคัญอย่างขาดไม่ได้ใน workflow นั้นได้อย่างไร

ปัญหาของการพิมพ์ภาษาไทยใน LaTeX

Standard LaTeX (pdflatex) ไม่สามารถ render ภาษาไทยได้ คุณจำเป็นต้องใช้ XeLaTeX ซึ่งรองรับ Unicode และ OpenType fonts ได้แบบ natively ตัว template ถูกสร้างขึ้นมาโดยอิงจาก font TH Sarabun New — ซึ่งเป็น typeface ภาษาไทยที่ดูสะอาดและอ่านง่าย — โดยทำการ load ผ่าน fontspec การจัดการเรื่อง hyphenation (การตัดคำ), line-breaking (การขึ้นบรรทัดใหม่) และ spacing ของการผสมระหว่างภาษาไทยและภาษาอังกฤษ ต้องอาศัยการทดลองทำซ้ำๆ และนี่คือจุดที่การมี Claude เป็นผู้ช่วยในการทำงานคู่กัน (pair) นั้นมีคุณค่าอย่างมาก

Project Structure

Repository นี้ใช้การวางโครงสร้างแบบ modular เพื่อให้จัดการ documents ขนาดใหญ่ได้ง่าย:

template-doc/
├── main.tex              # Entry point — includes all sections
├── easreport.cls         # Custom document class (Thai fonts, headers, layout)
├── conf/
│   └── latexmkrc         # Build config: XeLaTeX engine, out/ output dir
├── sections/             # One .tex file per section
│   ├── title.tex
│   ├── togaf.tex
│   ├── a_vision.tex
│   ├── b_business.tex
│   ├── c_system.tex
│   ├── d_technology.tex
│   ├── e_opportunities.tex
│   ├── f_migration.tex
│   ├── g_security_er.tex
│   ├── overview.tex
│   ├── security.tex
│   └── install.tex
├── figures/              # Images referenced in sections
└── assets/               # Watermark and other assets

แต่ละส่วนจะเป็นไฟล์ .tex ที่แยกเป็นอิสระต่อกัน และถูกรวมเข้ามาผ่าน \input{} ในไฟล์ main.tex ทำให้การร่างเอกสารทีละส่วนร่วมกับ Claude สามารถทำได้ง่ายโดยไม่ต้องไปยุ่งกับเนื้อหาส่วนอื่นของ document เลย

The Custom Class: easreport.cls

หัวใจสำคัญของ template นี้คือ easreport.cls — ซึ่งเป็น custom document class ที่ extends มาจาก standard article class มันรวบรวมทุกสิ่งที่จำเป็นสำหรับ technical reports ในภาษาไทยแบบมืออาชีพ:

  • fontspec + xunicode — การจัดการ Unicode font สำหรับภาษาไทย
  • TH Sarabun New — font หลักที่ถูกตั้งค่าไว้สำหรับข้อความภาษาไทยและอักษรละติน
  • microtype — การปรับปรุงความสวยงามของการจัดพิมพ์ (typographic enhancements) ขั้นสูง
  • geometry — หน้ากระดาษ A4 ที่มี margin ด้านบน/ล่าง 1 นิ้ว และด้านข้าง 0.7 นิ้ว
  • fancyhdr — header และ footer พร้อมกับชื่อองค์กร, ชื่อ document, และหมายเลขหน้า
  • tabularx, booktabs, longtable — การจัดรูปแบบตารางอย่างมืออาชีพ
  • hyperref — clickable links ที่ซ่อนเส้นขอบ
  • hyphenat + ragged2e — การควบคุม hyphenation สำหรับเนื้อหาภาษาไทยผสมภาษาอังกฤษ

Class นี้ยังมีการกำหนด custom metadata commands ด้วย — \docversion, \docdate, \authorname — เพื่อให้ทุก document มีการระบุ version อย่างสม่ำเสมอโดยไม่ต้องแก้ไข header แบบ manual

Building the PDF

การ build จะใช้ latexmk ร่วมกับ project-local config file:

# Build PDF
latexmk -r conf/latexmkrc main.tex

# Clean build artifacts
latexmk -r conf/latexmkrc -C main.tex

conf/latexmkrc จะตั้งค่าให้ XeLaTeX เป็น engine และกำหนดให้ output ทั้งหมดไปอยู่ที่ directory out/ ไฟล์ PDF ที่ compile เสร็จจะปรากฏที่ out/main.pdf ส่วน build artifacts (.aux, .log, .toc) จะถูกทำ gitignore ไว้ เพื่อให้ repository สะอาด

วิธีที่ผมทำงานกับ Claude บน LaTeX

Repository นี้จะมีไฟล์ CLAUDE.md ที่ให้บริบทกับ Claude ในการเขียน LaTeX ที่ถูกต้องและ compile ผ่านได้เสมอ หากไม่มีสิ่งนี้ AI-generated LaTeX มักจะเลือกใช้ engine ผิด, ขาดลืม packages, หรือใช้คำสั่งที่ไม่ compatible กัน

กฎสำคัญใน CLAUDE.md:

  • ต้องกำหนดเป้าหมายเป็น XeLaTeX เสมอ — การใช้ pdflatex จะเกิด fail เนื่องจากเราต้องการ fontspec สำหรับภาษาไทย
  • ใช้ environments อย่าง \[ ... \] หรือ align สำหรับการทำ display math ไม่ใช่ $$
  • ต้อง escape ตัวอักษรพิเศษของ LaTeX ทุกครั้งเมื่อใช้เป็นข้อความปกติ (literal text)
  • เลือกใช้ semantic markup: อย่าง \emph{} แทน \textit{}
  • ใส่ \microtypecontext{spacing=nonadjacent} ใน preamble เมื่อใช้งาน microtype ร่วมกับ font ภาษาไทย
  • ใช้ \sloppy / \fussy ภายใน sections เพื่อควบคุมเรื่อง line-breaking สำหรับข้อความภาษาไทย

Practical Workflow

Workflow แบบวันต่อวันเมื่อต้องเขียนแต่ละ section ร่วมกับ Claude:

  1. เปิดไฟล์ section — เช่น, sections/d_technology.tex
  2. อธิบายรายละเอียดเนื้อหา ให้ Claude ฟังด้วยภาษาพูดธรรมดา — บอกว่า section นี้เกี่ยวกับอะไร, มี diagrams อะไรบ้างใน figures/
  3. Claude จะเริ่ม draft เป็น LaTeX — โดยใช้ custom commands ของ class, การจัดการ font ภาษาไทยที่ถูกต้อง, รวมไปถึงการเลือกใช้ table/figure environments อย่างเหมาะสม
  4. Build และ ตรวจทาน (review) — รัน latexmk -r conf/latexmkrc main.tex และเปิดไฟล์ out/main.pdf
  5. ทำซ้ำ (Iterate) — ถ้านำมา compile แล้วเจอ error ให้ copy กลับไปให้ Claude เพื่อแก้ไขเฉพาะจุดที่พัง

โครงสร้างแบบ modular section คือส่วนสำคัญอย่างยิ่ง Claude จะมองเห็นไฟล์ .tex แค่ทีละไฟล์ ซึ่งช่วยให้บริบทของมันโฟกัสอยู่แค่ส่วนนั้นๆ ส่งผลให้ได้ output ที่แม่นยำ

Gotchas ที่ควรรู้

  • XeLaTeX จำเป็นต้องใช้เสมอ การใช้ pdflatex จะทำให้การ compile ล้มเหลวทันทีที่ \usepackage{fontspec} อย่าลืมตรวจสอบ engine ภายใน build config ก่อนเสมอ
  • TH Sarabun New จะต้องถูก install ก่อน บน macOS/Linux, ให้ทำการ install font นี้เป็น system font ก่อนสั่ง building สำหรับบนสภาพแวดล้อมแบบ CI ก็มักจำเป็นต้องมีขั้นตอนการ install font แบบ explicit ด้วยเช่นกัน
  • microtype + Thai ต้องการ config line เพิ่ม \microtypecontext{spacing=nonadjacent} เพื่อซ่อนข้อความเตือนและหลีกเลี่ยงปัญหาเรื่อง spacing กับการใช้ตัวอักษรไทย
  • การทำ line-breaking สำหรับข้อความภาษาไทยนั้นเป็นเรื่องที่ยุ่งยาก พยายามใช้ \sloppy บ่อยๆ ภายใน sections ที่มีข้อความภาษาไทยจำนวนมาก เพื่อหลีกเลี่ยงการเจอ overfull hbox warnings

Why This Approach Works

การรวมความแม่นยำของ LaTeX เข้ากับ interface ที่พูดคุยผ่านภาษาธรรมชาติของ Claude ช่วยขจัดความเหนื่อยล้าในการที่ต้องคอยจำทุก command และทุก environment ไปได้ ผมแค่อธิบายสิ่งที่ผมต้องการในภาษาไทยหรือภาษาอังกฤษ จากนั้น Claude ก็จะทำการ generate LaTeX อย่างถูกต้องตาม template ที่ได้ถูกออกแบบไว้ และผมก็สามารถ compile ดูผลได้ทันที ไฟล์ CLAUDE.md ทำหน้าที่เปรียบเสมือน standing contract ระหว่างผมกับ AI — จึงไม่ต้องมานั่งอธิบายข้อตกลงใหม่ซ้ำๆ, ไม่มี engine ที่ผิดอีกต่อไป, และไม่มีปัญหาเรื่อง packages ที่หายไปเลย

ตัว template ถูกเปิดไว้เป็น open source บน GitHub ที่ nuboat/template-doc คุณสามารถ clone มัน, เพิ่มเนื้อหาในส่วนต่างๆ เข้าไป และชี้เป้าให้ Claude ศึกษาจากไฟล์ CLAUDE.md ของคุณ — หลังจากนั้น คุณก็จะสามารถสร้างไฟล์ PDF ขององค์กรในภาษาไทยที่ดูมีความเป็นมืออาชีพได้สำเร็จภายในไม่กี่นาที

Note: บทความบน blog นี้ ถูกเขียนร่วมกับ Claude Code โดยได้อ้างอิง source material มาจาก template-doc repository

使用 Claude AI 编写 LaTeX 文档

核心结论 (BLUF): 必须使用 XeLaTeX 才能正确渲染泰文。通过将自定义的 document class 与 Claude AI 以及清晰的 CLAUDE.md 指令文件结合使用,您可以轻松生成专业的泰文企业报告。

LaTeX 仍然是我处理任何重要 document 的首选——尤其是当它需要看起来很 professional、能够正确处理泰文文本,并且可以在不同 projects 之间 reusable 时。 在这篇文章中,我将逐步介绍我是如何构建 template-doc 的, 这是一个用于泰文 enterprise reports 的 custom LaTeX template,以及 Claude 是如何成为该 workflow 中不可或缺的一部分的。

在 LaTeX 中处理泰文的 Problem

Standard LaTeX (pdflatex) 无法 render 泰文。你需要使用 XeLaTeX,它 natively 支持 Unicode 和 OpenType fonts。 该 template 是围绕 TH Sarabun New font 构建的——这是一种干净、易读的泰文 typeface——通过 fontspec 加载。 要正确处理泰文的 hyphenation、line-breaking,以及泰文和英文混合的 spacing 确实需要不断地 iteration,而这正是让 Claude 作为搭档 (pair) 显得极其有价值的地方。

Project Structure

该 repository 采用了 modular 的布局,以便使大型 documents 易于管理:

template-doc/
├── main.tex              # Entry point — includes all sections
├── easreport.cls         # Custom document class (Thai fonts, headers, layout)
├── conf/
│   └── latexmkrc         # Build config: XeLaTeX engine, out/ output dir
├── sections/             # One .tex file per section
│   ├── title.tex
│   ├── togaf.tex
│   ├── a_vision.tex
│   ├── b_business.tex
│   ├── c_system.tex
│   ├── d_technology.tex
│   ├── e_opportunities.tex
│   ├── f_migration.tex
│   ├── g_security_er.tex
│   ├── overview.tex
│   ├── security.tex
│   └── install.tex
├── figures/              # Images referenced in sections
└── assets/               # Watermark and other assets

每一个 section 都是一个独立的 .tex 文件,通过 main.tex 中的 \input{} 包含进来。 这使得我们可以很容易地让 Claude 一次只起草一个 section,而不需要触及整个 document。

The Custom Class: easreport.cls

该 template 的核心是 easreport.cls——这是一个 custom document class,它扩展了 standard article class。 它捆绑了 professional 泰文 technical reports 所需的一切:

  • fontspec + xunicode — 泰文脚本的 Unicode font 管理
  • TH Sarabun New — 配置为泰文和拉丁文本的主要 font
  • microtype — 高级排版增强功能 (typographic enhancements)
  • geometry — 上下 margin 1 英寸,侧边 margin 0.7 英寸的 A4 页面
  • fancyhdr — 包含组织名称、document 标题和页码的 header 和 footer
  • tabularx, booktabs, longtable — professional 表格格式化
  • hyperref — 隐藏边框的 clickable links
  • hyphenat + ragged2e — 用于泰文-英文混合内容的 hyphenation 控制

该 class 还定义了 custom metadata commands——\docversion、\docdate、\authorname—— 因此,每个 document 都能保持一致的 version 跟踪,无需 manual 编辑 header。

Building the PDF

构建过程使用 latexmk 并配合 project-local 的 config 文件:

# Build PDF
latexmk -r conf/latexmkrc main.tex

# Clean build artifacts
latexmk -r conf/latexmkrc -C main.tex

conf/latexmkrc 将 XeLaTeX 设为 engine,并将所有输出 route 到 out/ 目录中。 编译后的 PDF 会出现在 out/main.pdf。Build artifacts(.aux、.log、.toc) 会被 gitignore 处理,以保持 repository 的整洁。

我如何与 Claude 在 LaTeX 上合作

该 repository 包含一个 CLAUDE.md 文件,它为 Claude 提供了生成正确、可编译的 LaTeX 所需的上下文。 如果没有这个文件,AI-generated 的 LaTeX 经常会使用错误的 engine、遗漏 packages,或者使用不兼容的 commands。

CLAUDE.md 中的关键规则:

  • 必须始终 target XeLaTeX——使用 pdflatex 会失败,因为泰文需要 fontspec
  • 使用 \[ ... \] 或 align environments 来编写 display math,而不是使用 $$
  • 当特殊的 LaTeX 字符作为 literal text 出现时,必须对其进行 escape 处理
  • 首选 semantic markup:例如,优先使用 \emph{} 而不是 \textit{}
  • 当泰文 fonts 配合 microtype 使用时,在 preamble 中添加 \microtypecontext{spacing=nonadjacent}
  • 在包含大量泰文的 sections 中使用 \sloppy / \fussy 来控制 line-breaking

Practical Workflow

当我和 Claude 一起编写一个 section 时的 day-to-day workflow:

  1. 打开一个 section 文件——例如,sections/d_technology.tex
  2. 用口语向 Claude 描述内容——说明该 section 涵盖什么内容,以及 figures/ 中有哪些 diagrams
  3. Claude 起草 LaTeX——使用 class 的 custom commands,正确处理泰文 font,并使用适当的 table/figure environments
  4. Build 并进行 review——运行 latexmk -r conf/latexmkrc main.tex 并打开 out/main.pdf
  5. 迭代 (Iterate)——将编译 error 粘贴回给 Claude,以进行针对性的修复

modular 的 section 结构在这里起到了关键作用。Claude 一次只需要查看一个 .tex 文件, 这使它的上下文保持集中,输出也更加准确。

值得注意的 Gotchas

  • XeLaTeX 是必须的。 如果运行 pdflatex,会立即在 \usepackage{fontspec} 处失败。 请务必在 build config 中确认你的 engine。
  • 必须安装 TH Sarabun New。 在 macOS/Linux 上,请在 building 前将其作为 system font 安装。 CI 环境通常需要一个显式的 font 安装步骤。
  • microtype + 泰文需要一行 config。 添加 \microtypecontext{spacing=nonadjacent} 可以抑制警告并防止与泰文字符发生 spacing 冲突。
  • 泰文文本的 line-breaking 很难处理。 在包含密集泰文散文的 sections 中,应多使用 \sloppy 以避免出现 overfull hbox 警告。

Why This Approach Works

将 LaTeX 的精确性与 Claude 的自然语言 interface 结合起来,消除了记忆每一个 command 和 environment 的摩擦。 我只需要用泰文或英文描述我需要什么,Claude 就会根据一个定义良好的 template 生成正确的 LaTeX,然后我可以直接编译来验证。 CLAUDE.md 文件就像是我和 AI 之间的一份 standing contract——不需要重复的解释,不会有错误的 engine,也不会有缺失的 packages。

该 template 已在 GitHub 上的 nuboat/template-doc 开源。 将其 clone 下来,添加你自己的 sections,并让 Claude 阅读你的 CLAUDE.md——几分钟后你就可以制作出 professional 的泰文 PDF 了。

Note: 这篇 blog post 是在 Claude Code 的帮助下,使用 template-doc repository 作为 source material 编写的。

Claude AI を使った LaTeX ドキュメントの作成

要点 (BLUF): タイ語フォントを正しくレンダリングするには XeLaTeX が必要です。カスタム document class と Claude AI、そして明確な CLAUDE.md を組み合わせることで、プロフェッショナルなタイ語の企業向けレポートを簡単に作成できます。

LaTeX は、いまでも本格的な document を作成するための私の頼れるツールです。特に professional な見た目が必要な時や、タイ語のテキストを正しく処理し、複数の projects 間で reusable にする必要がある場合はそうです。 この記事では、私がタイ語の enterprise reports 用の custom LaTeX template である template-doc をどのように構築したか、そして Claude がその workflow においてどのように不可欠な存在となったかについて解説します。

LaTeX におけるタイ語の Problem

Standard LaTeX (pdflatex) はタイ語を render できません。Unicode と OpenType fonts を natively にサポートする XeLaTeX が必要です。 この template は、すっきりと読みやすいタイ語の typeface である TH Sarabun New font をベースに構築されており、fontspec を通じてロードされます。 タイ語の hyphenation、line-breaking、そしてタイ語と英語が混在する spacing を正しく設定するには、実際の iteration が必要であり、そこで Claude をペアとして持つことが非常に貴重でした。

Project Structure

この repository は、大規模な documents を管理しやすくするために、modular なレイアウトを採用しています:

template-doc/
├── main.tex              # Entry point — includes all sections
├── easreport.cls         # Custom document class (Thai fonts, headers, layout)
├── conf/
│   └── latexmkrc         # Build config: XeLaTeX engine, out/ output dir
├── sections/             # One .tex file per section
│   ├── title.tex
│   ├── togaf.tex
│   ├── a_vision.tex
│   ├── b_business.tex
│   ├── c_system.tex
│   ├── d_technology.tex
│   ├── e_opportunities.tex
│   ├── f_migration.tex
│   ├── g_security_er.tex
│   ├── overview.tex
│   ├── security.tex
│   └── install.tex
├── figures/              # Images referenced in sections
└── assets/               # Watermark and other assets

各 section は独立した .tex ファイルであり、main.tex で \input{} 経由でインクルードされます。 これにより、document 全体に触れることなく、Claude と一度に1つの section だけをドラフトすることが容易になります。

The Custom Class: easreport.cls

この template の核心は easreport.cls です。これは standard article class を拡張した custom document class です。 professional なタイ語の technical reports に必要なすべてがバンドルされています:

  • fontspec + xunicode — タイ文字のための Unicode font 管理
  • TH Sarabun New — タイ語およびラテン文字用に設定されたプライマリ font
  • microtype — 高度なタイポグラフィ強化 (typographic enhancements)
  • geometry — 上下 1インチ、左右 0.7インチの margin を持つ A4 ページ
  • fancyhdr — 組織名、document タイトル、ページ番号を含む header と footer
  • tabularx, booktabs, longtable — professional なテーブルフォーマット
  • hyperref — 境界線を隠した clickable links
  • hyphenat + ragged2e — タイ語・英語混在コンテンツの hyphenation コントロール

この class では custom metadata commands(\docversion、\docdate、\authorname)も定義されており、 header を manual で編集することなく、すべての document で一貫した version トラッキングが可能です。

Building the PDF

ビルドには project-local の config ファイルとともに latexmk を使用します:

# Build PDF
latexmk -r conf/latexmkrc main.tex

# Clean build artifacts
latexmk -r conf/latexmkrc -C main.tex

conf/latexmkrc は XeLaTeX を engine として設定し、すべての出力を out/ ディレクトリに route します。 コンパイルされた PDF は out/main.pdf に表示されます。Build artifacts(.aux、.log、.toc) は gitignore されるため、repository はクリーンに保たれます。

LaTeX での Claude との働き方

この repository には CLAUDE.md ファイルが含まれており、正しくコンパイル可能な LaTeX を毎回生成するために必要なコンテキストを Claude に提供します。 これがないと、AI-generated の LaTeX は間違った engine を使用したり、packages が欠落していたり、互換性のない commands を使用したりすることがよくあります。

CLAUDE.md の主なルール:

  • 常に XeLaTeX を target にする — タイ語には fontspec が必要なため、pdflatex では失敗します
  • display math には $$ ではなく \[ ... \] または align environments を使用する
  • 特別な LaTeX 文字が literal text として表示される場合はエスケープする
  • semantic markup を優先する:\textit{} よりも \emph{}
  • タイ語 fonts で microtype を使用する場合は、preamble に \microtypecontext{spacing=nonadjacent} を配置する
  • タイ語テキストの line-breaking を制御するには、sections 内で \sloppy / \fussy を使用する

Practical Workflow

Claude と section を書くときの日々の workflow は次のとおりです:

  1. section ファイルを開く — 例: sections/d_technology.tex
  2. 内容を説明する — その section で何を取り上げるか、figures/ にどのような diagrams があるかなどを平易な言葉で Claude に伝えます
  3. Claude が LaTeX をドラフトする — class の custom commands、正しいタイ語 font の扱い、適切な table/figure environments を使用します
  4. Build とレビュー — latexmk -r conf/latexmkrc main.tex を実行し、out/main.pdf を開きます
  5. 反復 (Iterate) — コンパイル error を Claude にペーストし、的を絞った修正を行います

ここでは、modular な section 構造が鍵となります。Claude は一度に1つの .tex ファイルだけを見ればよいため、 コンテキストが集中し、出力が正確になります。

知っておくべき Gotchas

  • XeLaTeX は必須です。 pdflatex を実行すると、\usepackage{fontspec} で直ちに失敗します。 build config で常に engine を確認してください。
  • TH Sarabun New をインストールする必要があります。 macOS/Linux では、building 前に system font としてインストールしてください。 CI 環境では多くの場合、明示的な font インストールステップが必要です。
  • microtype + タイ語には config 行が必要です。 警告を抑制し、タイ文字との spacing の競合を防ぐために \microtypecontext{spacing=nonadjacent} を追加します。
  • タイ語の line-breaking は厄介です。 overfull hbox 警告を避けるために、密なタイ語の散文がある sections では \sloppy を惜しみなく使用してください。

Why This Approach Works

LaTeX の正確さと Claude の自然言語 interface を組み合わせることで、すべての command や environment を覚える摩擦がなくなります。 タイ語や英語で必要なものを説明するだけで、Claude が明確に定義された template に対して正しい LaTeX を生成し、私はすぐにコンパイルして確認できます。 CLAUDE.md ファイルは私と AI の間の standing contract として機能します — 繰り返しの説明も、間違った engine も、欠落した packages もありません。

この template は GitHub の nuboat/template-doc でオープンになっています。 これを clone し、独自の sections を追加して、Claude にあなたの CLAUDE.md を読ませれば — 数分で professional なタイ語の PDF を作成できるようになります。

Note: この blog post は、template-doc repository を source material として使用し、Claude Code で執筆されました。

LaTeX-Dokumente mit Claude AI schreiben

Zusammenfassung (BLUF): XeLaTeX ist erforderlich, um thailändische Schriftarten korrekt zu rendern. Durch die Kombination einer benutzerdefinierten Dokumentenklasse mit Claude AI und einer klaren CLAUDE.md-Datei können Sie problemlos professionelle thailändische Unternehmensberichte erstellen.

LaTeX ist immer noch meine erste Wahl für jedes ernsthafte document – besonders dann, wenn es professional aussehen, thailändischen Text korrekt verarbeiten und über verschiedene projects hinweg reusable sein muss. In diesem Beitrag zeige ich, wie ich template-doc entwickelt habe, ein custom LaTeX template für thailändische enterprise reports, und wie Claude zu einem unverzichtbaren Teil dieses workflows wurde.

Das Problem mit Thai in LaTeX

Standard LaTeX (pdflatex) kann die thailändische Schrift nicht rendern. Sie benötigen XeLaTeX, das Unicode und OpenType fonts natively unterstützt. Das template baut auf der font TH Sarabun New auf – einem klaren, gut lesbaren thailändischen typeface – der über fontspec geladen wird. Die richtige Einstellung von thailändischer hyphenation, line-breaking und dem spacing von gemischtem thailändisch-englischem Text erforderte einige iteration, und genau hier war Claude als Pair von unschätzbarem Wert.

Project Structure

Das repository folgt einem modular aufgebauten Layout, um große documents verwaltbar zu halten:

template-doc/
├── main.tex              # Entry point — includes all sections
├── easreport.cls         # Custom document class (Thai fonts, headers, layout)
├── conf/
│   └── latexmkrc         # Build config: XeLaTeX engine, out/ output dir
├── sections/             # One .tex file per section
│   ├── title.tex
│   ├── togaf.tex
│   ├── a_vision.tex
│   ├── b_business.tex
│   ├── c_system.tex
│   ├── d_technology.tex
│   ├── e_opportunities.tex
│   ├── f_migration.tex
│   ├── g_security_er.tex
│   ├── overview.tex
│   ├── security.tex
│   └── install.tex
├── figures/              # Images referenced in sections
└── assets/               # Watermark and other assets

Jeder section ist eine unabhängige .tex Datei, die über \input{} in main.tex eingebunden wird. Dies macht es einfach, mit Claude jeweils nur einen section zu entwerfen, ohne das gesamte document zu berühren.

The Custom Class: easreport.cls

Das Herzstück des template ist easreport.cls – eine custom document class, die die standard article class erweitert. Sie bündelt alles, was für professional thailändische technical reports benötigt wird:

  • fontspec + xunicode — Unicode font Management für die thailändische Schrift
  • TH Sarabun New — die primäre font, konfiguriert für thailändischen und lateinischen Text
  • microtype — fortgeschrittene typografische Verbesserungen (typographic enhancements)
  • geometry — A4-Seite mit 1 Zoll margin oben/unten und 0,7 Zoll seitlichen margins
  • fancyhdr — header und footer mit Organisationsname, document Titel und Seitenzahlen
  • tabularx, booktabs, longtable — professional Tabellenformatierung
  • hyperref — clickable links mit versteckten Rändern
  • hyphenat + ragged2e — hyphenation Kontrolle für gemischte thailändisch-englische Inhalte

Die class definiert außerdem custom metadata commands — \docversion, \docdate, \authorname — sodass jedes document eine konsistente version Verfolgung hat, ohne manual den header bearbeiten zu müssen.

Building the PDF

Für den Build wird latexmk mit einer project-local config Datei verwendet:

# Build PDF
latexmk -r conf/latexmkrc main.tex

# Clean build artifacts
latexmk -r conf/latexmkrc -C main.tex

conf/latexmkrc legt XeLaTeX als engine fest und leitet alle Ausgaben in das Verzeichnis out/ weiter. Das kompilierte PDF erscheint unter out/main.pdf. Build artifacts (.aux, .log, .toc) werden auf gitignore gesetzt, damit das repository sauber bleibt.

Wie ich mit Claude an LaTeX arbeite

Das repository enthält eine CLAUDE.md Datei, die Claude den Kontext gibt, den es braucht, um jedes Mal korrektes, kompilierbares LaTeX zu erzeugen. Ohne dies verwendet AI-generated LaTeX oft die falsche engine, es fehlen packages, oder es werden inkompatible commands genutzt.

Wichtige Regeln in CLAUDE.md:

  • Zielen Sie immer auf XeLaTeX ab – pdflatex wird fehlschlagen, da fontspec für Thai erforderlich ist
  • Verwenden Sie \[ ... \] oder align environments für display math, nicht $$
  • Escapen Sie spezielle LaTeX-Zeichen, wenn sie als literal text erscheinen
  • Bevorzugen Sie semantic markup: \emph{} gegenüber \textit{}
  • Platzieren Sie \microtypecontext{spacing=nonadjacent} in der preamble, wenn Sie microtype mit thailändischen fonts verwenden
  • Nutzen Sie \sloppy / \fussy in sections, um das line-breaking von thailändischem Text zu kontrollieren

Practical Workflow

Mein alltäglicher workflow, wenn ich einen section mit Claude schreibe:

  1. Öffnen einer section Datei — z. B. sections/d_technology.tex
  2. Beschreiben des Inhalts — ich erkläre Claude in einfacher Sprache, was der section abdeckt und welche diagrams in figures/ vorhanden sind
  3. Claude entwirft das LaTeX — unter Verwendung der custom commands der class, der korrekten Behandlung von thailändischen font und angemessenen table/figure environments
  4. Build und Review — latexmk -r conf/latexmkrc main.tex ausführen und out/main.pdf öffnen
  5. Iterieren (Iterate) — ich füge Kompilierungs-error wieder bei Claude ein, um gezielte Korrekturen vornehmen zu lassen

Die modular strukturierte section ist hier der Schlüssel. Claude muss immer nur eine .tex Datei gleichzeitig sehen, was den Kontext fokussiert und die Ausgabe präzise hält.

Gotchas, die man kennen sollte

  • XeLaTeX ist zwingend erforderlich. Die Ausführung von pdflatex wird sofort bei \usepackage{fontspec} fehlschlagen. Überprüfen Sie immer die engine in Ihrer build config.
  • TH Sarabun New muss installiert sein. Auf macOS/Linux sollten Sie es als system font installieren, bevor Sie mit dem building beginnen. CI Umgebungen erfordern oft einen expliziten font Installationsschritt.
  • microtype + Thai benötigt eine config Zeile. Fügen Sie \microtypecontext{spacing=nonadjacent} hinzu, um Warnungen zu unterdrücken und spacing Konflikte mit thailändischen Zeichen zu vermeiden.
  • Das line-breaking von thailändischem Text ist knifflig. Verwenden Sie in sections mit dichter thailändischer Prosa großzügig \sloppy, um overfull hbox Warnungen zu vermeiden.

Why This Approach Works

Die Kombination der Präzision von LaTeX mit der natürlichen Sprach-interface von Claude beseitigt die Reibung, sich jeden command und jedes environment merken zu müssen. Ich beschreibe, was ich auf Thai oder Englisch brauche, Claude generiert korrektes LaTeX basierend auf einem klar definierten template, und ich kompiliere sofort zur Überprüfung. Die CLAUDE.md Datei fungiert als ein standing contract zwischen mir und der KI – keine wiederholten Erklärungen, keine falsche engine, keine fehlenden packages.

Das template ist Open Source und auf GitHub unter nuboat/template-doc verfügbar. Klonen Sie es, fügen Sie Ihre eigenen sections hinzu und lassen Sie Claude Ihre CLAUDE.md lesen – so erstellen Sie in wenigen Minuten professional thailändische PDFs.

Note: Dieser Blog-Beitrag wurde mit Claude Code geschrieben, wobei das template-doc repository als source material verwendet wurde.