Skip to content

Word to PDF through LibreOffice: keep a footnote's number inside its brackets - #1130

Open
KnifeLemon wants to merge 1 commit into
mainfrom
fix/docx-note-marks-libreoffice
Open

KnifeLemon wants to merge 1 commit into
mainfrom
fix/docx-note-marks-libreoffice

Conversation

@KnifeLemon

@KnifeLemon KnifeLemon commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes #620

Cause

Word lets a footnote's number sit anywhere in the note's text, and Arabic papers commonly put it in brackets: ( + w:footnoteRef + ). LibreOffice's DOCX import drops the number from that place and draws its own label at the start of the note. The brackets stay behind, so the note comes out as 1(), which on the page reads ()1 in a right-to-left paragraph. That is the report's symptom. References in the body text were fine, whichever way their brackets were typed.

So this isn't a bidi problem, and it also affects left-to-right documents.

Fix

DocxNoteMarks runs before LibreOffice renders a Word document (PDF, PNG, SVG, EMF, WMF). For a document with text before a note's number, LibreOffice gets a copy where:

  • every reference has an invisible custom mark (customMarkFollows with U+200B), which replaces LibreOffice's label, followed by its number as text in the reference's formatting;
  • every note has its number as text where Word has it.

A custom mark doesn't count in the numbering, so all footnotes change together and the numbers are worked out here. A document stays as it was if its numbers restart per page or section, or use a format other than decimal or Hindi digits. Endnotes stay LibreOffice's, because I couldn't verify them.

How this was checked

  • With LibreOffice 26.2.6 from build/fetch-engines.ps1 (pinned, SHA-256 checked), all of DocxNoteMarksTests passes, including The_number_stays_inside_its_brackets_in_the_pdf, which runs the whole route through the job queue.
  • A two-note Arabic document through that route, rendered to an image and looked at: the notes show (1) and (2), and the body marks keep their own look. The same document given to the same LibreOffice without this change has the number outside its brackets. There is no U+200B in the PDF's extracted text.
  • DocxNoteMarksTests also checks the XML that Prepare writes.

CI has no LibreOffice, so the route test skips there. The reporter's own file isn't attached: this fixes the reported symptom in a document built to the layout that causes it.

🤖 Generated with Claude Code

…brackets

Word lets a footnote's number sit anywhere in the note's text, and Arabic papers
commonly put it in brackets: "(" ref ")". LibreOffice's DOCX import drops the
number from that place and draws its own label at the start of the note, so the
note comes out as "1()", which reads "()1" in a right-to-left paragraph.

For such documents LibreOffice now gets a copy in which every reference has an
invisible custom mark followed by its number as text, and every note has its
number as text where Word has it. Documents whose numbers depend on the pages or
use another number format stay as they were; endnotes stay LibreOffice's.

Refs #620

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

[Bug]: لدي ملف ورد

1 participant