How to merge two files containing cross-references to numbered paragraphs with renumbering them?

I have two prepared LibreOffice Writer files. Each contains text with cross-references to its own numbered paragraphs.
In both files, the text appears first, followed by the numbered paragraphs themselves. Now these files need to be combined into a single document featuring continuous text with cross-references, followed by a common set of numbered paragraphs using a single numbering system.

Clarification: the text of the first file (excluding the numbered paragraphs themselves) should be followed by the text of the second file (excluding the numbered paragraphs themselves), then a section of the numbered paragraphs from the first file, and finally a section of the numbered paragraphs from the second file. The paragraph numbers from the second file must change to continue the numbering from the first file. Cross-references to paragraph numbers within the inserted text from the second file must now point to the new paragraph numbers (which have increased due to the renumbering).
An equivalent situation (which might make it clearer) is this: two independently prepared chapters are merged into a single book, and the literature citations in the second chapter need to point to the new reference numbers in the consolidated bibliography.

The simplest way: If I insert the text of the second chapter at the end of the first (using Ctrl+C/Ctrl+V or “Insert”—> “Text from File”), the cross-references from the added file will effectively point to paragraph numbers in the first chapter. While the numbered paragraphs from the second file can easily be merged into a single numbering sequence (using “Toggle Numbered List”/F12), the cross-references within the added second chapter must be updated to reflect the new numbers.

How can such a merging process be automated or simplified?
LibreOffice 7.1.8 from AlmaLinux 9 is being used.

many Words … well explained abstract!
but you have the documents to work with, we not!
maybe you should attach these docs to help us to help you?

Provided your files are formatted with styles and your numbered paragraphs use a list style (and not “Toggle Numbered List”/F12 which is direct formatting), everything will be done automatically.

Unfortunately, very few people understand conceptually what is a list. And things are made worse by the “compatibility” implementation of the really badly designed M$ Word feature (under Format → Bullets & Numbering or equivalently toolbar button and F12).

To evaluate your need (and skill), please attach a reduced sample of a single “chapter” with some lines of the fixed part and some numbered paragraphs of the second part.


Hoping your document is saved .odt. If it is DOC(X), no luck, everything must be done manually.

PS: 7.1.8 is really an old release, you should update (perhaps also your OS).

1 Like

Version 9 will have active support until 31 May 2027, and security support until 31 May 2032.

So I guess older versions of LibreOffice will be around for some time…

File1.odt (11.1 KB)
File2.odt (11.0 KB)
Thank you for the prompt replies!

I am attaching some brief sample files that I created specifically to help me better understand the answers (my knowledge of LibreOffice is low).

No style-based formatting was used in the files; one of them was originally created in MS Word (I converted to the ODT format).
In both files, paragraph numbering was applied via Format → Bullets & Numbering.

I undersyand that the LibreOffice version is old, but I would prefer not to install a new version from source code.

offtopic: I dont know Alma-Linux, but would assume there is a way to install ready compiled packages from Libreoffice-Download?!

Preliminary remark: your post is not a solution to your problem. It only provides additional “technical” data needed to solve the issue. It should have been a Comment so that chronological order can be preserved, which is never the case with Answers.

All Linux distros come with a package manager to automate management and installation of programs. They are not provided as source unless you explicitly request so, and need no compilation to unstall. AlamLinux is based on CentOS; therefore the package management tool should be dnf and a GUI tool should also be available (dnfdragora?)

Now to the point

You are unfortunately in the worst case: full manual formatting. But, hopefully, the M$ Word origin has not polluted the style dictionary, perhaps because, again, everything was manually done. Apparently, you applied built-in Preformatted Text to your document and overlaid this with direct formatting. Preformatted Text is intended to be used with manually aligned text, usually under fixed-pitch font. The “normal” style for your main topic is Body Text.

I don’t see huge differences between files 1 and 2. But, I tried to merge them anyway.

As I feared it, using Format → Bullets & Numbering added its own “mess”. Due to the imitation of the badly implemented feature in M$ Word, membership of a logical list is based on contorted heuristics highly dependent on edit history.

In this case, after pasting file 2 into file 1, the heuristics decides that your numbered paragraphs are independent logical lists and don’t renumber them as a whole. It is though possible to fix the issue but it requires to select each numbered paragraph in its turn and Format → Lists → Add to List and Tools → Update → Update All after the operation. This assumes you have a single list across the merge document. If you need to manage several lists, there is no practical solution. The choice of Format → Bullets & Numbering leads you to a nightmarish situation.


My best advice is to postpone merging your documents and learn how to use styles in Writer. The Writer Guide is a good starting point but will not clearly present the benefits of styling. This is done by Bruce Byfield’s Designing with LO also available from the same page though a bit hidden (I heard that the link might be broken; I have a copy of the book I can send through private mail if needed).

Taking the time to read basic literature will boost your productivity and you’ll be more efficient.

The key in merging 2 numbered lists is to format them under the same list style so that they are considered as member of the same logical list without any ambiguity. You can use built-in Numbering 123 for this. You can always Format → Lists → Restart Numbering at any list item if you want to have several occurrences of the same logical list.

1 Like

I hope you dont mean BASIC :speak_no_evil:

No, here “basic” means ABC, preliminary, fundamental, … :wink:

>
… Apparently, you applied built-in Preformatted Text to your document and overlaid this with direct formatting. Preformatted Text is intended to be used with manually aligned text, usually under fixed-pitch font.

I switched from Word to LibreOffice and used all the default settings. My Style is set to “Preformatted Text” and “Default Character,” and I switched (as required) to Times New Roman.


…It is though possible to fix the issue but it requires to select each numbered paragraph in its turn and Format → Lists → Add to List and Tools → Update → Update All after the operation. This assumes you have a single list across the merge document.

Yes, I need a single list of numbered paragraphs spanning the entire document. Unfortunately, in LibreOffice 7.1, the Format— > Lists menu does not offer an “Add to List” option. After merging file1 and file2, I can select all the numbered paragraphs from file2 and choose “Continue Previous Numbering” (instead of “Add to List”); all the paragraphs will then receive the correct new numbers, but the cross-references within the added text will still point to the paragraph numbers from file1. This is exactly what I mentioned initially: it requires manually updating the cross-references in the “file2 text partition” to reflect the new paragraph numbers.

If I install version 26.2.6 and the “Add to List” option becomes available, will the necessary manual changes be limited only to the numbered paragraphs “from file2” themselves?

… This is done by Bruce Byfield’s Designing with LO also available from the same page though a bit hidden (I heard that the link might be broken; I have a copy of the book I can send through private mail if needed).

Unfortunately, this book is not available there.


Taking the time to read basic literature will boost your productivity and you’ll be more efficient.

Yes, I have to agree with that. It’s just that the work needs to be finished by a certain deadline, and I’m not sure I can get the hang of the list style quickly enough.

Yes, there was a change in wording, sometime after 7.x. I forgot it.

This should not happen and it does not when I merge your sample files. Are you absolutely sure that the sample files use the same cross-references as your real documents?

All the cross-references, as used by me, point to an internal LibreOffice Writer ID—specifically, something like _RefNumPara_number, where “number” is the internal ID generated at the time of creation. These are visible in that format if you toggle the view using Ctrl+F9. This is confirmed by the appearance of the merged file—perhaps I didn’t phrase things quite precisely in my previous message. That is why I am attaching the merged file File_joint in this message.

You could compare the IDs from File1, File2, and File_joint.
Could it be due to a chance coincidence of IDs in the first three cross-references within of File1 and File2 ?
File_joint.odt (12.5 KB)

Please, please, please, don’t use Suggest a Solution for something which is not a solution to the problem, but simply additional information. You should use a Comment which is created by clicking on the call icon with Comment label under the relevant post. But creating fake “solutions”, you confuse users who have the same issue and may prevent regular contributors from participatong because they see the question was “answered”.

During your “merge”, you probably damaged something because:

  • in File2 part, references to “1”, “2” and “3” now point to File1; only “4” still points to File2
  • looking carefully to first item of File2, you see that [1] is rendered in some kind of monospaced font like Courier while the others are “standard”

Your use of list toolbar button creates independent lists, notwithstanding it is direct formatting, prohibiting centralised management.

You have two problems here: your “merge” procedure has damaged your references; and direct formatted lists.

The second one can be somehow fixed (except for the glitch in the first item of “File2”):

  1. select each list in its turn and press the toolbar button to remove list numbering
  2. customise Numbering 123 built-in list style to ad your brackets and tune position (number and text alignment)
  3. select the lists and apply Numbering 123

If the list in “File2” part is not renumbered automatically, try Format → Lists>Add to List on the offending item(s).

Last minute: I found why the first item number looks “different”. You seem to have applied direct formatting over Preformatted Text because its default font is Liberation Mono which you replaced by Times New Roman. In principle, you can do this on the number; you should apply a character style through list style configuration. However there is an undocumented effect where direct formatting is possible on “intermediate” numbers (which excludes the first number).

If you want predictable and stable formatting, you should word exclusively with styles and absolutely avoid direct formatting. Contrary to general belief, direct formatting is not “intuitive” at all and requires super guru expert skills to get what you want without errors. And, anyway, direct formatting is an expressway to formatting nightmare.

My apologies—I assumed the only way to provide a response was via the large “Suggest a solution” icon, and I completely overlooked the “Reply” icon. I reworked the document largely “by hand” —though I did manage to finish in time.
However, it seems to me (and I could be wrong) that switching to a style-based workflow would break compatibility with MS Word. I frequently receive .doc/.docx files that I need to merge with my own work, and often the final document has to be delivered in Word format as well! Issues with merging are likely quite common; they can be resolved using macros, so it might be useful to have a set of “standard macros” available.

Read it the other round: working in DOCX format breaks advanced features in Writer. ODF provides more automation and formatting “primitives”, i.e. styles, than DOCX. This means, every time you save .docx, you lose information because styles are converted to some form of direct formatting so that Word understands what you intended.


Unfortunately, there is also a conversion when you open a DOCX to translate it into internal format so that Writer can work on the text. This is also an approximate translation. In the end, sessions have a cumulative damaging effect where the edited document no longer has any resemblance with the pure-ODF original file. The induced direct formatting is so devastating that you frequently end up with a collection of individual pages separated by hard breaks (even in the middle of a word).

Direct formatting is a real nightmare but combined with DOCX it becomes hell.

The recommended workflow is to work on your computer ODF .odt and to export DOCX to your recipients with track changes enabled. When you receive a revised document, open it and look at the changes. Open you .odt and paste the changes as unformatted text (in order not to pollute your original with Word slags).

Your own editing and formatting optimisation will be much easier and comfortable with ODF.

You can also reverse the paradigm: M$ Word claims to be able to accept .odt (the truth is M$ implemented a proprietary-modified variant of ODF making it in fact incompatible with the standard).

Beware! Macros “fix” issues with direct formatting generally. And we’re back on the expressway to formatting hell.

Even if what I suggest on local work with ODF and manual merging may look like a boring constraint, it is much safer than working DOCX, document stability-wise.

If your recipients are imposing DOCX, ask them to provide you a licenced copy of Word. Working in native format is the simplest way to avoid problems.