[Solved] Find/Replace: Line breaks to line break & Indent

Discuss the word processor
Post Reply
A.S.
Posts: 76
Joined: Mon Nov 25, 2013 1:00 pm

[Solved] Find/Replace: Line breaks to line break & Indent

Post by A.S. »

This topic is a continuation of one that started in Beginnings called Libre and Open Office where it was inappropriately located:
( viewtopic.php?f=5&t=103471#p500630 )

What I'm trying to do is change the formatting of a book from paragraphs defined throughout by an extra line break following each paragraph, to one in which the paragraphs are defined by an indent and there is no extra empty line between all the extra paragraphs. I would like to do this mechanically so that I can control those places where I need the extra line break to stay there.

I originally wanted to do this with an overview of what I'm doing, and so asked how to do this with a simple find and replace of the paragraph character by the indent character.

Below is the answer I first got (and my question) which has been moved to this topic. What I can say about the following instructions is that using ^$ (a hat and a dollar sign), I was able to mark the empty line following each paragraph. However, I was not able to replace this empty line with a tab or indent, so each following paragraph would appear as an indented paragraph.
Post by A.S. Mon Nov 2, 2020 10:22 am
Whether I use Libre or Open Office, I want to find and replace double paragraph endings (2 line breaks) with one line break and a tab. I don't know these names in the attributes and I can no longer copy the line breaks with my mouse so I can simply insert it into the find and replace. I expect this question needs to be elsewhere.
Post by Villeroy » Mon Nov 02, 2020 9:36 am
Yes, the extra question deserves another topic.
Anyway: menu:Edit>Find&Replace....
[More Options]
[x] Regular expressions
Search: ^$
Replace: <nothing, nada, empty>
[Replace All]
If I replace with "<nothing, nada, empty>", it prints that out exactly, including the < > marks. If I replace it with nothing at all, it doesn't have anything as a replacement. If I replace it with <> it jumps halfway down the text.

So I went back into Edit>Find & Replace> More Options> Regular Expressions > Format, and there's a tab there which describes Indents and Spacing.

If this whole change could be made with the Indent & Line Breaks, this might be easier.
Last edited by A.S. on Sat Dec 05, 2020 10:42 am, edited 2 times in total.
Open Office 4.1.7 - Win 10 pro x64
Bill
Volunteer
Posts: 8933
Joined: Sat Nov 24, 2007 6:48 am

Re: Find & Replace - line breaks with line break and tabs

Post by Bill »

It's not really easier. If you try to do it in one step using Find & Replace, it will use direct formatting instead of changing the paragraph style and will only change paragraphs which follow an empty paragraph, so you would have to go back through the whole document to fix any paragraphs which were missed. Use Find & Replace to delete the empty paragraphs, then change the indent setting in the paragraph style that is applied to the remaining paragraphs to change the indents globally.
AOO 4.1.14 on Ubuntu MATE 22.04
A.S.
Posts: 76
Joined: Mon Nov 25, 2013 1:00 pm

Re: Find & Replace - line breaks with line break and tabs

Post by A.S. »

Thank you. There aren't any indents. I'm not familiar with paragraph style and I'm not sure what direct formatting is, so I wanted to ask a little more, but first this question.

Why can't I see the formatting symbols in my document? In the Settings I have all of the check-marked to be visible.

This is where I am with replacing empty lines with indentations, by whatever means:

In the online help, I found the following:
The regular expression for the end of a paragraph is a dollar sign ($). The regular expression character combination for the start of a paragraph is a caret and a period (^.).

The regular expression for a tab character is \t.
Could I follow your suggestion to get rid of all the empty lines and then look for the end of paragraph sign ($) and replace that with ($ \t), assuming that I've marked the indentation in the formatting area at the top of the page? Or is there an easier way to tell Libre that following any ($) there should be a (/t) ?

I will try to read what paragraph style is. I know, everything's easy, once you know how to do it!
Last edited by A.S. on Sun Nov 08, 2020 3:23 pm, edited 1 time in total.
Open Office 4.1.7 - Win 10 pro x64
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find & Replace - line breaks with line break and tabs

Post by RoryOF »

If your text is formatted with a paragraph mark at the end of each text line, and a double paragraph mark at the end of each paragraph do this:

Use Find and Replace

Find ^$, Replace %%%% (or some similar token that does not occur in the document). More Options, set Regular Expressions on. Press Replace all

Now convert the single line paragraphs to continuous text:
Find $, Replace <space char>, More Options, set Regular expressions on, Replace all

Now reinstate the original text paragraphing:
Find %%%%, Replace \n, More options, set Regular Expressions on, Replace all.

All done.

If you have (in the original text) multiple blank lines, before reinstating the original text paragraphing, use Find and Replace to Find %%%% %%%%
(there may or may not be an intervening space - check in your document), and Replace %%%%, with More options unchecked, Replace all.

Do this until it finds no more occurrences of multiple %%%%, then do the reinstate original text paragraphing as set out above.

Now turn all your paragraphs from (probably) Default paragraph style into Text Body paragraph style, by using F&R

Drop more options and select Styles. Choose Default in the Find line, Text body in the Replace line. Replace all. Adjust Text Body style to have an initial Indent (hint: see its Indents and Spacing tab). Also to (probably) be Justified (hint: Alignment tab)

You may have to hand edit Chapter Headers and title page, but at least you did not have to individually hand edit each text paragraph.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Bill
Volunteer
Posts: 8933
Joined: Sat Nov 24, 2007 6:48 am

Re: Find & Replace - line breaks with line break and tabs

Post by Bill »

Replacing paragraph marks with anything can be dangerous because of the size limitation of paragraphs. It would be safer to just insert tabs at the beginning of the paragraphs.

For example, to insert a tab at the beginning of each paragraph with size 12 font, in Find & Replace, click in the "Search for" box, then select More Options > Format > Font and select size 12. Now tick the "Regular Expressions" option and the "Including styles" option. In the "Search for" box type

Code: Select all

^(.)
This will select the first character of a paragraph and memorize it.

In the "Replace with" box type

Code: Select all

\t&
This will replace the first character with a tab and reinsert the first character after the tab.

Now you can click "Replace all" to insert tabs at the beginning of all paragraphs where the first character is size 12.
AOO 4.1.14 on Ubuntu MATE 22.04
A.S.
Posts: 76
Joined: Mon Nov 25, 2013 1:00 pm

Re: Find & Replace - line breaks with line break and tabs

Post by A.S. »

Bill and Rory! Thank you very much for your help! I'm making progress.

I created a test piece with some pages from the long document that needs reformatting and when I copy anything out of the long text into a new Libre document, it turns from the font Times New Roman into Liberation Serif. I have to change it all back to Times New Roman.

I first tried out Format > Paragraph option and entered 5 pts for the first line, which works great, but it does change the entire document all at once. This makes me nervous. So, hoping to click through one paragraph at a time, I tried the Find&Replace option to put in the indent as a tab, because this would allow me more control over which paragraphs are indented.

I followed the instructions to do this, changed the font to Times New Roman 12 under Format > Paragraph > Format and it says Times New Roman 12 pt under both the Find and Replace windows. I then entered ^(.) into the Find box and \t& into Replace.

The effect was that when I hit "find next", it did not indent the paragraph but put the whole first paragraph into Liberation Serif, leaving it without the tab. I thought this was because I hadn't marked the tab, so I added the tab into the top ruler and retried the find and replace and it did the same thing as before. It did not put in a tab and it put the entire paragraph into Liberation Serif. I haven't used the font Liberation Serif anywhere in the original document, so I'm not sure why my document keeps wanting to go to that font.

I appreciate your help. I like learning these things.
Open Office 4.1.7 - Win 10 pro x64
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find & Replace - line breaks with line break and tabs

Post by RoryOF »

Before doing anything else, it may be helpful to read some instructions. Many have found this
Writer for students (several languages)
to be helpful.

For information, by using Styles correctly, I can take (as an example) a downloaded copy of War and Peace (500,000+ words) from Project Gutenberg, convert it into flowing text, and format it to standard book formatting in about ten minutes - using correct paragraph layout, chapter headers and numbering, page headers and numbering, page size and font.

So some little time reading how to use styles will save you a lot of time working by trial and error.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find & Replace - line breaks with line break and tabs

Post by RoryOF »

A useful overview of the use of Styles in OpenOffice is linked from this posting
viewtopic.php?p=275320#p275320
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Bill
Volunteer
Posts: 8933
Joined: Sat Nov 24, 2007 6:48 am

Re: Find & Replace - line breaks with line break and tabs

Post by Bill »

A.S. wrote:...into a new Libre document...
Your signature says OpenOffice 4.1.2. If you're using LibreOffice, please change your signature. My replies so far are based on OpenOffice and have not been tested in LibreOffice.
AOO 4.1.14 on Ubuntu MATE 22.04
Bill
Volunteer
Posts: 8933
Joined: Sat Nov 24, 2007 6:48 am

Re: Find & Replace - line breaks with line break and tabs

Post by Bill »

A.S. wrote:The effect was that when I hit "find next", it did not indent the paragraph but put the whole first paragraph into Liberation Serif, leaving it without the tab.
You have to hit "Replace" to insert the tab. "Replace" makes the replacement and moves to the next instance. "Find next" shouldn't change or insert anything at all. It should only move to the next instance. I can't duplicate what's happening with your font setting, but Liberation Serif is the default font in LO Writer on my system.
AOO 4.1.14 on Ubuntu MATE 22.04
A.S.
Posts: 76
Joined: Mon Nov 25, 2013 1:00 pm

Re: Find & Replace - line breaks with line break and tabs

Post by A.S. »

Hi Bill,
Churchill is credited (perhaps erroneously) as having said, that "You can always count on Americans to do the right thing – after they’ve tried everything else." In that regard, I'm quite American. :D

So, after you mentioned that your instructions were for an Open Office document because of my signature, and because I have Open Office installed, I simply opened the document in Open Office rather than Libre and tried the instructions again. As background information about the document, with the exception of manually removing all the page breaks, which I did do using Libre, all the previous work on the document has been done in Open Office. I don't mind using either one, but the computer I'm using (a recent acquisition) had Libre preinstalled and I thought I could just switch to that.

So, I tried your instructions again, this time using Open Office:
Bill wrote: For example, to insert a tab at the beginning of each paragraph with size 12 font, in Find & Replace, click in the "Search for" box, then select More Options > Format > Font and select size 12. Now tick the "Regular Expressions" option and the "Including styles" option. In the "Search for" box type

Code: Select all

^(.)
This will select the first character of a paragraph and memorize it.

In the "Replace with" box type

Code: Select all

\t&
This will replace the first character with a tab and reinsert the first character after the tab.

Now you can click "Replace all" to insert tabs at the beginning of all paragraphs where the first character is size 12.
The result was that it found the beginning of the next paragraph and removed the 1 1/2 line spacing, but it didn't insert an indent. I repeated replace several times and it did the same thing for each paragraph.

One of my reaonsfor wanting to do this manually, is that I can't see all the hidden information that is contained in characters like Paragraph Endings. I see that something's there when I don't get the expected result, but I don't know what's causing two paragraphs to act differently. I ran into this specifically with paragraph endings numerous times and corrected the problem by finding a paragraph ending where it worked, copying that paragraph ending and several more after it, and replacing the one that wasn't giving me the effect I want. I wish I could simply point at the Paragraph end symbols and see what they are doing.


@ Rory - I followed your link for Open Office Writer for Students and will give it more time. There are a lot of links, so it looks to be a bigger piece of reading than my hoped for "remove an empty line and put a tab in the front of the next paragraph". When I read "convert it into flowing text" in your response, I did a google search to try and figure out what flowing text is. I know all of these things are easy, but my first typing course was on an electric typewriter that hat a back-up button so you could insert the little correction papers and fix your errors and I also used those really lovely old black models where you need mighty fingers. The words "flowing text" brought me back to the reality that life has gone on and I haven't kept up. Thanks for your help.
Last edited by A.S. on Sun Nov 15, 2020 3:20 pm, edited 1 time in total.
Open Office 4.1.7 - Win 10 pro x64
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find & Replace - line breaks with line break and tabs

Post by RoryOF »

To explain, in case it needs clarification: often an OCRed file is presented as if it was from a typewriter - every line is terminated by Enter, and each paragraph is terminated by an extra blank line (Enter on its own). This does not permit flexible reformatting; for that, one has to turn it into what I termed "flowing text", where it is a stream of text with only Enter marking the end of each paragraph.

That permits each paragraph be reformatted easily, using change of font, size of type, length of line, interline spacing, paragraph structure.

My experience was that I needed to format about three longish documents - from memory, three 32 A5 page booklets - before becoming comfortable with OpenOffice's use of Styles.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
A.S.
Posts: 76
Joined: Mon Nov 25, 2013 1:00 pm

Re: Find & Replace - line breaks with line break and tabs

Post by A.S. »

Only the paragraphs have endings (not every line), but many of them have two paragraph endings, because I wanted to leave an empty line between most of the paragraphs.

I wonder if some of the results I'm now getting is because I moved the document from AOO to LO (and back again)? If I do a simple search for either ^$ or for ^(.) the result is that the paragraph loses its 1 1/2 spacing and goes to single spacing. It doesn't identify either the empty line or the paragraph beginning and it doesn't indent. I think this part is wrong ^(.) I think it's changing the spacing rather than offering an indent.

I'm just reading the information in the link you gave me about Ctrl 0, 1, 2, 3 and that looks useful. I tried them out and can see that they are pre-formatted with something default and I can see that those could be changed to whatever I want. So I'll try those out.

I understand the danger of formatting everything manually, but it does seem easier. lol :D
Open Office 4.1.7 - Win 10 pro x64
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find & Replace - line breaks with line break and tabs

Post by RoryOF »

If only the paragraphs have Pilcrows (backwards P symbols, turn on /View /Non printing characters to see these), it is safe to remove single (stand-alone) pilcrows, as the inter-paragraph spacing is (or can be) controlled by the Paragraph Style in use (F11 key), select Indents and Spacing tab on the Paragraph style in use, set Space Below paragraph non zero. To cause an initial indent on a paragraph, on that same tab, set a desired indent on the First Line setting (I would use my type size, such as 12 pt.), or, as you require a larger indent than that. leave that setting 0, and check Automatic.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Bill
Volunteer
Posts: 8933
Joined: Sat Nov 24, 2007 6:48 am

Re: Find & Replace - line breaks with line break and tabs

Post by Bill »

A.S. wrote:So, I tried your instructions again, this time using Open Office:
[quote="Bill]
For example, to insert a tab at the beginning of each paragraph with size 12 font, in Find & Replace, click in the "Search for" box, then select More Options > Format > Font and select size 12. Now tick the "Regular Expressions" option and the "Including styles" option. In the "Search for" box type

Code: Select all

^(.)
This will select the first character of a paragraph and memorize it.

In the "Replace with" box type

Code: Select all

\t&
This will replace the first character with a tab and reinsert the first character after the tab.

Now you can click "Replace all" to insert tabs at the beginning of all paragraphs where the first character is size 12.
The result was that it found the beginning of the next paragraph and removed the 1 1/2 line spacing, but it didn't insert an indent. I repeated replace several times and it did the same thing for each paragraph.[/quote][/quote][/quote][/quote]
My instructions were for "Replace all" which I did test in AOO, not "Find" then selectively "Replace" which I did not test in AOO. After testing using "Replace" instead of "Replace all", Writer did not insert a tab and changed the paragraph style from "Default" to "Textformatvorlage" which had single line spacing. If you're going to use "Replace" instead of "Replace all", then you could probably use the Search for Styles option to selectively replace the "Default" style with the "First line indent" style. This will give you a true indent without inserting a tab.
AOO 4.1.14 on Ubuntu MATE 22.04
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Find & Replace - line breaks with line break and tabs

Post by John_Ha »

Trying to find every formatting error and correcting each you find is very time consuming and error prone.

Experience shows if you have a mixture of direct and styled formatting it is almost always quicker to remove all formatting so that you can start from scratch with plain unformatted text. Edit > Select All. Ctrl+M. That's four mouse/keystrokes and all the formatting is gone. Now define the styles you want to use and apply them. Try it on a copy - you will be surprised how quick it is.

Typically it will take me an hour or so for a 200 page book and the result will be much easier to handle as it isn't a mixture of direct and indirect. Of course, once everything else is done and you are concentrating on final "print page" layout, you may need to tweak things with direct formatting so that you don't get odd things like a page with just a few words on it etc.

I think setting a Gap after paragraph is much more aesthetic than using a blank line - I use a 2mm gap for 11 or 12 point text.

Remove empty paragraphs with a regular expression Find ^$ and Replace with nothing.

Also see OOoFBTools in [Tutorial] How do I remove end_of_paragraph marks? where empty paragraphs (and much more) can be selected as a menu item.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
A.S.
Posts: 76
Joined: Mon Nov 25, 2013 1:00 pm

Re: Find & Replace - line breaks with line break and tabs

Post by A.S. »

Hi Rory, Bill and John Ha,

Thank you for your help. Amazing!
Bill wrote:My instructions were for "Replace all" which I did test in AOO, not "Find" then selectively "Replace" which I did not test in AOO. After testing using "Replace" instead of "Replace all", Writer did not insert a tab and changed the paragraph style from "Default" to "Textformatvorlage" which had single line spacing. If you're going to use "Replace" instead of "Replace all", then you could probably use the Search for Styles option to selectively replace the "Default" style with the "First line indent" style. This will give you a true indent without inserting a tab.
This explains why I was getting a different result than I was expecting. Thank you. I always run away when I see the word Textformatvorlage. lol

I tried the search for hat (caret) and dollar sign ^$ and found that I can remove the empty lines with this now that I'm in Open Office instead of Libre.

I tried removing the formatting using Ctrl M and that works, however, it removes both italics and bold.

Rory, after you downloaded War and Peace, how did you keep all the italicized and bold words and passages italicized and bold? I envision having to go through 450 pages and find all the words and passages that are italicized or in bold and redo them all either with i & B buttons or by highlighting them and pointing at a style. Is there some way to leave those formatted the way they are or did you go through all of War and Peace to pick those up?

RoryOF wrote:If only the paragraphs have Pilcrows (backwards P symbols, turn on /View /Non printing characters to see these), it is safe to remove single (stand-alone) pilcrows, as the inter-paragraph spacing is (or can be) controlled by the Paragraph Style in use (F11 key), select Indents and Spacing tab on the Paragraph style in use, set Space Below paragraph non zero. To cause an initial indent on a paragraph, on that same tab, set a desired indent on the First Line setting (I would use my type size, such as 12 pt.), or, as you require a larger indent than that. leave that setting 0, and check Automatic.
I'm not quite out of questions but am moving cautiously forward, testing and learning.

For anyone else who's new to this like I am, I found a helpful youtube video that is very simplified, showing some easy hands-on steps that show you how to use Open Office to format an existing text for an ebook. I'm thinking that the text in the video may be without formatting to start with. For anyone else who might be struggling with the concept of styles, this was a good introduction to get used to the vocabulary and where stuff is and what you need or don't need to get started with formatting a book. It gave me a chance to understand more of the information in this whole thread. For anyone interested:

Apache Open Office Styles & Formatting for ebooks Part 1
https://www.youtube.com/watch?v=oTf0WrgXC0E

Thanks again!
Open Office 4.1.7 - Win 10 pro x64
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find & Replace - line breaks with line break and tabs

Post by RoryOF »

The War and Peace I downloaded was plain text, with no formatting, so I didn't pick out italicized or bold text, which does not occur in all editions of W&P. In the case that the area of text is in French it usually shows up highlighted as spelling errors and it is easy enough to format this in italics or as required.

I prefer to get my information from written sources rather than youtube videos, applying it to a short demo file until I am comfortable with it.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
A.S.
Posts: 76
Joined: Mon Nov 25, 2013 1:00 pm

Re: Find & Replace - line breaks with line break and tabs

Post by A.S. »

RoryOF wrote:I prefer to get my information from written sources rather than youtube videos, applying it to a short demo file until I am comfortable with it.
The thing that can be helpful for me with some Youtubes is that the steps are shown. I watch where the pointer goes, stop the video and then go find that on my computer. I'm not the type of person who can listen to clarifications of things for very long, but seeing it take place before my eyes is helpful. Once I watched what this person was doing, I suddenly had a clearer picture of what styles are about. The vocabulary often throws me when I come into a new area.

Since I didn't do the smart thing, which would have been to format the text at the beginning, I'm going to do everything I can in Open Office and then try Scrivner, which I've never used, and see if it can pick up the italics. I like the idea that the italicized parts might be caught by the spellchecker. The dictionary was never corrected to ignore things like the foreign words, so that may also work.

Thanks for now. I appreciate all this information and am working on it.
Open Office 4.1.7 - Win 10 pro x64
A.S.
Posts: 76
Joined: Mon Nov 25, 2013 1:00 pm

Re: Find & Replace - line breaks with line break and tabs

Post by A.S. »

I return. I downloaded the trial version for Scrivener and in the very last segment of the tutorial, it says this:
Scrivener is really about “hammering out” that draft; it is not a word processor or full page layout program, so at some point—unless you just want a very basic manuscript—you may well want to move your work into a word processor or dedicated scriptwriting program for final formatting.
Okay, so this entire Find & Replace topic has been really helpful. I have another last question, but I wonder if it needs a new topic.

I was able to remove all the unwanted page breaks, remove all the lines between paragraphs and indent all the paragraphs. I also found a post here in the forum about how to save the italics and bold: https, which I'm going to try.

viewtopic.php?f=7&t=103638&p=501512&hil ... ph#p501512

What I need now is to figure out how to keep the first paragraph after a segment or chapter heading from indenting, as those need not to be indented.
Open Office 4.1.7 - Win 10 pro x64
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find & Replace - line breaks with line break and tabs

Post by RoryOF »

In my case I use two separate Paragraph styles; one used after a segment separator is called TextBodyNoIndent, it is identical to Text Body with the exception that it is set to have no initial indent (on its Indents and Spacing tab, set Indent First line to be 0, and make sure Automatic is unchecked). The other is called FirstPara, used for chapter opening paragraphs; identical to TextBodyNoIndent, except that it is set to use a Drop Cap as the opening character. Each of these is set to use Text Body as the continuation paragraph style.
 Edit: Depending on the complexity of your formatting, Scrivener may be overkill. I format classical text (novel type) formatting using OpenOffice and find it quite satisfactory. 
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Post Reply