| View previous topic :: View next topic |
| Author |
Message |
tfg004 Newbie

Joined: 18 Jun 2007 Posts: 3
|
Posted: Mon Jun 18, 2007 4:32 am Post subject: How to replace existing standard quotes with custom quotes ? |
|
|
Hi,
I have lots of documents which were written in OOo v1.x with standard quotes.
I'm using v2.0.4 now and have standard quotes automatically replaced with custom quotes by the AutoCorrect settings.
However, I couldn't find a way to automatically replace the standard quotes in all my older documents.
I found an old thread about this, and user RGB suggested:
| Quote: | | The opening quotes usually comes with a space before them, and the closing ones with a character instead: if you do a search-replace using space+normal quote, and replacing it by space+custom quote, you will be able to replace the opening quotes, then, doing a search-replace using normal quotes -> custom quotes, you will be able to replace the closing ones. |
However, that is no option for me as the opening quotes in my documents usually are not after a space, but at the start of a sentence. But sometimes also after a space or tab.
The same with the close quotes, they could be followed by spaces, dots, commas, tabs, end of lines, etc.
Does anyone have any idea how to replace all my existing standard quotes with custom quotes ?
Thank you very much in advance for your help.
-tfg004 |
|
| Back to top |
|
 |
RGB Super User


Joined: 25 Nov 2003 Posts: 1743 Location: In Lombardy, near a glass of red Tuscany wine
|
Posted: Mon Jun 18, 2007 4:45 am Post subject: |
|
|
Format -> autoformat -> Apply.
It is simpler than my (forgotten) old answer... |
|
| Back to top |
|
 |
tfg004 Newbie

Joined: 18 Jun 2007 Posts: 3
|
Posted: Mon Jun 18, 2007 6:31 am Post subject: |
|
|
I already tried that, but it didn't work  |
|
| Back to top |
|
 |
BillP Super User

Joined: 07 Jan 2006 Posts: 2702
|
|
| Back to top |
|
 |
acknak Moderator


Joined: 13 Aug 2004 Posts: 4295 Location: ~ 40°N,75°W
|
Posted: Mon Jun 18, 2007 7:48 am Post subject: |
|
|
If you have to resort to Find & Replace, you can do a pretty good job with
Search for: "\<
Replace with: “ (U+201C LEFT DOUBLE QUOTATION MARK)
Options / Regular expressions: ON
Repeat using
Replace with: ‘ (U+2018 LEFT SINGLE QUOTATION MARK)
That will handle almost all the opening quotes correctly.
Once that's done, you can use straight F&R on the remaining (closing) ascii quotes. |
|
| Back to top |
|
 |
tfg004 Newbie

Joined: 18 Jun 2007 Posts: 3
|
Posted: Mon Jun 18, 2007 8:12 am Post subject: |
|
|
The F&R with Regular expressions did the job.
Thanks
-tfg |
|
| Back to top |
|
 |
bluegecko General User

Joined: 12 Jun 2007 Posts: 49 Location: Portugal
|
Posted: Thu Sep 06, 2007 3:55 pm Post subject: |
|
|
The same limitation was bugging me for ages (why on earth OOo's Autoformat only works on Default paragraph styles I don't know!). Anyway, in case this helps others looking for a simple solution, here's a macro I wrote to do the business. It should also correctly change apostrophes (ie single quotes within words, like we'd or o'clock). There's a bit of a kludge required as OOo's implementation of Regular Expressions does not permit placing matched substrings in the replace field.
For ease of use, you could associate the macro with a hot key.
| Code: | rem **********************************************************************
rem TYPOGRAPHIC QUOTES
rem **********************************************************************
rem ---- this macro changes dumb quotes to curlies regardless of styles
rem ---- (unlike OOo's in-built "Autoformat" function)
Sub TypographicQuotes
oDoc = thisComponent
' character codes used in this macro
' Chr(34) double quote
' Chr(39) single quote
' Chr(8216) single quote left
' Chr(8217) single quote right
' Chr(8220) double quote left
' Chr(8221) double quote right
aFind = Array(""+_
Chr(34)+"\<",_
Chr(34),_
Chr(39)+"\<",_
Chr(39),_
"[0-9A-Za-zÀ-Ö\x00D8-\x00F6\x00F8-\x021B\x1E80-\x1EF3\xF730-\xF739\xFB00-\xFB06]\>"+Chr(8216)+"\<",_
Chr(8216)+"OOoRegExSucks"_
)
' The line beginning "[0-9 and ending +"\<",_ should be on one line.
' It's a workaround for OOo's lack of substring matching in RegEx when using find/replace.
' It appends a temporary tag to left single quotes when following words or numbers
' To avoid another bug/limitation, characters allowed at word-ends are defined in hex ranges
' (includes all Latin characters you're ever likely to need, plus the Unicode range for hanging/oldstyle figures)
aReplace = Array(""+_
Chr(8220),_
Chr(8221),_
Chr(8216),_
Chr(8217),_
"&OOoRegExSucks",_
Chr(8217)_
)
aRayCount = 0
FandR = oDoc.createReplaceDescriptor
FandR.SearchCaseSensitive = true
FandR.SearchRegularExpression = true
While aRayCount <= uBound(aFind)
FandR.setSearchString(aFind(aRayCount))
FandR.setReplaceString(aReplace(aRayCount))
aRayCount = aRayCount + 1
oDoc.ReplaceAll(FandR)
Wend
End Sub |
|
|
| Back to top |
|
 |
samdiener General User

Joined: 16 Oct 2009 Posts: 5
|
Posted: Sun Nov 07, 2010 8:42 am Post subject: Trying to install my first macro to get this to work |
|
|
Hello,
I'm a newbie trying to install this macro. I've never installed a macro before.
I tried following the instructions in the Getting Started with Macros document: http://documentation.openoffice.org/manuals/oooauthors2/0117GS-GettingStartedWithMacros.pdf
On page 13 of that document, it says,
"Some macros are contained in documents, some as regular files
that you must select and import, and some as macro text that should be copied and pasted into the Basic IDE; use Tools > Macros > Organize Macros > OpenOffice.org Basic to open the OpenOffice.org Macros dialog, choose the macro to edit, and then click Edit to open the macro in the Basic IDE."
So I went to Organize Macros and OpenOffice.org Basic, then chose new.
I pasted the text you suggest for creating a smartquotes macro into the document.
This sounds lke a ridiculously easy question, but now what?
I tried clicking compile, but I got a syntax error saying "undexpected symbol: +." strangely, this error did not stop on the first plus sign in the afind command, but in the line with "Chr(34)+"\<",_"
I also don't see how to save it with a name like "SmartQuotes" or if that's even what I should do, because it seems to want to name it "My Macros & Dialogs.Standard". One more question: on a mac, do you know to where I save this? I imagine it might be in an openoffice library or something, but I'm not sure where. |
|
| Back to top |
|
 |
floris_v Moderator


Joined: 12 Jul 2007 Posts: 4605 Location: Netherlands
|
Posted: Sun Nov 07, 2010 9:58 am Post subject: |
|
|
It's really much simpler than that.
Tools - macros - OOo Basic - Organizer. Navigate to My macros - Standard - Module 1. Select any macro in the list and click Edit. That opens the macro editor. Scroll down to the bottom of the screen and paste the macro text there, close the editor screen (changes are saved automatically). You can now run that macro. _________________ LibreOffice 3.6.3; OOo 3.4.1 on Windows Vista
Join the Official community forum - in several languages, including Nederlandstalig forum |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8983 Location: Lexinton, Kentucky, USA
|
Posted: Sun Nov 07, 2010 1:53 pm Post subject: |
|
|
| Quote: | | I got a syntax error saying "unexpected symbol: +." | A trailing space after
aFind = Array(""+_
would cause that error. |
|
| Back to top |
|
 |
samdiener General User

Joined: 16 Oct 2009 Posts: 5
|
Posted: Mon Nov 08, 2010 12:25 am Post subject: That got it working! |
|
|
Thanks JohnV and floris_v. I appreciate your help.
floris_v - The method I used it turned out did insert it right where you said it would be, but your method for inserting macros is much simpler. It would be great to get that into the documentation. Is there someone I should contact about suggesting that, or a wiki where I should credit you and paste what you said in so that future users might find it easier?
And JohnV, the trailing space you mentioned did kick up that error, and after I fixed that one I got another set of errors saying essentially the same thing. There was a single trailing space after a bunch of lines as I copied them from up above.
I removed those trailing spaces, clicked close as you said, ran the macro, and voila, it worked as advertised. Very cool. Thanks to the macro's author, also.
I'm pasting in below the version I used that worked:
| Code: | rem **********************************************************************
rem TYPOGRAPHIC QUOTES
rem **********************************************************************
rem ---- this macro changes dumb quotes to curlies regardless of styles
rem ---- (unlike OOo's in-built "Autoformat" function)
Sub TypographicQuotes
oDoc = thisComponent
' character codes used in this macro
' Chr(34) double quote
' Chr(39) single quote
' Chr(8216) single quote left
' Chr(8217) single quote right
' Chr(8220) double quote left
' Chr(8221) double quote right
aFind = Array(""+_
Chr(34)+"\<",_
Chr(34),_
Chr(39)+"\<",_
Chr(39),_
"[0-9A-Za-z�-�\x00D8-\x00F6\x00F8-\x021B\x1E80-\x1EF3\xF730-\xF739\xFB00-\xFB06]\>"+Chr(8216)+"\<",_
Chr(8216)+"OOoRegExSucks"_
)
' The line beginning "[0-9 and ending +"\<",_ should be on one line.
' It's a workaround for OOo's lack of substring matching in RegEx when using find/replace.
' It appends a temporary tag to left single quotes when following words or numbers
' To avoid another bug/limitation, characters allowed at word-ends are defined in hex ranges
' (includes all Latin characters you're ever likely to need, plus the Unicode range for hanging/oldstyle figures)
aReplace = Array(""+_
Chr(8220),_
Chr(8221),_
Chr(8216),_
Chr(8217),_
"&OOoRegExSucks",_
Chr(8217)_
)
aRayCount = 0
FandR = oDoc.createReplaceDescriptor
FandR.SearchCaseSensitive = true
FandR.SearchRegularExpression = true
While aRayCount <= uBound(aFind)
FandR.setSearchString(aFind(aRayCount))
FandR.setReplaceString(aReplace(aRayCount))
aRayCount = aRayCount + 1
oDoc.ReplaceAll(FandR)
Wend
End Sub |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|