Looking for guidance: changing paragraph styles programmatically

I’m reformatting a book to use a different set of paragraph styles. I once had a program to do this in MS Word, but it belonged to and employer. So I’m writing one for LibreOffice.

I’m looking for documentation or code that will allow me to understand and work with the following behaviour:
When I list the lines and styles, I see:

=== ODT Document Content ===
Paragraph 1: P1: Chapter 2,?Why Do We Have Queues
Paragraph 3: P3: Anything in magenta is notes to the author and editors.

However, when I list the styles in styles.xml, I see

Name → DisplayName (xml:"name,attr"xml:"display-name,attr" )
Body → Body
Caption → Caption

P1 → P1
P10 → P10

Text_20_body → Text body

I’m puzzled at one of my paragraphs being “Text Body” in the UI, and P1 in the list of stiles by line. I was expecting it to be something like Text_20_body.

I’m hoping I’ve just misunderstood something and would appreciate

  • a pointer to RTFM
  • a pointer to code, or
  • a few sentences of clarification

–dave

Good day!
I think it will be easier for us to understand if you upload a small file - an example.

1 Like

From my observations on the XML, styling is a two-tier process to allow renaming styles without the need to modify text description.

The user-readable name is recorded in the style dictionary, sometimes with an hexadecimal encoding of non alphanumeric characters, e.g. “Text_20_Body” for “Text Body” where _20_ stands for the space character.

The dictionary also holds an “internal name” in the form “P123” for paragraph styles (or “T123” for character styles) which is used throughout the document. Thus you can change the user-readable name in the dictionary without changing it elsewhere.

Direct formatting is managed the same, except there is no user-readable name in the entry. You can guess you have one entry per occurrence, contrary to named styles where the entry is shared between occurrences.

That’s what I speculated was the case, but the results I got from the two runs were:

From the paragraphs, I found

=== ODT Document Content ===
Paragraph 1: P1: Chapter 2,?Why Do We Have Queues
Paragraph 3: P3: Anything in magenta is notes to the author and editors. The table of contents and index are just for the author’s convenience.
Paragraph 4: P4: The images are in their native size and the text is not wrapped, to avoid making it hard for your editorial designer. I provide them in full size in the Resources/* files for the various chapters
Paragraph 5: P5: Table of contents is broken.his t
Paragraph 7: P8: Introduction2.1
Paragraph 8: P9: Everyone has had the experience of getting stuck in a queue, often in stores.It’s not enjoyable.
Paragraph 11: P12: Multiple people want to buy something, are actually wanting to give the store money, but they can’t. So they queue up at the service desk and wait for the clerk to finish the previous person. The service desk is a bottleneck.
Paragraph 12: P13: Computers, too, are full of queues, for the CPU, for I/O, for a page of memory and so on, ad infinitum. When things queue up, the machine gets slow. As a result, they have been extensively studied by computer scientists and mathematicians, in order to know how not to bottleneck, and to not have queues build up.
Paragraph 13: P14: There are single , single-server as illustrated in igure 1.linequeues.,F
Paragraph 16: P15: a host of others like: And there are
Paragraph 17: P21: All of them come from having more work than workers, like the clerks in , so the checkout desk is a bottleneck.

from the styles, I found

PARAGRAPH STYLES:

AppendixNumber → AppendixNumber
AppendixTitle → AppendixTitle
BackmatterTitle → BackmatterTitle
Blockquote → Blockquote
Body → Body
BodyContinued → BodyContinued
BodyCustom → BodyCustom
BookAuthor → BookAuthor
BookEdition → BookEdition
BookHalfTitle → BookHalfTitle

NoteCode → NoteCode
NoteContinued → NoteContinued
P1 → P1
P10 → P10
P11 → P11
P12 → P12
P13 → P13
P14 → P14
P15 → P15
P16 → P16
P2 → P2
P3 → P3
P4 → P4
P5 → P5
P6 → P6
P7 → P7
P8 → P8
P9 → P9
PartIntro → PartIntro
PartList → PartList

I’m going to look at the sources again, just in case, to ensure the styles are from the same struct in both cases.

This means your document is exclusively direct formatting. Instead of trying to handle the case programmatically, you should rather apply styles (both paragraph and character) and remove all direct format. You can then change the look and layout by modifying the style configuration without the need for any macro. This is more stable and reliable.

YAY!
Thank you, kind sir!

Please close this with my thanks