|
|
#1 |
|
Member
![]() 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! |
|
|
|
|
|
#2 |
|
Member
![]() 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> |
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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":
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. |
|
|
|
|
|
#4 |
|
Member
![]() Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
|
Thanks so much! This works perfectly. I need to learn regex.
|
|
|
|
|
|
#5 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
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. |
|
|
|
| Advert | |
|
|
|
|
#6 |
|
Member
![]() 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. |
|
|
|
|
|
#7 |
|
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
|
|
|
|
|
#8 |
|
Member
![]() 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.
|
|
|
|
|
|
#9 |
|
Member
![]() 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!!! |
|
|
|
|
|
#10 |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
|
|
|
|
|
#11 |
|
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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) Granted, an extra space at the beginning of the line will probably be rendered out anyway, but for the sake of cleanliness.
|
|
|
|
|
|
#12 |
|
Member
![]() Posts: 15
Karma: 10
Join Date: Jan 2015
Device: iPad
|
Thanks so much!! This works great!
|
|
|
|
|
|
#13 |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
(¼|½|¾) |
|
|
|
|
|
#14 |
|
Member
![]() 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. |
|
|
|
|
|
#15 |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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
|
|
|
|
|
![]() |
|
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 |