Auto-formatting tool for removing double spaces

Discuss the word processor

Auto-formatting tool for removing double spaces

Postby prr » Wed Feb 03, 2010 4:44 pm

I often paste content from the web into a word processor, and would like to be able to eliminate double- and even triple-spacing between paragraphs in one fell swoop. Is there any such autoformatting command that I can use that would accomplish this? I didn't see anything in the OO user guide. I looked in the autocorrect options, and only saw in the Options tab, the option to remove blank paragraphs. Is this what I want to do? Or is there another option I can use? Or would I need a macro of some kind?
LO 6.0.6.2 on Windows 10
prr
 
Posts: 225
Joined: Wed Feb 04, 2009 5:37 pm

Re: Auto-formatting tool for removing double spaces

Postby RoryOF » Wed Feb 03, 2010 5:27 pm

Find and Replace will do the job. Press the Replace all button
Apache OpenOffice 4.1.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29799
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Auto-formatting tool for removing double spaces

Postby acknak » Wed Feb 03, 2010 11:39 pm

I often use something like this:

Edit > Find & Replace
Search for: [:space:]+
Replace with: space
Options: Regular expressions: YES

Click "Replace all"

That will replace one or more consecutive space characters of any kind (including things like non-breaking spaces) with exactly one plain space.

Stuff that's pasted from the 'Net has all kinds of oddball junk--beside the extra spaces--in it. It could be pretty handy to have a nice way to handle it.
AOO4/LO5 • Linux • Fedora 23
User avatar
acknak
Moderator
 
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Auto-formatting tool for removing double spaces

Postby Robert Tucker » Thu Feb 04, 2010 9:21 am

prr wrote:I often paste content from the web into a word processor, and would like to be able to eliminate double- and even triple-spacing between paragraphs in one fell swoop.

Do you mean it's creating extra paragraphs breaks, inserting blank paragraphs? You can eliminate these easily by installing AltSearch and searching for \p\p\p and replacing with \p\p. You might also want to look at this macro:

http://www.oooforum.org/forum/viewtopic.phtml?t=6429
LibreOffice 6.x.x on Fedora 31 and Ubuntu 19.10 (Dual Boot)
User avatar
Robert Tucker
Volunteer
 
Posts: 1247
Joined: Mon Oct 08, 2007 1:34 am
Location: Manchester UK

Re: Auto-formatting tool for removing double spaces

Postby prr » Fri Apr 30, 2010 12:00 am

Installed AltSearch but looking for \p\p didn't turn anything up. Not sure what the problem is. One click in MS Word does autoformatting which takes care of all of this for me. Hopefully I'll stumble across something here...
LO 6.0.6.2 on Windows 10
prr
 
Posts: 225
Joined: Wed Feb 04, 2009 5:37 pm

Re: Auto-formatting tool for removing double spaces

Postby prr » Wed May 05, 2010 7:11 pm

acknak wrote:I often use something like this:

Edit > Find & Replace
Search for: [:space:]+
Replace with: space
Options: Regular expressions: YES

Click "Replace all"

That will replace one or more consecutive space characters of any kind (including things like non-breaking spaces) with exactly one plain space.

Stuff that's pasted from the 'Net has all kinds of oddball junk--beside the extra spaces--in it. It could be pretty handy to have a nice way to handle it.


Can you explain exactly what you type in? What I typed in didn't come up with any hits. What do you type in with the search for, and replace with? The colon and plus sign confused me...
LO 6.0.6.2 on Windows 10
prr
 
Posts: 225
Joined: Wed Feb 04, 2009 5:37 pm

Re: Auto-formatting tool for removing double spaces

Postby acknak » Wed May 05, 2010 8:02 pm

You should type in the "Search for:" box exactly the bold text in my post:

    [:space:]+
In fact, you can copy/paste the blue text above into the box.

Type one space character in the "Replace with:" box.

Make sure that the "Regular expressions" option is on; you have to click on the "More Options" button to see it.
AOO4/LO5 • Linux • Fedora 23
User avatar
acknak
Moderator
 
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Auto-formatting tool for removing double spaces

Postby JohnV » Thu May 06, 2010 6:09 am

would like to be able to eliminate double- and even triple-spacing between paragraphs in one fell swoop.
I just wrote a macro to do this a week ago for another person with the same request.
Code: Select all   Expand viewCollapse view
Sub StripEmptyParagraphs
b = CInt(InputBox("Entry maximum empty paragraphs ( 0 is a valid entry ).",,1))
oDoc = ThisComponent
FandR = oDoc.createReplaceDescriptor
FandR.SearchRegularExpression = true
FandR.setSearchString("\n")
FandR.setReplaceString("\n")
oDoc.ReplaceAll(FandR) 'Change line breaks to paragraph breaks
oTC = oDoc.Text.createTextCursor
While oTC.isEndOfParagraph 'Remove blank paragraphs from top of doc.
  oTC.goRight(1,true)
  oTC.String = ""
Wend
Do While oTC.goToNextParagraph(False)
p = p + 1
Loop
oTC = oDoc.Text.createTextCursor
Do While oTC.gotoNextParagraph(false)
pc = pc + 1
If oTC.isEndOfParagraph then c = c + 1
If c > b then
  Do While oTC.isEndOfParagraph
  oTC.goRight(1,true)
  oTC.String = ""
  lc = lc + 1
  If lc > p then exit do
  Loop
  lc = 0
  c = 0
EndIf
If pc > p then exit do
Loop
End Sub
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Auto-formatting tool for removing double spaces

Postby prr » Fri May 07, 2010 9:03 pm

The macro works on some of these spaces between paragraphs, but not all. See, for example, this document. It will remove only a few of the large gaps.

EDIT: Acknak, thanks for clarifying your actions, but the same thing--on the attached doc, the vast majority (if not all) the spaces are not removed.
Attachments
Versailles.rtf
(49.74 KiB) Downloaded 234 times
LO 6.0.6.2 on Windows 10
prr
 
Posts: 225
Joined: Wed Feb 04, 2009 5:37 pm

Re: Auto-formatting tool for removing double spaces

Postby JohnV » Fri May 07, 2010 9:29 pm

When I open Versailles.rtf with OOo it is using a paragraph style with spacing both above and below the paragraph. Do Ctrl+A and apply the Default paragraph style and this spacing will go away.
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Auto-formatting tool for removing double spaces

Postby RoryOF » Fri May 07, 2010 9:39 pm

In Text Body style spacing above and below the paragraph is set to 0.42cm (say 12 pts). You should check the Help file on Styles and how to modify them.
Apache OpenOffice 4.1.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29799
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Auto-formatting tool for removing double spaces

Postby prr » Fri May 07, 2010 11:17 pm

RoryOF wrote:In Text Body style spacing above and below the paragraph is set to 0.42cm (say 12 pts). You should check the Help file on Styles and how to modify them.


The spaces I'm talking about are a lot greater than 2/5 of a cm.
LO 6.0.6.2 on Windows 10
prr
 
Posts: 225
Joined: Wed Feb 04, 2009 5:37 pm

Re: Auto-formatting tool for removing double spaces

Postby prr » Fri May 07, 2010 11:21 pm

JohnV wrote:When I open Versailles.rtf with OOo it is using a paragraph style with spacing both above and below the paragraph. Do Ctrl+A and apply the Default paragraph style and this spacing will go away.


OK that is one quick solution when this happens---select all, then apply a paragraph style that has no (or just limited) spacing before and after paragraphs. That actually wouldn't even require a macro....
LO 6.0.6.2 on Windows 10
prr
 
Posts: 225
Joined: Wed Feb 04, 2009 5:37 pm

Re: Auto-formatting tool for removing double spaces

Postby RoryOF » Fri May 07, 2010 11:39 pm

prr wrote:
RoryOF wrote:In Text Body style spacing above and below the paragraph is set to 0.42cm (say 12 pts). You should check the Help file on Styles and how to modify them.


The spaces I'm talking about are a lot greater than 2/5 of a cm.


They are most probably 0.42 cm after the para above and 0.42cm before the para below. Modify your Text Body Style to remove these two settings and see where that gets you.

 Edit: Also, turn ON Display Formatting characters and look at your file again. There are several extra paragraph marks which need to be removed. 
Apache OpenOffice 4.1.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29799
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Auto-formatting tool for removing double spaces

Postby Murph » Tue Jun 08, 2010 6:15 am

I am having the opposite problem - I have text with a mixture of single and double spacing and I would like to make sure it is all double spaced. I tried replacing ". " with ". " but this adds the extra space to an existing double space. Is there a code for a non-space character? e.g. say * = represents any letter or number I could replace ". *" with ". *"

Thanks

Murph
OOo 3.2.1, WinXP
Murph
 
Posts: 16
Joined: Thu Mar 18, 2010 2:12 pm

Re: Auto-formatting tool for removing double spaces

Postby Robert Tucker » Tue Jun 08, 2010 11:13 am

Murph wrote:I am having the opposite problem - I have text with a mixture of single and double spacing and I would like to make sure it is all double spaced. I tried replacing ". " with ". " but this adds the extra space to an existing double space. Is there a code for a non-space character? e.g. say * = represents any letter or number I could replace ". *" with ". *"

Search: ([^:space:]) ([^:space:])
Replace: $1 $2
(Regular expressions checked, of course)

for some reason has a problem with "I"s.

You could replace all spaces by two spaces then repeatedly replace three spaces by two spaces until no more three spaces are found.
LibreOffice 6.x.x on Fedora 31 and Ubuntu 19.10 (Dual Boot)
User avatar
Robert Tucker
Volunteer
 
Posts: 1247
Joined: Mon Oct 08, 2007 1:34 am
Location: Manchester UK

Re: Auto-formatting tool for removing double spaces

Postby acknak » Tue Jun 08, 2010 3:07 pm

Search: ([^:space:]) ([^:space:])

I don't think does what you expect it to do :shock:

I think it should work if you just use plain spaces in the pattern: ([^_])_([^_]) (where the "_" represents a plain space character).
AOO4/LO5 • Linux • Fedora 23
User avatar
acknak
Moderator
 
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Auto-formatting tool for removing double spaces

Postby Robert Tucker » Tue Jun 08, 2010 3:59 pm

acknak wrote:
Search: ([^:space:]) ([^:space:])

I don't think does what you expect it to do

No. I thought it would find any character except a space separated by a space from any character except a space. It does but not when an "I" is involved. I'd be interested in the explanation for that.

acknak wrote:I think it should work if you just use plain spaces in the pattern: ([^_])_([^_]) (where the "_" represents a plain space character).

Yes, I'd tried with (^ ) (^ ) but didn't have any success, of course.
LibreOffice 6.x.x on Fedora 31 and Ubuntu 19.10 (Dual Boot)
User avatar
Robert Tucker
Volunteer
 
Posts: 1247
Joined: Mon Oct 08, 2007 1:34 am
Location: Manchester UK

Re: Auto-formatting tool for removing double spaces

Postby acknak » Sat Jun 12, 2010 4:03 pm

It does but not when an "I" is involved. I'd be interested in the explanation for that.
Robert Tucker wrote:
acknak wrote:
Search: ([^:space:]) ([^:space:])

I don't think does what you expect it to do

No. I thought it would find any character except a space separated by a space from any character except a space. It does but not when an "I" is involved. I'd be interested in the explanation for that.

Anything other than "[:space:]" is not recognized as the named class. So [^:space:] is a plain, ordinary character class: it matches any character except the letters s, p, a, c, e or colon.

At least I think that's what happens--does that square with your "I" example?
AOO4/LO5 • Linux • Fedora 23
User avatar
acknak
Moderator
 
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Auto-formatting tool for removing double spaces

Postby Robert Tucker » Sat Jun 12, 2010 5:43 pm

acknak wrote:...does that square with your "I" example?

Looking at it again it seems more than the "I"s are affected. I get this result for Search for: ([^:space:]) ([^:space:]) Replace with: $1 $2.

Before:
space_replace-01.png
space_replace-01.png (6.68 KiB) Viewed 31471 times


After:
space_replace-02.png
space_replace-02.png (6.84 KiB) Viewed 31471 times


From your explanation I can understand that it doesn't change to a double-space between "opposite" and "problem". But why no double-space between "I" and "am" and "the" and "opposite" and so on?
LibreOffice 6.x.x on Fedora 31 and Ubuntu 19.10 (Dual Boot)
User avatar
Robert Tucker
Volunteer
 
Posts: 1247
Joined: Mon Oct 08, 2007 1:34 am
Location: Manchester UK

Re: Auto-formatting tool for removing double spaces

Postby Bill » Sat Jun 12, 2010 7:45 pm

There's another problem when single non-space characters are both preceded by a space and followed by a space. During a first run of Search and Replace, the combination of a character-space-"I" is found and replaced. The search then continues with the space following "I", so the combination of "I"-space-character isn't found during the first run. Search and Replace has to be run a second time to find the "I"-space-character combinations.
Bill
Volunteer
 
Posts: 7396
Joined: Sat Nov 24, 2007 6:48 am

Re: Auto-formatting tool for removing double spaces

Postby acknak » Sat Jun 12, 2010 11:20 pm

... why no double-space between "I" and "am" and "the" and "opposite" and so on?

The entire pattern has to match--if either one of the characters around the space matches the excluded class, the whole pattern fails to match. So "I a" doesn't match because "a" is a member of the excluded set; "e o" because "e" is excluded.

The problem posed is tough to do with a regular expression for English prose because English has complicated rules for punctuation. It often requires some analysis of the context to determine for sure where the end of a sentence is--at least for the general case.
AOO4/LO5 • Linux • Fedora 23
User avatar
acknak
Moderator
 
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Auto-formatting tool for removing double spaces

Postby bro.norman » Sun Aug 19, 2012 3:10 pm

Acknak's remedy resolve the same issue in LibreOffice 3.5. I was searching for the the tag in LibreOffice and after applying all of it, nothing worked. I know OpenOffice uses the same source code as LibreOffice so I googled the tag, this time instead of LibreOffice, I used OpenOffice. I tried Acknak''s remedy which was slightly different than that in LibreOffice' community. It worked. Thanks acknak.
LibreOffice 3.5
bro.norman
 
Posts: 1
Joined: Sun Aug 19, 2012 3:04 pm

Re: Auto-formatting tool for removing double spaces

Postby nikkitytom » Tue Feb 19, 2019 11:27 am

[quote="acknak" quote] Thanks so much. I’ve spend days looking for this solution. Typing [:space:]+ into the Find All box works like a charm. But ‘typing one space character’ into the Replace All box needs clarification. There’s no “character” for one space, instead you have to just press the space bar once ... be careful that the cursor is in position before you press that space bar. Only ONCE. What is confusing is that the space bar doesn’t show anything in the Replace All box. The cursor has merely advanced one space.
This works like a charm, but I’ve pulled out half my hair searching for it. :bravo:
OpenOffice 3.1 on Windows Vista
nikkitytom
 
Posts: 17
Joined: Sun Dec 16, 2012 3:17 am

Re: Auto-formatting tool for removing double spaces

Postby Bill » Tue Feb 19, 2019 1:05 pm

A space is a character. It's the first "printable" character on the list of ASCII characters.

ASCII

ascii codes
AOO 4.1.6 and LO 6.2.0.3 on Manjaro MATE
Bill
Volunteer
 
Posts: 7396
Joined: Sat Nov 24, 2007 6:48 am

Re: Auto-formatting tool for removing double spaces

Postby nikkitytom » Tue Feb 19, 2019 1:23 pm

Sorry, I stand corrected ... I was confused by the blank space. I followed your link ASCII and it is as complex String Theory. There are so many queries regarding this simple operation that I'm guessing I'm not alone in my befuddlement. "Hit the Space Bar once" would have solved the problem.
OpenOffice 3.1 on Windows Vista
nikkitytom
 
Posts: 17
Joined: Sun Dec 16, 2012 3:17 am


Return to Writer

Who is online

Users browsing this forum: No registered users and 35 guests