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 01-08-2015, 11:57 AM   #1
Pam E.
Member
Pam E. began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
F/R Question

What would be the best way to fix fractions (in Calibre's Edit Book) when they use this code below instead of a real fraction?

<li class="ing"><span class="fraction"><span class="numerator">1</span><span class="virgule">⁄</span><span class="denominator">8</span></span> teaspoon freshly ground black pepper</li>

The above is VERY messy!

I would like it to be this instead:

1/8 teaspoon freshly ground black pepper

I do not like the one-character (symbol fractions, such as ¼) either but I can easily f/r those.

Thank you!
Pam E. is offline   Reply With Quote
Old 01-08-2015, 12:00 PM   #2
Pam E.
Member
Pam E. began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
Here's another example:

<li class="ing"><span class="fraction"><span class="numerator">1</span><span class="virgule">⁄</span><span class="denominator">3</span></span> cup dried cranberries</li>

I would rather it simply be:

<li class="ing">1/3 cup dried cranberries</li>
Pam E. is offline   Reply With Quote
Advert
Old 01-08-2015, 09:04 PM   #3
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
You could just use a simple Regex. What you want to do is when you are in the Calibre Editor, when you do a Find, you want to make sure that you set the Mode to "Regex":

Click image for larger version

Name:	CalibreRegex.png
Views:	226
Size:	91.3 KB
ID:	133555

Then you can use this Search/Replace:

Search: <span class="fraction"><span class="numerator">([0-9]+)</span><span class="virgule">⁄</span><span class="denominator">([0-9]+)</span></span>

Replace: \1/\2

In English:

What this says in English is: "find the spans with fraction + numerator" + "grab the number and stick it in \1" + "find the spans with the virgule and denominator" + "grab the number and stick it in \2".

Replace with "the first captured number" + "slash" + "the second captured number".

Your examples:

<li class="ing"><span class="fraction"><span class="numerator">1</span><span class="virgule">⁄</span><span class="denominator">8</span></span> teaspoon freshly ground black pepper</li>

<li class="ing"><span class="fraction"><span class="numerator">1</span><span class="virgule">⁄</span><span class="denominator">3</span></span> cup dried cranberries</li>

This should give you the exact output you were looking for.

Last edited by Tex2002ans; 01-08-2015 at 09:16 PM.
Tex2002ans is offline   Reply With Quote
Old 01-08-2015, 09:16 PM   #4
Pam E.
Member
Pam E. began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
Thanks so much! This works perfectly. I need to learn regex.
Pam E. is offline   Reply With Quote
Old 01-08-2015, 09:24 PM   #5
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by Pam E. View Post
Thanks so much! This works perfectly. I need to learn regex.
Yes, it is quite helpful, especially for easy things like that where you can recognize a very simple pattern.

Also, one word of warning. Regexes can be very powerful, so always save a backup copy before running Regex on it. You might make one minor typo, and it could blow up in your face. Definitely don't press "Replace All" unless you have tested it out thoroughly, and see that it works perfectly.

To be on the safe side, I would just go through the entire book and just "Replace" one-by-one... at least until you become much more familiar with Regex.
Tex2002ans is offline   Reply With Quote
Advert
Old 01-08-2015, 09:29 PM   #6
Pam E.
Member
Pam E. began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
Thanks again! It worked great even with those like 2/3, etc. There were about 30 changes. I did a Replace one at a time to make sure it worked as it should. It did! The only thing I had to adjust was a couple of time when I needed to add a space...11/2 to 1 1/2. Beautiful!! My book is much cleaner to view in my ebook reader too. Thank you so much for taking the time to explain in ENGLISH what the code meant. That is very helpful in understanding how it works. You're awesome!! Made my day!

Thanks for the screenshot too.

Last edited by Pam E.; 01-08-2015 at 09:32 PM.
Pam E. is offline   Reply With Quote
Old 01-10-2015, 12:39 PM   #7
signum
Zealot
signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.
 
Posts: 119
Karma: 64428
Join Date: Aug 2011
Device: none
One tiny little addition-

The search pattern suggested above is tedious to type in and ensure its you haven't made a typo somewhere. You can save a lot of typing by highlighting the code and then typing ctrl-f, as if you were searching for it.

Then, all you have to do is edit the search pattern to replace the digits with (\d+) and construct the replacement pattern, just as above.
signum is offline   Reply With Quote
Old 01-10-2015, 03:31 PM   #8
Pam E.
Member
Pam E. began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
Thank you! I'll play with that on a copy of my epub and see what happens.
Pam E. is offline   Reply With Quote
Old 01-10-2015, 08:34 PM   #9
Pam E.
Member
Pam E. began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
One more f/r question. I'd like to change these to three-character fractions:

1½ pounds fresh crabmeat, picked over for shells
1½ cups fresh corn (or frozen corn, thawed)
¾ cup diced red bell pepper
¾ cup chopped celery
¾ cup finely chopped yellow onion
1½ cups mayonnaise
¾ teaspoon dry mustard
¾ teaspoon salt
½ teaspoon freshly ground black pepper
1 large egg, lightly beaten
2½ cups saltine cracker crumbs, divided
2 tablespoons unsalted butter, plus more as needed


Is there an easy way for it to find all fractions that are symbols and replace them all at once?

I'd like there to be a space between the replaced fractions when necessary, such as the black pepper doesn't need one but the saltine cracker crumbs do, like this:

1/2 teaspoon freshly ground black pepper
2 1/2 cups saltine cracker crumbs, divided

Right now I do a normal f/r on each fraction to find ½ and replace with 1/2. Then I go back through and manually add a space where one is needed, such as fixing the 21/2 to 2 1/2.

I'm sure there's an easier way that I could learn? Thanks again!!!
Pam E. is offline   Reply With Quote
Old 01-10-2015, 08:54 PM   #10
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,249
Karma: 61360164
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
(\d*)(\d\/\d) find any digits followed by digit/digit

\1 \2 <insert the space

This does not work with the vulger fraction entities
theducks is offline   Reply With Quote
Old 01-11-2015, 12:37 AM   #11
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Make that
Code:
(\d+)(\d\/\d)
so as to avoid matching where (\d*) equals nothing-at-all.

Granted, an extra space at the beginning of the line will probably be rendered out anyway, but for the sake of cleanliness.
eschwartz is offline   Reply With Quote
Old 01-11-2015, 10:00 AM   #12
Pam E.
Member
Pam E. began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
Thanks so much!! This works great!
Pam E. is offline   Reply With Quote
Old 01-11-2015, 11:07 AM   #13
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,249
Karma: 61360164
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
If your original used the vulgar fractions (as shown in you original example) , I know how to find those
Code:
(&frac14;|&frac12;|&frac34;)
What I don't know is how to do this as a single pass replace
theducks is offline   Reply With Quote
Old 01-11-2015, 11:14 AM   #14
Pam E.
Member
Pam E. began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
Ok, great! I'll give that a try. I've been using normal f/r and saved searches.

Find: ⅛, ⅔, etc.

Replace: 1/8, 2/3, etc.
Pam E. is offline   Reply With Quote
Old 01-11-2015, 11:20 AM   #15
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,249
Karma: 61360164
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 Pam E. View Post
Ok, great! I'll give that a try. I've been using normal f/r and saved searches.

Find: ⅛, ⅔, etc.
Where did you find these, they are not in the standard entity charts? Another non-standard 'Word' abomination?

Quote:
Replace: 1/8, 2/3, etc.
theducks is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A question for you all. J.M. Pierce Writers' Corner 11 09-26-2010 08:49 PM
iPad 3G question vonCZ Apple Devices 46 08-10-2010 10:33 AM
Classic Few Nook Question and Question on Nook 3G vs WiFi blackonblack Barnes & Noble NOOK 4 07-02-2010 02:07 AM
Looking for another reader question and PRS-600 question lilpretender Which one should I buy? 9 10-24-2009 04:02 AM


All times are GMT -4. The time now is 02:26 PM.


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