0

I try to change the style of src code blocks export with odt exporter but it does not work as expected.

I first exported my file to an odt document. Then I changed the style of OrgSrcBlock and saved my document as a template file (let's say mystyle.odt).

Finally I added #+ODT_STYLES_FILE: "mystyle.odt" in the org file and re-exported but nothing changed in the resulting odt document.

I tried the same procedure for the OrgTile style and it works as expected (the style is correctly applied in the resulting odt document).

I'm using Org mode version 9.2.4.

1

What I want to achieve is to export to ODT document with a style which differs from the one use in org mode document. I use a dark theme to work on org mode and I want a light theme in the produced document.

ox-odt-9.2.4.251.tar has support for this feature. Please upgrade before tying out the solution below

For a step-by-step instructions on how you can achieve this see https://github.com/kjambunathan/org-mode-ox-odt/issues/60#issuecomment-522818853

At the end of the process your .org will look like this:

#+odt_extra_styles: <style:style style:name="OrgSrcFontLockStringFace" style:family="text">
#+odt_extra_styles:   <style:text-properties fo:background-color="#ededed" fo:color="#4e9a06" />
#+odt_extra_styles:  </style:style>
#+odt_extra_styles:  
#+odt_extra_styles: <style:style style:name="OrgSrcFontLockDocFace" style:family="text">
#+odt_extra_styles:   <style:text-properties fo:background-color="#ededed" fo:color="#4e9a06" />
#+odt_extra_styles:  </style:style>
#+odt_extra_styles:  <style:style style:name="OrgSrcBlock" style:family="paragraph" style:parent-style-name="Preformatted_20_Text">
#+odt_extra_styles:    <style:paragraph-properties fo:background-color="#ededed" fo:padding="0.049cm" fo:border="0.51pt solid #000000" style:shadow="none">
#+odt_extra_styles:     <style:background-image/>
#+odt_extra_styles:    </style:paragraph-properties>
#+odt_extra_styles:    <style:text-properties fo:color="#2e3436"/>
#+odt_extra_styles:   </style:style>
#+odt_extra_styles:  
#+odt_extra_styles: <style:style style:name="OrgSrcFontLockFunctionNameFace" style:family="text">
#+odt_extra_styles:   <style:text-properties fo:background-color="#ededed" fo:color="#00578e" />
#+odt_extra_styles:  </style:style>
#+odt_extra_styles:  
#+odt_extra_styles: <style:style style:name="OrgSrcFontLockKeywordFace" style:family="text">
#+odt_extra_styles:   <style:text-properties fo:background-color="#ededed" fo:color="#a52a2a" />
#+odt_extra_styles:  </style:style>

#+BEGIN_SRC emacs-lisp 
  (defun helloworld ()
    ""
    (message "hello world"))
#+END_SRC

and when you export the above file, the src blocks will use adwaita theme, even if your Emacs is using misterioso.

Here is a screenshot.

Emacs uses misterioso but ODT document uses adwaita enter image description here

  • Very nice, works as expected and the step by step procedure helps to configure specific options quite easily ! – Lgen Aug 20 at 12:57
0

When I look at the exported ODT file, I don't see any use of OrgSrcBlock; I do see OrgSrcFontLockBuiltinFace, OrgSrcBlockLastLine, ... I also am using org version 9.2.4.

  • Thanks for your answer. I think that if you have a source code with more than one line, the OrgSrcBlock style is applied to all lines of code except the last for which OrgSrcBlockLastLine is used. I just tried with the following block: #+begin_src python :results none :exports code print("First line") print("Second line") #+END_SRC and the two styles are used in the odt export. – Lgen Jul 25 at 13:16
  • Indeed. Yes, if there is more than one line. Sorry for the noise. I did try making a change to the styles.xml file (within the .odt container) and that is definitely being taken into account. I have tried telling org to use the modified file. The export has incorporated the change correctly but the odt file, when opened, does not reflect that change. Very strange. – éric Jul 25 at 14:25
  • Yes, I tried exactly the same procedure with no luck. It seems that the export overrides the template file style. May be it's a bug. – Lgen Jul 25 at 15:46
  • I'm not sure that's what is happening; i.e. I don't think it's actually an org bug. The resulting ODT file does have the change incorporated. For some reason, LibreOffice is ignoring that change. Something else must be overriding the change or something is missing? Have you tried comparing the styles.xml files with and without the STYLE specification? – éric Jul 25 at 16:32
  • I compared with meld the styles.xml files of the file exported with template and the template itself. For styles like OrgSubtitle the style description is the same which is OK. However, for the OrgSrcBlock the value in the exported file is the same than the one obtained without the template but differs from the template which is not OK. So my observation is that, in the generated file , the format of the template is not applied and it is the default format (without template) which is used. So it seems to differ from your observation in which the exported file is modified. – Lgen Jul 25 at 19:35
0

Author of the ODT exporter here.

I maintain a fork of the ODT exporter at https://github.com/kjambunathan/org-mode-ox-odt/blob/master/README.md. Follow the instructions in the link and (1) add my repo to your package-archives and (2) install the ODT exporter. You will see that your source blocks are fontified. If you have any additional queries or issues, open an issue in my github repo and I will /solve/ your problem. FYI, The color of your source block will match the color that Emacs itself uses for the source block. i.e., If you want to change the colors, you need to change the color theme (or custom theme) of your Emacs, and re-export the source block. If this is not what you want, I am willing to listen to your requirements and make suitable changes to my branch.

ps: I saw your report on official orgmode list: https://lists.gnu.org/archive/html/emacs-orgmode/2019-08/msg00169.html. I will be surprised if anyone on that list /solves/ your problem. Look at this issue How to export babel source blocks with syntax highlighting to ODT in org-mode in Emacs 27?. The issue is related to fontification of source blocks. The issue was reported some 2 years ago. There was a bug filed against Emacs. The original poster had brought attention to his woes in the official Emacs Orgmode mailing list. Despite all these nudges by the OP,the bug has remained open till date, and no progress has been made for the last 2 years. The reason I am typing all this is to /inform/ you of what you can realistically expect from that list vis-a-vis your specific report.

Let me reiterate: If you want a solution to your problem, visit my github repo and interact with me there. Trust me, I will solve your problem

  • Thanks for your detailed answer. I installed the alternative odt exporter with the suggested procedure but I now have a new problem: the exportation is not done and an error message is issued: "org-odt-template: OpenDocument export failed with error: ‘Styles file is invalid:". The document used are those posted on the official org mode list. – Lgen Aug 17 at 10:41
0

(If you want further help, please raise a issue on my github repo)

I installed the alternative odt exporter with the suggested procedure but I now have a new problem: the exportation is not done and an error message is issued: "org-odt-template: OpenDocument export failed with error: ‘Styles file is invalid:".

Don't surround your styles file within double quotes.

Instead of,

#+ODT_STYLES_FILE: "mystyle.odt"

use

#+ODT_STYLES_FILE: mystyle.odt

That will take care of the error.

In the screenshot below, you see the input org file and and the result I get in LibreOffice Writer. Note that I have commented out the ODT_STYLES_FILE. Pay particular attention to the color of the python block within Emacs, and color of it in LibreOffice Writer. They match. This tells you that if you want different set of colors for src block in your ODT file, you pick a matching color or custom theme for Emacs.

Source fontification in ODT document matches the fontification in Emacs Source fontification in ODT document matches the fontification in Emacs

Correspondence between style names in styles.xml and styles in LibreOffice stylist Correspondence between styles.xml and styles in LibreOffice stylist

I tried the same procedure for the OrgTitle style and it works as expected (the style is correctly applied in the resulting odt document).

If you are using my fork, then you don't have to use the #+ODT_STYLES_FILE at all. I have added an option for inline automatic and custom styles. If you are a user of LibreOffice you already know what /automatic/ and /custom/ styles mean.

Try exporting the snippet below using my fork, and see what you get. You will see that the title is in green and left-aligned. The snippet does NOT use ODT_STYLES_FILE and instead uses odt_extra_styles.

What I am saying is this: The inline styles feature is available only on my fork, and is not available in the official Emacs.

#+options: toc:nil
#+Title: Test ODT exporter

#+options: tex:t
#+description:
#+keywords:
#+subtitle:
#+odt_styles_file:
#+odt_extra_images:

#+odt_extra_styles:  <style:style style:name="OrgTitle" style:family="paragraph" style:parent-style-name="Title">
#+odt_extra_styles:   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" loext:contextual-spacing="false" fo:text-align="start" style:justify-single-word="false"/>
#+odt_extra_styles:   <style:text-properties fo:color="#579835" fo:font-size="24pt"/>
#+odt_extra_styles:  </style:style>

#+odt_extra_automatic_styles:
#+odt_master_styles:
#+odt_content_template_file:
#+odt_automatic_styles:
#+odt_display_outline_level: 2
#+bib_file:


I try to change the style of src code blocks export with odt exporter but it does not work as expected.

It is not clear to me what sort of effect you want to achieve. So, I am at a loss to give you any hints in this area. If you would like to venture in to Emacs Lisp code relevant to source code fontification, please look at

  1. org-odt-src-block-paragraph-format
  2. org-odt-hfy-face-to-css

Before I go, LibreOffice compresses the XML file it generates (i.e., they don't have a newlines for example). Emacs is notorious for choking when opening files that have very long lines. So, if you want to grok the LibreOffice generated XML file, then configure your LibreOffice to produce pretty XML. See https://github.com/kjambunathan/org-mode-ox-odt/wiki#libreoffice-tips

The document used are those posted on the official org mode list.

Here is the link to your post on Emacs Orgmode mailing list: https://lists.gnu.org/archive/html/emacs-orgmode/2019-08/msg00169.html

For the attention of anyone who wants help with my fork of ODT exporter ....

Let me reiterate, the issues page of my fork--- https://github.com/kjambunathan/org-mode-ox-odt/issues ---is the official channel for any queries related to my fork of ODT exporter. I don't track Stack exchange or Emacs Orgmode mailing lists these days. (It so happened that your query happened to catch my attention on one of my random visits.) But I do get notifications when someone raises an issue on my github repo. So, the best way to get my immediate attention is through the issues page I linked above. Please pop up on my github repo, if you want further help.

  • Thanks again for your help. What I want to achieve is to export to ODT document with a style which differs from the one use in org mode document. I use a dark theme to work on org mode and I want a light theme in the produced document. I tried with your exporter and the template file, the exportation now works well but the style is still not applied in the resulting document for OrgSrc blocks. I will try to use the other suggested approach with #+odt_extra_styles to see if I can achieve the desired result. – Lgen Aug 19 at 10:38

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.