org-mode-ox-odt icon indicating copy to clipboard operation
org-mode-ox-odt copied to clipboard

Anchoring images "to character": A LibreOffice bug

Open kjambunathan opened this issue 2 years ago • 8 comments

~/src1/org-mode-ox-odt$ git log -1 --format=oneline
abb9993c2dc87868ab6a948596e457fc2b772de8 (HEAD -> master) * lisp/ox-odt.el: Support for "side-by-side" figures and "side-by-side" sub-figures

~/src1/org-mode-ox-odt$ git diff > patch.diff


diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 033e9aa33..1e3c7e0fa 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -5212,7 +5212,13 @@ used as a communication channel."
 		(format "\n<text:p text:style-name=\"%s\">%s</text:p>"
 			(nth 3 captions)
 			(concat
-			 short-caption
+			 (org-odt--textbox (format "\n<text:p text:style-name=\"%s\">%s</text:p>" "Standard" short-caption)
+                                           ;; (car widths)
+                                           ;; (car heights)
+                                           nil
+                                           0.2
+                                           "ShortCaptionFrame"
+                                             " draw:z-index=\"10\" "  "char")
 			 (apply 'org-odt--frame href (car widths) (car heights)
 				(append inner title-and-desc))))))))
 	(apply 'org-odt--textbox

Org snippet

#+odt_preferred_output_format: docx

#+odt_extra_styles: <style:style style:name="InnerFrame" style:family="graphic">
#+odt_extra_styles: <style:graphic-properties draw:blue="0%"
#+odt_extra_styles:                           draw:color-inversion="false"
#+odt_extra_styles:                           draw:color-mode="standard"
#+odt_extra_styles:                           draw:contrast="0%"
#+odt_extra_styles:                           draw:gamma="100%"
#+odt_extra_styles:                           draw:green="0%"
#+odt_extra_styles:                           draw:image-opacity="100%"
#+odt_extra_styles:                           draw:luminance="0%"
#+odt_extra_styles:                           draw:red="0%"
#+odt_extra_styles:                           fo:clip="rect(0cm, 0cm, 0cm, 0cm)"
#+odt_extra_styles:                           style:horizontal-pos="from-left"
#+odt_extra_styles:                           style:horizontal-rel="paragraph"
#+odt_extra_styles:                           style:mirror="none"
#+odt_extra_styles:                           style:run-through="foreground"
#+odt_extra_styles:                           style:vertical-pos="from-top"
#+odt_extra_styles:                           style:vertical-rel="paragraph"
#+odt_extra_styles:                           style:wrap="none" />
#+odt_extra_styles: </style:style>

#+odt_extra_styles: <style:style style:name="OuterFrame" style:family="graphic"
#+odt_extra_styles:	     style:parent-style-name="Frame">
#+odt_extra_styles:   <style:graphic-properties text:anchor-type="paragraph"
#+odt_extra_styles:			    svg:x="0cm" svg:y="0cm" fo:margin-left="0cm"
#+odt_extra_styles:			    fo:margin-right="0cm" fo:margin-top="0cm"
#+odt_extra_styles:			    fo:margin-bottom="0cm" style:wrap="none"
#+odt_extra_styles:			    style:vertical-pos="top"
#+odt_extra_styles:			    style:vertical-rel="paragraph-content"
#+odt_extra_styles:			    style:horizontal-pos="center"
#+odt_extra_styles:			    style:horizontal-rel="paragraph" draw:opacity="0%"
#+odt_extra_styles:			    fo:padding="0cm" fo:border="none" />
#+odt_extra_styles: </style:style>

#+begin_src emacs-lisp :results silent :exports results
(setq org-odt-experimental-features
      '(language short-caption-as-label))
#+end_src

#+odt_extra_styles: <style:style style:name="OrgSubFigure"
#+odt_extra_styles:	     style:family="paragraph"
#+odt_extra_styles:	     style:parent-style-name="Figure">
#+odt_extra_styles:   <style:text-properties text:display="none" />
#+odt_extra_styles: </style:style>

#+odt_extra_styles: <style:style style:name="OrgFigureText"
#+odt_extra_styles:	     style:family="paragraph" style:parent-style-name="Standard">
#+odt_extra_styles:   <style:paragraph-properties fo:margin-left="0cm"
#+odt_extra_styles:			      fo:margin-right="0.3cm" fo:margin-top="0.499cm"
#+odt_extra_styles:			      fo:margin-bottom="0cm" fo:text-align="end"
#+odt_extra_styles:			      style:justify-single-word="false" fo:text-indent="0cm"
#+odt_extra_styles:			      style:auto-text-indent="false" />
#+odt_extra_styles: </style:style>

#+odt_extra_styles: <style:style style:name="ShortCaptionFrame"
#+odt_extra_styles:              style:parent-style-name="Frame"
#+odt_extra_styles:              style:family="graphic">
#+odt_extra_styles:   <style:graphic-properties text:anchor-type="char" style:horizontal-pos="right"
#+odt_extra_styles:                             style:horizontal-rel="paragraph-content"
#+odt_extra_styles:                             style:vertical-pos="top"
#+odt_extra_styles:                             style:vertical-rel="paragraph-content" />
#+odt_extra_styles: </style:style>

#+NAME: dog1
#+CAPTION[([[dog1]])]:
#+ATTR_ODT: :width 7.1
#+ATTR_ODT: :outer-frame  (style "OuterFrame" anchor "as-char" extra "draw:z-index=\"1\"")
#+ATTR_ODT: :inner-frame  (style "InnerFrame" extra "draw:z-index=\"0\"" anchor "char")
[[./org-mode-unicorn.png]]


kjambunathan avatar Apr 21 '22 13:04 kjambunathan

If the smaller frame is move a lit bit to the right, and doesn't overlap with the other frame in the odt file, the converted docx file displays the small frame position correctly in wps-office. In wps-office, the smaller frame in the docx file can be moved freely, and it can overlap with the other frame. Wps-office deb package: https://wdl1.pcfg.cache.wpscdn.com/wpsdl/wpsoffice/download/linux/10976/wps-office_11.1.0.10976.XA_amd64.deb

QiangF avatar Apr 23 '22 13:04 QiangF

If the smaller frame is move a lit bit to the right, and doesn't overlap with the other frame in the odt file, the converted docx file displays the small frame position correctly in wps-office. In wps-office, the smaller frame in the docx file can be moved freely, and it can overlap with the other frame.

This is what I see in onedrive (live.com ). It strips the long caption and the short caption is pushed very much to the right.

Screenshot from 2022-04-24 08-11-33

My experimentation with Google Docs suggested that I shouldn't use org-odt--textbox at all. The most recent code doesn't use org-odt--textbox at all.

The odt and docx file that I have shared in the LibreOffice bug report uses old code. I would like to see what their response is, and how they are going to put it in words. I am interested in what they are going to say, and I don't expect much to come out of that bug report. That said, .... I am open to be surprised.

Wps-office deb package: https://wdl1.pcfg.cache.wpscdn.com/wpsdl/wpsoffice/download/linux/10976/wps-office_11.1.0.10976.XA_amd64.deb

Thanks for the link. If it is going to be free for only limited number of days then it is going to be too much hassle.

This is where I am going to draw the line .... I am not going to bother much about Microsoft Word at all. The most I am willing to do is ... export a odt file to docx and re-open it in LibreOffice to see how it renders. Any effort beyond that is not worth my investment.

From compatibility perspective, I want a document produced by the ODT exporter to render well on Google Docs without any loss of content. I use Google Docs to occasionally share information with family and friends. And I will be willing to consider any changes that improves compatibility with Google Docs.

I was SHOCKED to see that even a simple captioned image wasn't rendering on Google Docs. If I go by what this report says Caption and figure reference to .docx (org-export), I believe that the exact problem lies with docx as well. The fact that these compatibility problems never got reported to either on emacs-orgmode list (when I was active there) or here, says that there is hardly anyone interested in ODT exporter beyond a casual use.

It is good that you brought up compatibility issues between what the ODT exporter generates and what works well with DOCX. (Your constant request change for changing anchor to as-char was actualy this .... "If I create a ODT document with LibreOffice and simply export it to DOCX there is a loss of information along the way". I never understood "loss of information", because I was assuming that LibreOffice will do the right thing when converting from ODT to DOCX.

We could have saved sometime--we have been talking about the same thing for around 5 years now--if you had articulated your requests around "loss of information" (and pointed to some relevant remarks from LibreOffice Dev team). If I had been a user of Microsoft Word myself, I would have also made a better attempt at translating from what you are saying to what you actually want.

That said .... the code in the master repo is much better at producing "compatible" documents. I will share some test files, and maybe you can tell me how it looks on your side. This probably after some time.

kjambunathan avatar Apr 24 '22 03:04 kjambunathan

After all this compatibility work ... 'short caption as a label' is too much of a hassle, if you also want compatibility. I have a feeling that LibreOffice provides much more flexibility at positioning things than what Microsoft Word does. That is, .... LibreOffice provides much better layout options than Microsoft Word does, and if my ODT exporter needs to create "compatible" documents, then you should NOT use all the features that LibreOffice provides, but only a limited set of those.

Withe respect to Short Catpions, this is what I suggest you do ... If compatibility is important to you, create a document with short caption in WPS, and share that with me. I will import it in to LibreOffice and examine the XML to see how things could be improved.

kjambunathan avatar Apr 24 '22 03:04 kjambunathan

I have introduced new keyword #+ODT_APP.

If you add

#+ODT_APP: docx

then you will get an output which hopefully will produce a Microsoft Word-compatible / Google Docs-compatible output.

kjambunathan avatar Apr 24 '22 08:04 kjambunathan

It's sad that mediocre file format like docx dominates the market, I think the audience of this odt exporter is people using Latex, to create good looking document without latex's weird command and packages is great.

The linux version of wps-office is free and don't require any registration. It's has compatibility with MS office in mind. I mainly use it to open files sent by other people.

I am quite happy with the current odt exporter. I think the best place to fix the compatibility issue is on the libreoffice side. Just in case you are curious, I manually moved the smaller frame in wps office to above the bigger frame, and attached the file. That drag of the smaller frame resulted in several changes in the xml file inside the docx file, that another proof of the evil of microsoft, they just makes things complicated to get the monopoly. small_frame_moved_to_top_of_larger_frame(remove_zip_extension_to_open).docx.zip img_2022_04_24__20_52_13

QiangF avatar Apr 24 '22 12:04 QiangF

small_frame_moved_to_top_of_larger_frame(remove_zip_extension_to_open).docx.zip

Just for the sake of record ....

The rendering on WPS side, does not match on the MS Word side.

But the rendering on MS Word/Onedrive side exactly matches with rendering on LibreOffice side.

This shows that playing with different ODT apps is not a good idea, and in fringe cases they do their own thing. It is better to stick with one app only and NOT move the same document between different ODT apps.

This is what I see in Microsoft's onedrive (live.com)

Screenshot from 2022-04-25 08-25-37

This is what I see in LibreOffice

Screenshot from 2022-04-25 08-27-03

kjambunathan avatar Apr 25 '22 03:04 kjambunathan