|
| 1 | +# Pandoc DOCX Reference Document |
| 2 | + |
| 3 | +The file `pandoc_reference.docx` is used as a style template when generating `.docx` exports. Pandoc uses the styles defined in this file while filling in content from the app. It does **not** use the content of the reference doc, only its styles. |
| 4 | + |
| 5 | +## How it works |
| 6 | + |
| 7 | +When `show_docx` runs in `plan_exports_controller.rb`, it passes this file to `pandoc` via `--reference-doc`. Pandoc maps HTML elements to Word styles like so: |
| 8 | + |
| 9 | +| HTML element | Word style | |
| 10 | +|---|---| |
| 11 | +| `<p>` | Body Text / First Paragraph | |
| 12 | +| `<h1>` – `<h6>` | Heading 1 – Heading 6 | |
| 13 | +| `<blockquote>` | Block Text | |
| 14 | +| `<code>` | Verbatim Char | |
| 15 | +| `<a>` | Hyperlink | |
| 16 | +| `<hr>` | Horizontal rule paragraph (avoid — use pBdr on heading instead) | |
| 17 | + |
| 18 | +## Editing styles |
| 19 | + |
| 20 | +The styles are stored in `word/styles.xml` inside the `.docx` file. Since `.docx` files are zip archives, you need to unzip, edit, and rezip. |
| 21 | + |
| 22 | +### 1. Unzip |
| 23 | + |
| 24 | +```bash |
| 25 | +cd lib/templates |
| 26 | +unzip pandoc_reference.docx -d pandoc_ref_tmp |
| 27 | +``` |
| 28 | + |
| 29 | +### 2. Edit |
| 30 | + |
| 31 | +Open `pandoc_ref_tmp/word/styles.xml` in any text editor and find the style you want to change. |
| 32 | + |
| 33 | +Font sizes use half-points, so: |
| 34 | + |
| 35 | +| Value | Point size | |
| 36 | +|---|---| |
| 37 | +| 20 | 10pt | |
| 38 | +| 22 | 11pt | |
| 39 | +| 24 | 12pt | |
| 40 | +| 26 | 13pt | |
| 41 | +| 28 | 14pt | |
| 42 | +| 32 | 16pt | |
| 43 | + |
| 44 | +Spacing values (e.g. `w:before`, `w:after`) use twentieths of a point (twips), so 240 = 12pt of space. |
| 45 | + |
| 46 | +Common styles to edit: |
| 47 | + |
| 48 | +- **`docDefaults`** — fallback font and size for anything not explicitly styled |
| 49 | +- **`BodyText`** — regular paragraphs |
| 50 | +- **`FirstParagraph`** — first paragraph after a heading |
| 51 | +- **`Heading1` – `Heading9`** — headings (also update the matching `Heading1Char` etc.) |
| 52 | + |
| 53 | +### 3. Rezip |
| 54 | + |
| 55 | +Run the zip command from **inside** the tmp folder — this is important, otherwise the folder itself gets included and Pandoc won't read the file correctly. |
| 56 | + |
| 57 | +```bash |
| 58 | +cd pandoc_ref_tmp |
| 59 | +zip -r ../pandoc_reference.docx . |
| 60 | +cd .. |
| 61 | +rm -rf pandoc_ref_tmp |
| 62 | +``` |
| 63 | + |
| 64 | +### 4. Deploy |
| 65 | + |
| 66 | +Commit `pandoc_reference.docx` and deploy. Changes take effect immediately on the next export. |
| 67 | + |
| 68 | +## Editing styles using Word |
| 69 | + |
| 70 | +You can open `pandoc_reference.docx` directly in Word and modify styles visually, though it requires a few extra steps to make sure changes actually persist to the style definitions (not just the sample text). |
| 71 | + |
| 72 | +### 1. Open the file in Word |
| 73 | + |
| 74 | +Open `pandoc_reference.docx` directly. You will see sample text for each style, e.g. "Body Text.", "First Paragraph.", "Heading 1", etc. |
| 75 | + |
| 76 | +### 2. Open the Styles pane |
| 77 | + |
| 78 | +- **Mac:** Go to **Format** menu → **Style...** → **Modify** |
| 79 | +- **Windows:** On the **Home** tab, click the small arrow at the bottom-right corner of the Styles group |
| 80 | + |
| 81 | +### 3. Modify a style |
| 82 | + |
| 83 | +In the Styles pane, hover over the style you want to change (e.g. **Body Text**) until a dropdown arrow appears on the right side. Click it and choose **Modify Style...**. Change the font, size, spacing, etc. and click **OK**. |
| 84 | + |
| 85 | +Do **not** right-click the sample text in the document body itself — that only affects the text, not the underlying style definition. |
| 86 | + |
| 87 | +### 4. Save |
| 88 | + |
| 89 | +Save the file normally. Word should write your style changes into the underlying XML. |
| 90 | + |
| 91 | +### 5. Verify the change was saved |
| 92 | + |
| 93 | +Because Word sometimes silently fails to persist style changes, it is worth verifying by unzipping and inspecting the XML after saving: |
| 94 | + |
| 95 | +```bash |
| 96 | +cd lib/templates |
| 97 | +unzip -p pandoc_reference.docx word/styles.xml | grep -A 10 '"Body Text"' |
| 98 | +``` |
| 99 | + |
| 100 | +Check that `<w:sz w:val="..."/>` reflects the size you set. If it does not, the change did not save and you will need to edit the XML directly instead (see **Editing styles** above). |
| 101 | + |
| 102 | +## Tips |
| 103 | + |
| 104 | +- Always back up the file before editing: `cp pandoc_reference.docx pandoc_reference_backup.docx` |
| 105 | +- To verify a style was saved correctly, unzip and grep: `unzip -p pandoc_reference.docx word/styles.xml | grep -A 10 '"Body Text"'` |
| 106 | +- Avoid using `<hr>` in the HTML template. Instead, add a bottom border to the Heading style using `<w:pBdr>` in `styles.xml` to avoid extra spacing. |
0 commit comments