Ask Your Question
6

How do I convert straight quotes to typographic quotes? [closed]

asked 2012-05-13 21:33:55 +0100

ubersoft gravatar image

updated 2013-06-11 16:40:27 +0100

manj_k gravatar image

I'm in the middle of assembling chapters of a novel together that will eventually be sent out in both eBook and paperback format. When it's sent out for printing, I need the " symbols to be typographic--in other words, I need to use smart quotes (also known as "curly quotes"). This isn't an issue for chapters that I create in LibreOffice, but it is an issue on chapters that I create on other devices--notably my tablet, which currently has no software on it that supports smart quotes at all. When I import text from my tablet, I get the straight inch marks instead of the curled quotation marks.

In Microsoft Word, one trick you can do is simply do a search for (") and replace it with (") -- I know, it's exactly the same symbol, but it will actually go through and replace the straight quotes with the typographic quotes (though not always with 100% accuracy, I'm afraid). I vaguely remember there being a process for LibreOffice, but it was pretty complicated and involved using a lot of regular expressions in a non-intuitive way.

Do you know of any shortcuts, plugins, scripts or add-ons that can simplify replacing straight quotes with typographic quotes? Extra points for ones that handle both the single (') and double (") quotes.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-02-21 07:17:39.513315

6 Answers

Sort by » oldest newest most voted
1

answered 2012-05-13 21:40:30 +0100

ubersoft gravatar image

OK, I'm going to answer my own question. It's a feature I'd never noticed until now.

FIRST, make sure that the replacement of smart quotes is active in your autocorrect settings: Format > Autocorrect > Autocorrect Options...

SECOND, highlight the text that you want to apply your autocorrect options to (including and up to CTRL+A for the entire document.

FINALLY, use Format > Autocorrect > Apply to cause autocorrect to go through and apply it's autocorrect settings to the selected text.

This is a great feature!

edit flag offensive delete link more

Comments

1

This solution will NOT work if the paragraphs have a "style" other than "Default" applied to them. In my experimenting, this ONLY works if para is set to "Default". Any idea how to get this solution also to work with "styled" (Text Body, Quotations, Heading 1, etc.) paragraphs? Would be great!

David gravatar imageDavid ( 2012-10-20 14:17:29 +0100 )edit

The UI, in specific the menu structure, was modernised recently. Starting with V5.1.y (I think) the feature described was moved to > 'Tools' > 'AutoCorrect' > 'Apply'.

Lupp gravatar imageLupp ( 2016-02-29 14:34:16 +0100 )edit

Sadly, the limitation in my comment above persists into 5.0.x, anyway: text must have Default Style applied; it won't work if, e.g. Text Body is the style. It also incorrectly applies the typopgraphic-quotes, and then alters the style of the text anyway! The "macro" solution remains more reliable in my testing.

David gravatar imageDavid ( 2016-02-29 20:00:33 +0100 )edit
2

answered 2012-10-20 22:29:56 +0100

David gravatar image

updated 2016-02-29 13:45:49 +0100

 
[N.b. Now updated for 5.0.x, and Gist updated/corrected. 20160229]

My earlier reply stepping through the regex/search-replace steps certainly works. But the original question included this:

I vaguely remember there being a process for LibreOffice, but it was pretty complicated and involved using a lot of regular expressions in a non-intuitive way.

My sense about assigning this to a macro proved to be correct. Here is how you can (1) set up the macro, and (2) assign it to the menu bar for 1-click simplicity.

1. Set up macro

  1. Click on Tools > Macros > Organise macros > LibreOffice Basic... (a new window opens).
  2. In the left-hand box, you should see "[+] My Macros". Open that up by clicking on the "plus" sign to get "[+] Standard", open it and see "Module 1", now click on it. You should now see "Main" listed in the right-hand box, "Existing macros in: Module 1".
  3. Click on "Main" in the right-hand box, and now the "Edit" button to the right of it. A new window opens, and in the main text area, you should see "Sub Main" followed a blank line later by "End Sub". Good.
  4. Now we need to get the LO Basic code to paste in below that "End Sub" line. I have saved this as a "gist" on Gitub, but go to the raw version, hit CTRL-A to select all, then CTRL-C to copy to clipboard.
  5. Return to the LibreOffice Macro editor, position your cursor under the "End Sub" line, then hit CTRL-V to paste it in. Press CTRL-S to save it.
  6. Close the Macro editor.

Now when you go to Tools > Macros > Organise macros > LibreOffice Basic... (and My Macros > Standard > Module 1) again, you will see StraightQuotes2CurlyQuotes listed below Main. Good. It worked!

2. Assign to Menu

You could just run the macro from Tools > Macros > Organise macros > LibreOffice Basic..., click on StraightQuotes2CurlyQuotes, then click "Run" (the top button on the right). If you're doing this infrequently, that's probably good enough. If you think you might be using this more often, then it can be assigned to the menus by following these steps:

  1. Go Customise > Menus, then choose the menu you want to add your macro to from the Menu drop-down.
  2. Click the Add... button on the right of the dialog, and scroll to the bottom of the "Category" listing until you see > LibreOffice Macros.
  3. Click (to open) on My Macros > Standard > Module 1. You should now see StraightQuotes2CurlyQuotes listed in the right-hand "Commands" box. Click on it to select it.
  4. Click the Add button (which will add the macro to your chosen menu), then Close, to close the "Add Commands" dialog.
  5. You can now use the ⇧ and ⇩ buttons to locate the "Straight2Curly" macro precisely where you want it in the menu. When finished, click OK.
  6. You may need to close and re-open LibreOffice for your new entry to be visible in the ...
(more)
edit flag offensive delete link more

Comments

1

Works fine, only "…" (quotation mark·ellipsis·quotation mark) has to be replaced manually.

manj_k gravatar imagemanj_k ( 2012-12-01 14:10:56 +0100 )edit

Thank you for providing this (It looks like a LOT of work)!

I followed your instructions, but when I run the macro, hoping that foot marks will be replaced with apostrophes, instead foot marks are replaced with this: ’

What might I have done wrong -- or is this macro not meant to correct foot marks to apostrophes?

Thank you again for any further help you might be able to offer.

LPerkins gravatar imageLPerkins ( 2015-04-30 20:17:58 +0100 )edit

@LPerkins - I'm not sure what you mean by "foot marks"? Could you copy/paste the correct character you have now, and what you want to change it to? I still use this system, so it's working well for me! Should be easy to tweak to get it working properly for you, too.

David gravatar imageDavid ( 2015-04-30 23:26:50 +0100 )edit

This doesn't work well on v. 5.0.1.2 on a Mac (10.9.5). Not sure if it's related to the regexp problem cited below. Here's what I find:

"One" "two"

turns into

"Onene” "twonene” "two”

when the second replace segment runs. (I ran only this one to try to isolate the problem. That's why there are some straight marks in there.)

Haven't played with the code at all.

Eparch gravatar imageEparch ( 2015-09-13 02:29:19 +0100 )edit

@Eparch - now updated. If you test, please add some feedback here about whether it's working for you. Thanks!

David gravatar imageDavid ( 2016-02-29 13:45:01 +0100 )edit

Very thorough explanation. Works great.

Evil Overlord gravatar imageEvil Overlord ( 2016-05-17 18:39:32 +0100 )edit

I've followed these steps and it works fine for the most part. Except all of the punctuation just before the closing quotation mark is changed to $1. Every period, question mark, comma, exclamation point, etc gets changed. Is there a setting I can add to stop the macro from doing this? It's quite a job going back through hundreds of paragraphs to fix this individually. I believe it has to do with the difference between American English and Britsh English.

DragonDreads gravatar imageDragonDreads ( 2017-10-26 03:57:29 +0100 )edit

I have to amend my earlier comment, since somethin seems to have changed. I now have the same problem as @DragonDreads - it replaces the element before the end quote with a $1, which negates the value of the macro. It's frankly a lot easier to do all this in Word, and then transpose to LO.

Evil Overlord gravatar imageEvil Overlord ( 2018-11-22 18:23:05 +0100 )edit
1

answered 2013-02-18 17:19:50 +0100

shiyuan gravatar image

updated 2013-02-18 17:22:11 +0100

The commenting tool is not available to me and I can't upvote posts, very strange.

@David solutions work brilliantly when I was under ubuntu, particularly this expression:

 "(\<|[\[\(])

However on Mac the above expression is stop working. Not sure why, maybe it has different way of running regex? There is a post related to this.

I posted this and filed a bug, how there is a solution soon.

edit flag offensive delete link more

Comments

manj_k gravatar imagemanj_k ( 2013-02-18 22:19:42 +0100 )edit

@shiyuan - now updated - see my answer with the macro/Gist links for updates. Hope that helps!

David gravatar imageDavid ( 2016-02-29 13:47:52 +0100 )edit
1

answered 2012-10-20 15:28:59 +0100

David gravatar image

Answering my own comment ;) (well, partially)...

Where there are "styles" applied to paragraphs, the "Autocorrect > Apply" solution will not work. However, it is possible to use regex search-replace to speed up this process enormously. The instructions below are based on a very helpful discussion on the OpenOffice forum (do read through to the end, if it's of interest).

Double quotes

Hit CTRL-H to bring up the search/replace dialog; use the "More Options" drop-down, and select [x] Regular expressions. Paste in the following values:

First, Search for:

"(\<|[\[\(])

Replace with:

“$1

Click "Replace All".

Then, Search for:

(\>|[,.;!?\]\)])"

Replace with:

$1”

Click "Replace All". Now do a simple search for " (straight double-quote) to see if any have been missed. There shouldn't be many!

Single quotes

Much simpler: Search for [space]' and replace with [space]‘ for opener, then simply change all the rest of the ' marks to closer and that should do it. There might be cases of (' or [' which need to be catered for (my doc didn't have any), but the technique used for the double quotes will take care of those.

There must be a way of putting this all into a macro, but I haven't thought about that yet. So -- if preserving paragraph styles is important (it was to me in a 44-page imported and heavily styled document!), then this regex approach will get the job done very, very quickly.

edit flag offensive delete link more

Comments

I can't seem to type these slanted double quotes you have in the replace with fields. And if I copy from the posting here only the straight quotes are pasted into the replace field. So if I do the replace, the smart quotes do not get used.

I also use special formatting at times so replace is the way to go. I'm using LO 4.1 right now. Any ideas how to get the slanted quotes in the example above?

AwayTeam gravatar imageAwayTeam ( 2013-10-12 12:33:09 +0100 )edit
0

answered 2015-10-22 17:42:10 +0100

Francois_C gravatar image

"Onene” "twonene” "two”:

Not a specific Mac issue, David. I get the same error on v. 5.0.2.2 (x64) on Windows 7 64-bit, without playing with the code either…

edit flag offensive delete link more

Comments

Now updated. If you test, please add some feedback here about whether it's working for you. Thanks!

David gravatar imageDavid ( 2016-02-29 13:44:46 +0100 )edit

When I first ran the macro, I got the following error: undo = ThisComponent.UndoManager Basic Runtime Error Property or method not found. I rem'd that line; ran the program again and there was another undo-related error. I rem'd out that line; same thing happened again. Without the three Undo-related lines, the program ran fine. If someone is worried about undo...I don't know how to restore that functionality. The macro is a great fix.

mo gravatar imagemo ( 2016-04-15 11:22:43 +0100 )edit
0

answered 2016-02-17 06:33:46 +0100

DennisDaRev gravatar image

Here's what I finally came up with: Do the Find & Replace (CTRL+H) > use the "More Options" drop-down, and select [x] Regular expressions. (as suggested above) In the "Search For" box, type in "\< In the "Replace With" box, type CTRL+0147 (the ASCII number for a curly left quote). Then click "Replace all". This should take care of all of your left quote marks. Go back to CTRL+H, and in the "Search for" box, simply type in ". In the "Replace with" box, type CTRL+0148 (the ASCII number for a curly right quote). Click "Replace all," and all of your curly quotes should be taken care of. You can do the same thing with single quotes, just replace the " with a ', use CTRL+0145 for a left single, and CTRL+0146 for a right single.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2012-05-13 21:33:55 +0100

Seen: 30,300 times

Last updated: Feb 29 '16