Guidance for AI coding agents working in this repository.
JavaPasAPas.docx— the manuscript (Word). The primary deliverable.JavaPasAPas.pdf— the rendered book, regenerated from the.docx.chapitre_*/,JeuSimple/,extra/— the Java source files. The code listings inside the book are copies of these files — keep them in sync.styleconventions.md— the authoritative formatting/style reference. Read it before changing the document; update it when a convention changes.diagrammes/— modern SVG/PNG versions of the book's UML figures.
It is the author's other book and is often open in Word. Never edit, render, or save it. Be aware the render step (below) closes open Word documents — warn the user that unsaved Python work may need recovery if Word had it open.
Word XML is fiddly; edit it programmatically, not by hand.
unzipthe.docxto a working dir (it's a ZIP of XML parts).- Edit
word/document.xml(andstyles.xml,numbering.xml,header*.xml,settings.xml,[Content_Types].xml,_rels/document.xml.rels) with lxml in Python. Namespacew = http://…/wordprocessingml/2006/main. - Repackage:
zip -r -X out.docx '[Content_Types].xml' _rels word docProps customXml. Verify withzipfile.testzip()and no duplicate entries before deploying.
- A Python venv with lxml/Pillow lives at
/tmp/docxvenv(recreate if missing). - Keep a
.bakbefore overwritingJavaPasAPas.docx. w:szis half-points (16→8 pt); spacing is in twips (240→12 pt).
Rendering uses docx2pdf (drives MS Word). Two hard-won gotchas:
- docx2pdf converts Word's active document, not the path you pass. If the
Python book (or any doc) is open and active, you get the wrong PDF. Fix:
quit Word,
pkill -9 "Microsoft Word", remove~$*.docxlocks, relaunch Word fresh, close all docs, then run docx2pdf so the target opens as the sole doc. - Wedged Word after force-kills shows a recovery dialog → AppleScript times
out (
-1712/"Message incompréhensible"). Re-pkill, wait, relaunch.
Reliable sequence (zsh/macOS):
osascript -e 'tell application "Microsoft Word" to quit saving no'; sleep 2
pkill -9 "Microsoft Word"; rm -f /…/~$*.docx; sleep 6
open -ga "Microsoft Word"; sleep 12
osascript -l JavaScript -e 'function run(){var w=Application("Microsoft Word");\
while(w.documents.length>0){w.documents[0].close({saving:"no"});}}'
/tmp/docxvenv/bin/python -c "from docx2pdf import convert; \
convert('/…/JavaPasAPas.docx','/tmp/out.pdf')"- Do not raw-AppleScript
save as … format PDF(hangs on a modal dialog). - OpenOffice/LibreOffice headless is unavailable/hangs here.
- Inspect output with
pymupdf(systempython3 -c "import fitz").
Generate as SVG (Python scripts), then convert to EMF for insertion:
/Applications/Inkscape.app/Contents/MacOS/inkscape in.svg \ --actions="select-all;object-to-path" --export-type=emf --export-filename=out.emf
(object-to-path makes fonts render identically.) Measure text width with
rsvg-convert + Pillow so boxes never overflow. See styleconventions.md §10.
After edits that shift pages, the TOC is stale. Refresh manually in Word
(Cmd+A → F9 → update entire table). Do not set
<w:updateFields w:val="true"/> in settings.xml — it makes Word prompt and
hangs the headless render.
- Verify in the rendered PDF after every change (render figure pages, check margins ≤ text width, check for stray blank pages from section breaks).
- Keep book code listings and the
.javasource files in sync. - Commit/push only when explicitly asked. This repo's history is on
master. - Follow
styleconventions.md; update it (and this file) when conventions change.