Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 07-12-2014, 09:31 AM   #1
mikapanja
Perfectionist
mikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
Find straight quotes in the text

I'm editing an OCRd book with mixed straight and curly double quotes. Is there a way to find the straight ones in the text, outside the HTML tags, and replace them with the curly ones? A regular expression maybe?
mikapanja is offline   Reply With Quote
Old 07-12-2014, 09:58 AM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,003
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by mikapanja View Post
I'm editing an OCRd book with mixed straight and curly double quotes. Is there a way to find the straight ones in the text, outside the HTML tags, and replace them with the curly ones? A regular expression maybe?
NOT TESTED (in a mixed up usage)

Smarten Punctuation is a built in tool
theducks is offline   Reply With Quote
Advert
Old 07-12-2014, 10:28 AM   #3
mikapanja
Perfectionist
mikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
Quote:
Originally Posted by theducks View Post
NOT TESTED (in a mixed up usage)

Smarten Punctuation is a built in tool
Yes, I know about Smarten Punctuation, but would like to use a regular expression and do it manually.

Perhaps Kovid could help?
mikapanja is offline   Reply With Quote
Old 07-12-2014, 10:47 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,301
Karma: 27111240
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No, there isn't. In general the problem of converting straight quotes to curly quotes cannot be solved robustly without understanding the actual text.
kovidgoyal is online now   Reply With Quote
Old 07-12-2014, 11:15 AM   #5
mikapanja
Perfectionist
mikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
Quote:
Originally Posted by kovidgoyal View Post
No, there isn't. In general the problem of converting straight quotes to curly quotes cannot be solved robustly without understanding the actual text.
@ Kovid

How does Smarten Punctuation convert them? Is there something from the SP routine one could use in Search and Replace to deal with straight quotes manually?
mikapanja is offline   Reply With Quote
Advert
Old 07-12-2014, 11:26 AM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,301
Karma: 27111240
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
It uses an algorithm and that algorithm is not foolproof.
kovidgoyal is online now   Reply With Quote
Old 07-12-2014, 01:16 PM   #7
mikapanja
Perfectionist
mikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
OK, nailed the find part

To find single straight quotes outside HTML tags,
search for '(?!([^<]+)?>)

To find double straight quotes outside HTML tags,
search for "(?!([^<]+)?>)

The replace part is tricky, but that can be done manually, at least in my case, with relatively few instances of straight quotes.
mikapanja is offline   Reply With Quote
Old 07-12-2014, 06:39 PM   #8
weberr
New old guy
weberr began at the beginning.
 
Posts: 69
Karma: 10
Join Date: Feb 2012
Device: kindle fire
Quote:
Originally Posted by mikapanja View Post
OK, nailed the find part

To find single straight quotes outside HTML tags,
search for '(?!([^<]+)?>)

To find double straight quotes outside HTML tags,
search for "(?!([^<]+)?>)

The replace part is tricky, but that can be done manually, at least in my case, with relatively few instances of straight quotes.
Do you have any references re learning how to write 'replace' expressions?
weberr is offline   Reply With Quote
Old 07-12-2014, 08:28 PM   #9
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,621
Karma: 145864263
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Is there any easy way to find single quotes (not straight) that are not part of a contraction in order to convert them to double quotes? I find it odd reading a UK style eBook that has single quotes where I normally expect double quotes.
JSWolf is offline   Reply With Quote
Old 07-12-2014, 08:48 PM   #10
mikapanja
Perfectionist
mikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
Quote:
Originally Posted by weberr View Post
Do you have any references re learning how to write 'replace' expressions?
@ weberr

Nothing specific, but a lot of info is available here:
http://www.regular-expressions.info/
mikapanja is offline   Reply With Quote
Old 07-12-2014, 09:21 PM   #11
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,696
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by JSWolf View Post
Is there any easy way to find single quotes (not straight)...
Left single quote - in Insert Character (ctrl/alt/i) favourites (factory)

For dialogue will normally be preceded by space or a marker of some sort. But dialogue is not the only place they're used, I like to leave them single for things like... he played Billy Holiday’s ‘I Cover the Waterfront’ all night....

BR

Last edited by BetterRed; 07-12-2014 at 09:42 PM.
BetterRed is offline   Reply With Quote
Old 07-12-2014, 10:40 PM   #12
mikapanja
Perfectionist
mikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentametermikapanja can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
Quote:
Originally Posted by JSWolf View Post
Is there any easy way to find single quotes (not straight) that are not part of a contraction in order to convert them to double quotes? I find it odd reading a UK style eBook that has single quotes where I normally expect double quotes.
@ JSWolf

I believe this should cover it, but it will replace all the quotes, both in dialogues and outside them, except those that are part of a contraction. Of course, the book must have proper punctuation to begin with.

1) Replace opening single curly quotes with opening double curly quotes
Search:
Replace:

2) Replace closing single curly quotes with closing double curly quotes (two passes)

Search: ([.|…|,|:|;|?|!|\-|–|—])’
Replace: \1”

Search: ’([ |.|…|,|:|;|?|!|\-|–|—])
Replace: ”\1

Some of the combinations are unlikely to be found, but I guess better an overkill than missed instances
mikapanja is offline   Reply With Quote
Old 07-13-2014, 01:00 AM   #13
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,696
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by mikapanja View Post
@ JSWolf

I believe this should cover it, but it will replace all the quotes, both in dialogues and outside them, except those that are part of a contraction. Of course, the book must have proper punctuation to begin with.

1) Replace opening single curly quotes with opening double curly quotes
Search:
Replace:

2) Replace closing single curly quotes with closing double curly quotes (two passes)

Search: ([.|…|,|:|;|?|!|\-|–|—])’
Replace: \1”

Search: ’([ |.|…|,|:|;|?|!|\-|–|—])
Replace: ”\1

Some of the combinations are unlikely to be found, but I guess better an overkill than missed instances
Two passes on closing quotes are only required if punctuation is sometimes inside e.g ‘This is the end of the sentence.’ and other times outside e.g. ‘This is the end of the sentence’.; having both in the same text would be an exception, probably an error.

When converting single to double or visa versa one needs to be careful not to 'spoil' 6' 3" (Imperial length) 20' 15" (Time) and 33° 52' 34" S, 151° 13' 24" E (Geolocation).

And I've never seen an automated straight to curly that preserves the straight quotes on measurements. Shouldn't be too hard, if preceded by a digit leave it alone. Depends on the font, but to my eyes line B looks wrong.

A - 6' 3" (Imperial length) 20' 15" (Time) and 33° 52' 34" S, 151° 13' 24" E
B - 6’ 3” (Imperial length) 20’ 15” (Time) and 33° 52’ 34” S, 151° 13’ 24” E


I might start using « » on dialogue instead of “ ”

BR

Last edited by BetterRed; 07-13-2014 at 01:11 AM.
BetterRed is offline   Reply With Quote
Old 07-13-2014, 01:34 AM   #14
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,301
Karma: 27111240
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Smarten punctuation does preserve straight quotes on measurements. https://bugs.launchpad.net/calibre/+bug/1285351

To be precise it replaces them with the correct typographic prime
kovidgoyal is online now   Reply With Quote
Old 07-13-2014, 02:05 AM   #15
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,696
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by kovidgoyal View Post
Smarten punctuation does preserve straight quotes on measurements. https://bugs.launchpad.net/calibre/+bug/1285351

To be precise it replaces them with the correct typographic prime
I missed seeing that, I fix punctuation issues with Word macros I wrote years ago before I get to calibre conversion/editing etc, including measurement units. But I'm not averse to archiving old Word macros.

Added - and C looks even better (best)

C - 6′ 3″ (Imperial length) 20′ 15″ (Time) and 33° 52′ 34″ S, 151° 13′ 24″ E

BR

Last edited by BetterRed; 07-13-2014 at 02:36 AM.
BetterRed is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reducing file size for straight-text epub? Christi H ePub 5 01-10-2013 10:09 PM
Looking for a tool to find/fix mis-matched quotes... therealjoeblow Calibre 4 09-04-2011 01:25 AM
convert straight quotes to curly quotes alansplace Calibre 3 09-25-2010 03:51 PM
What's with all the straight quotes (inch marks)? DGReader ePub 35 03-03-2010 02:48 PM
Pielrf - Text to LRF with Easy TOC, Headers, Curly-Quotes, etc. (Mac!) EatingPie LRF 104 01-12-2009 12:35 PM


All times are GMT -4. The time now is 05:27 AM.


MobileRead.com is a privately owned, operated and funded community.