0

the org manual says "To preserve the line breaks, indentation and blank lines in a region, but otherwise use normal formatting" you can use #+begin_verse #+end_verse block.

if i run emacs -Q, open a new file, add this example:

#+BEGIN_VERSE
Great clouds overhead
Tiny black birds rise and fall
Snow covers Emacs

   ---AlexSchroeder
#+END_VERSE 

then export to odt using the dispatch with not alternate odt styles file specified, the output in odt looks like this:

Great clouds overhead
 Tiny black birds rise and fall
 Snow covers Emacs

   ---AlexSchroeder

i.e. a space is inserted at the beginning of every new line except the first.

this problem does not appear if you have #+options: \n:t set, but that using option breaks indentation on export for me too (it reduces all indentations to a single space).

1

[Not quite an answer, but too long for a comment - plus I can use code blocks to illustrate the problem and a suggested patch to Org mode for it.]

It's not clear (to me at least) what Org mode should be doing differently: it does not produce the extra spaces in LaTeX or HTML output, and it does not produce any extra spaces in the XML file that it produces for ODT output either - here's what you see if you open the ODT archive and look at the contents.xml file inside it:

<text:p text:style-name="OrgVerse">Great clouds overhead<text:line-break/>
Tiny black birds rise and fall<text:line-break/>
Snow covers Emacs<text:line-break/>
<text:line-break/>
 <text:s text:c="2"/>&#x2014;AlexSchroeder<text:line-break/>
</text:p>

Why soffice displays this with spaces at the beginning of the second and subsequent lines is a mystery to me, but there does not seem to be anything that can be done about it on the Org mode side, other than translating it to some different XML: if you know what it should be translating it into, you should probably file a bug report with org-submit-bug-report.

(Later): By trial and error, I discovered that if you open the ODT archive in emacs and edit the contents.xml file to look like this:

<text:p text:style-name="OrgVerse">Great clouds overhead<text:line-break/>Tiny black birds rise and fall<text:line-break/>Snow covers Emacs<text:line-break/><text:line-break/> <text:s text:c="2"/>&#x2014;AlexSchroeder<text:line-break/>
</text:p>

eliminating the explicit newlines, then it is shown without initial spaces.

I would suggest that you try the following patch to Org mode:

diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index ef07acfed..658c5949a 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -3676,8 +3676,9 @@ contextual information."
       ;; Replace leading tabs and spaces.
       "^[ \t]+" #'org-odt--encode-tabs-and-spaces
       ;; Add line breaks to each line of verse.
-      (replace-regexp-in-string
-       "\\(<text:line-break/>\\)?[ \t]*$" "<text:line-break/>" contents))))
+      (replace-regexp-in-string  "\n" ""
+           (replace-regexp-in-string
+            "\\(<text:line-break/>\\)?[ \t]*$" "<text:line-break/>" contents)))))
 
 
 

It's just a rough approximation at the moment, but it should take care of the initial spaces on the haiku lines, although it mangles the spaces in front of the em-dash.

1
  • 1
    thanks for this. i was also confused because the latex export is flawless. your patch almost works for me, but the problem is that it reduces any existing, intended indentation to a single space. it's the same problem i get when i enable \n:t, i.e. org-export-preserve-breaks, which looks like it does much the same as your patch. i asked about it on the mailing list: orgmode.org/list/…
    – mooseface
    Nov 30 '20 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.