+++ Sunday 15 June 2025 +++ Back to generating FODT ======================= For us, users of Open Source software, there are always some challenges to collaborate with the rest of the world, jailed by propriety solutions created by Microsoft or Apple. For years, I could send simple ODT-files to the publisher. I wrote my articles in org-mode, and when ready, I used the Emacs org-mode export functionality to create an ODT-file from my org-mode text. Now, the publisher requires a specific ODT-template (well, actually, it is a MS Word docx template). It looks like a handmade template, presumably geared towards easy conversion for their publishing software. This templates has many different elements, and for each element a different style. I tried to adapt the org-mode export functionality to export into this new format, but the many different elements and the use of their own names of the styles is a big hurdle. In the end, I decided to abandon this route and looked at writing an exporter myself. FODT ---- The "Flat XML ODF"-File format is a format for ODT documents. It consists of a single file, and uses the file extension "fodt". The more complex ODT-format consists of zip archive with multiple XML files. Compared to the ODT-format is much easier to generate a FODT-file. Simple org files ---------------- The articles are just headers, text and code, no tables or any other fancy stuff. There are only three levels of headers, the first level is just the title of the article, the second level just the subtitle. The third level headers are the headers that break up the text in chunks, to prevent a wall of text, guiding the eye, and making the article easier to read. Because of this, writing an exporter to fodt seems doable. Plan of attack -------------- I took the "template" (just an example file they created in MS Word), opened it in Libreoffice and saved it as a fodt-file. After some analyzing I came to the following plan of attack: * Manually create a file with the different elements in it, and tune this until Libreoffice opens it without complaining. * Add some entries in the org-structure-template-alist to quickly add some blocks fenced with tokens like `#+begin_intro' and `#+end_intro'. * Create a parser that recognizes the elements in the org-mode file and call a function on each element and generate the text to export. * Put the the XML intro and outro around the generated text. * Test and tune until Libreoffice is happy with the resulting fodt-file. In the past, I wrote a small elisp script that parses an org mode file (actually, a denote org file) and exports it into my phlog-format, so I could re-use that. It works -------- The after some trial-and-error I got a working elisp script. Libreoffice opens the exported fodt-file without complaining. Fodt is XML, special chars in the text have to be treated so they don't break the XML-code. Special chars, like `<', `>', and `&' have to be converted, and probably some others too. For this, I still must add some functionality to the elisp script, but that shouldn't be too hard (famous last words). Last edited: $Date: 2025/06/15 08:49:59 $