Writer: referencing the same image again and again

Hello all,

When writing documents with caveats, a small icon commonly draws attention on such paragraphs like the check mark in:

flagged paragraph

This icon is inserted in front of every flagged paragraphs and there are as many copies as occurrences.

Unfortunately, this doesn’t allow to change all occurrences of the icon for another one in a single step. Every occurrence must be changed manually.

Nota: an image cannot be bookmarked or cross-referenced which could have provided a (clumsy and too manual for my taste) solution.

An alternate approach is to use a link to a file. Changing the file content substitutes the icon in one step, but this requires to use a dedicated “frozen” filename to avoid the risk of losing the image or a soft link to the real image. The filename may be somewhat arbitrary and may no longer suggest the role of the file. The most serious inconvenience is the fact the the Writer document is no longer self-sufficient: when it is transferred, the image file(s) must also be transferred.

Is there a way to always reference the same image in a Writer document?

The procedure, if any, must allow:

  • the use of the same single image
  • replacement of the image by another one with effect on all occurrences
  • no disruption on other single-use images

I rule out macros because I want a fully “automated” and “transparent” solution without manual action.

Of course not a solution, just a workaround.

The repeated images are stored inside as a single file (we make sure to deduplicate the images). You may simply replace the image you want, with another image - you only need to make sure it has the same name. The names in the package are in fact hash codes of the images, so you would need to check which is the many images with meaningless names is the one you wanted…

Ah, I see @Hagar_Delest already mentioned file replacement.

As a fool-proof method, I refuse to outsmart file structure by playing with supposed non user-accessible contents.

In addition, I didn’t mention that the Navigator is full of meaningless Image999 for these decorative icons which do not bring semantic significance to the markup by a paragraph style. They clutter the Navigator and hide the really important images.

The bullet idea below seems promising though there are detail issues.

At some point there is an action needed.

Except changing the pic file in the /pictures folder of the odt package, I don’t see any other way. Or that would require a field that supports more than mere text.

Not acceptable. I ruled out macros. I don’t want to interfere in any way with the file structure either. What I’m looking for must be done from the UI or some hacky configuration in image properties or I keep on my manual procedure.

I fear it is related to some limitation in ODF.

It doesn’t have to be through a macro. Merely editing the .odt with an archive manager and replacing the relevant pic. But not very user friendly.

I also fear it is an ODF limitation.

“Macro” does not mean your proposal is a macro. But it belongs to the same kind of procedure: patching the XML file structure (and ancillary data) outside the style machinery.

Anyway, it does not address the main point: referencing the same picture from several paragraphs/frames. Once this is done, modifying the existing picture is the easy part. I feel referencing could be done with some macro trick but this direct-formatting will create havoc in the file and is probably unstable or extremely vulnerable to editing/file saving.

Use a paragraph style’s Area set to Bitmap; its style set to Custom position/size, position set to Center Left. Use borders and their padding to make sure that text does not overlap with the image (note that border may be None, it will not prevent padding from working).

Problems:

  1. I think that without tricks like having a white/transparent margin as part of the image, you will be unable to not have border touch the image (if you need border)
  2. There’s a bug that every time you edit the paragraph, the custom size resets to the image’s original size (in my 7.1.3.1). I have to reopen the paragraph settings, modify the size, and save. Needs reporting.
  3. It will be applied per-paragraph.

Other backgrounds may be also used, like frame’s/section’s/table’s… combinations could provide interesting options.

Here is the workaround I implemented. I insist on the fact that this is an ugly hack in the absence of a proper reference mechanism. Thanks to all who provided bits of this workaround.

##Picture/icon must be in the margin

This requires a frame so that it can be positioned outside text area. Frame style MarginIcon is created, derived from Graphics so that is anchor mode is To paragraph by default.

Position properties are adjusted to send the frame in the left margin centered vertically against the paragraph.

Size is set for a 1cm square (this is my requirement). Wrap is None with no spacing.

##Picture/icon is a bullet

List style MarginIcon is created where all levels will only differ by the bullet. This allows to manage all pictures/icons with a single style through the use of the Tab key.

Alignment is left 0cm, indent 0cm, Number followed by Nothing.

One image/picture is assigned to each level with Number Graphics, Graphics Select From file. In my case, these are .png files.

Due to a bad behaviour of graphics rendering by Writer (already mentioned on this AskLO site: drawings made in Draw are not displayed “as is” by Writer, but there a ~3% size difference; apparently this happens also on .png files), the bullet size needs to be slightly scaled to avoid interpolation resulting in visible distortion. This is fixed by setting Width and Height by trial and error.

##Internal frame content

To display the image/icon inside the frame, a list item paragraph must be entered. A dedicated paragraph style MarginIcon is created. It is derived from Default Paragraph Style so that any modification on other styles has no effect on it. Font size is set to 2pt to make content nearly invisible if any is typed by mistake.

List style MarginIcon is attached to it in Outline & Numbering tab.

A careful reader will have noticed that all three created user styles have the same name MarginIcon. This is possible because they live in different namespaces: paragraph, frame and list.

##Placing all bits together

  1. A frame is created with the cursor in the paragraph to decorate and styled MarginIcon

  2. Cursor is put inside the frame and paragraph is styled MarginIcon. Tab is pressed optionally to select the desired icon.

  3. VERY IMPORTANT! Writer does not like empty list items. It may remove the number/bullet because a single bullet in a line does not make sense.

    To protect against spurious editing causing the bullet to vanish, Insert>Formatting Mark>No-width No Break is added so that the paragraph is not empty. This character has a zero width; it does not change formatting.

    Note this is Unicode nonsense because this WORD JOINER U+2060 is intended to prevent two characters from being separated (no line wrap). Here I use it stand alone.

This tedious set up needs to be done only once. Next time, you just copy and paste the previous frame, eventually changing the list item level to change the bullet.

##Final result

Total file size is reduced, pictures are present only once in the list style definition (I checked on the .fodt).

All margin icons can be changed or tuned simultaneously from the list style.

Everything has been installed in my preferred template because it is too tricky to be repeated reliably by hand