Find and replace with page break when not at the end of a word/line

I write a document in text format and then open it up in Writer. Each chapter begins with a string, “section_break”, and I use this to do a Find and Replace with a page break (Format → Paragraph… → Text Flow → Breaks → Insert → Page → After.

The issue is that I’m ending up with blank pages in the document. Originally the “section_break” string began and ended with line breaks, and I thought those were the issue. I removed them, and now the string connects to the Chapter word and number. Now when I Find and Replace, it inserts the page break after the Chapter and Number, and not just the “section_break”.

For example, if the line ends with “__section_break__Chapter 2”, then the page break is inserted after the 2. I want it to be inserted before the C in Chapter.

Suggestions?

Thanks!

Leam

not sure I get the whole thing, but seems you’re searching against look ahead

something like __section_break__(?=Chapter +\d+)
or just __section_break__(?=Chapter)

Each chapter is a separate text file and building the book is automated. Part of the automation is to start with a blank “chapter”, add “section_break” if this isn’t the first chapter, then add “Chapter” and the number, and then the text of the chapter. Then add that to the main “book” text.

The goal is to Find section_break and replace it with a page break so that each chapter starts at the first line on a new page. I can’t put the page break before the replacement as it adds a newline before “Chapter”.

Then your text structure is strange. There is no reason that a page break Before adds a new line unless you put this page break on a separate line.

This is what styles are made for. Just apply Heading 1 on your chapter heading paragraph. If you Heading 1 Text Flow tab requests a page break Before, everything will happen as you expect.


As I mentioned in my answer, “Chapter” and number can be automatically added to your heading. Configure them in Tools>Heading Numbering.

Due to stupid habits of Word aficionados (their relentless to leave mechanical typewriter era and its idiosyncrasies, notably vertical spacing with empty paragraphs), Writer tries to correct these bad habits with “compatibility rules”. One of these is: empty Heading n paragraphs are not considered headings. Consequently, your automatic chapter heading must at least contain one space.

Globally, I don’t quite understand your workflow. It looks to me a huge loss of time and a lot of manual operations compared to initial styling. Also with modern computers, there is no advantage in splitting a book into several files. Writer can handle documents up to 800-1000 pages without noticeable degradation in performance.

Your error is to request a page break After.

But your whole workflow is also faulty. What you do is to add direct formatting on you text. This will cause you a lot of trouble when you start tuning your formatting and layout.

The “Writer-way” of formatting text is to use styles. There are styles for paragraphs, characters, pages, frames (image area) and list (in fact list bullet/numbering and indent).

In your case, you should use built-in paragraph styles Heading n with n=1 for chapter, n=2 for subchapters, etc. Apply an adequate Heading n on your “section break” paragraphs.

When done, customise Heading n so that they look they way you want. It will apply instantly on all so-styled paragraphs. Heading n paragraphs can also be auto-numbered. This is configured in Tools>Heading Numbering.

Note that text “__section__break__Chapter n” is useless in Writer. It is certainly useful, perhaps mandatory in your plain text file, but redundant in Writer. So, once you have style the paragraph, remove this noise text. I assume that chapter heading follows “section …”. If this is not the case (the heading is the next paragraph), apply Heading n on the real heading. Numbering and labelling will happen as definded in Tools>Heading Numbering and you can request a Page break Before in Heading n.

One last advice: don’t forget to remove your direct formatting (DF) because DF has precedence over styling. Therefore if you have conflicting settings on the same parameter in DF and style, DF wins and you lose all advantages and benefits of styles.

To make these formatting persistent, save your document as .odt.

I recommend you read the Writer Guide for an introduction to styles.