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 12-22-2018, 04:49 PM   #1
Brett Merkey
Not Quite Dead
Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.
 
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
Regex: CSS font-size keyword to ems

I have found that the Kindle PaperWhite does not handle CSS font-size keywords well. If device font-size settings are not at the default, the Kindle will display fonts at uncomfortably extreme sizes. I have created a Calibre regex-function which maps keywords to ems.

1) Restrict search to style files. Apply "Beautify files" tool to make sure code is ready.

2) Set Mode to Regex-function.

3) Search: font-size: \K([^\d.;]+)

4) Click "Create/Edit" button and paste the following into the code box:

Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    # Match from list of size keywords
    i = ["medium", "small", "large", "x-small", "xx-small", "x-large", "xx-large", "larger", "smaller"].index(match.group(1))
    # Map of corresponding sizes. Adjust as needed.
    size = ["1em", ".85em", "1.2em", ".75em", ".75em", "1.3em", "1.5em", "1.1em", ".9em"]
    
    return size[i]
5) Name the function and run.

You can see from the code snippet that you can adjust the mappings to meet your own requirements.

Last edited by Brett Merkey; 12-22-2018 at 04:56 PM.
Brett Merkey is offline   Reply With Quote
Old 12-23-2018, 09:37 AM   #2
Thom*
The Fumbler
Thom* began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Jun 2015
Device: android 4.2/fbreader
Nice!
Alternatively, you could have written 9 simple Search and Replace statements.
Thom* is offline   Reply With Quote
Advert
Old 12-23-2018, 09:49 AM   #3
Brett Merkey
Not Quite Dead
Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.
 
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
Quote:
...9 simple Search and Replace statements
There is something not quite "simple" in the number 9 — and something not quite simple in remembering, from book to book, which keyword maps to which em value. I let Calibre remember all this for me by making a regex-function.

Thank you, Calibre!
Brett Merkey is offline   Reply With Quote
Old 12-23-2018, 12:54 PM   #4
retiredbiker
Addict
retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.
 
retiredbiker's Avatar
 
Posts: 387
Karma: 1638210
Join Date: May 2013
Location: Ontario, Canada
Device: Kindle KB, Oasis, Pop_Os!, Jutoh, Kobo Forma
Quote:
Originally Posted by Brett Merkey View Post
There is something not quite "simple" in the number 9 — and something not quite simple in remembering, from book to book, which keyword maps to which em value. I let Calibre remember all this for me by making a regex-function.

Thank you, Calibre!
I had one search, that I would edit and run up to 9 times for a given book!

Thank you, Brett, this works like a charm and will same me a ton of work. I have been just gritting my teeth whenever I get a book from Open Road (among others); now it will be easy.
retiredbiker is offline   Reply With Quote
Old 12-23-2018, 01:07 PM   #5
Brett Merkey
Not Quite Dead
Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.
 
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
Thanks for the encouragement, RetiredBiker. I've been using this timesaver for a while. Perhaps I will review my collection of regexes and see if there any others that might be of general use.
Brett Merkey is offline   Reply With Quote
Advert
Old 12-23-2018, 01:40 PM   #6
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Many thanks for this -- another nice addition to my Saved Searches collection!
Phssthpok is offline   Reply With Quote
Old 12-23-2018, 01:58 PM   #7
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
...although I've just discovered that if I specify "All style files" it applies to ALL my saved searches, and I have to switch from "All text files" to "All styles files" and back again when I run it.

Wouldn't it be nice if each saved search included a specification of which files it applied to?
Phssthpok is offline   Reply With Quote
Old 12-23-2018, 02:09 PM   #8
Brett Merkey
Not Quite Dead
Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.
 
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
Quote:
Wouldn't it be nice if each saved search included a specification of which files it applied to?
I've wondered about that. The Saved Search feature saves every other relevant parameter but that one. I have to watch that and remember to switch back and forth since my regex searches apply, each in turn, to "all text" or "all selected" or "all style" files.
Brett Merkey is offline   Reply With Quote
Old 12-23-2018, 02:41 PM   #9
retiredbiker
Addict
retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.retiredbiker ought to be getting tired of karma fortunes by now.
 
retiredbiker's Avatar
 
Posts: 387
Karma: 1638210
Join Date: May 2013
Location: Ontario, Canada
Device: Kindle KB, Oasis, Pop_Os!, Jutoh, Kobo Forma
I groused about having to change file sets at first, but now I have searches that can run on either text or style files, depending on the book. One that gets rid of hundreds of "@page" lines, for example.

The list of saved searches gets so long it it becomes unwieldy after a while. Maybe a way to save different sets of searches--like text searches, style searches, and the infamous Other--that might be nice. But then, having to choose a set each time could be cumbersome.
retiredbiker is offline   Reply With Quote
Old 12-24-2018, 09:29 AM   #10
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Quote:
Originally Posted by retiredbiker View Post
The list of saved searches gets so long it it becomes unwieldy after a while. Maybe a way to save different sets of searches--like text searches, style searches, and the infamous Other--that might be nice. But then, having to choose a set each time could be cumbersome.
I've asked about this before, but Kovid isn't keen on the idea. Oh well.
Phssthpok is offline   Reply With Quote
Old 12-24-2018, 12:03 PM   #11
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: 29,792
Karma: 54830978
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 Phssthpok View Post
I've asked about this before, but Kovid isn't keen on the idea. Oh well.
One of the features of Sigil I make use of:
Search Groups (like folders). I have (also) USAGE type groups.
CSS S&R, Cleanup (messy code, de-wordify), Touchup (font size rename pt->em)
You can treat the group as a folder or you can RUN the group with a couple of clicks

Neither Sigil or Calibre lets you set the file type or S&R mode as part of the saved search.
theducks is offline   Reply With Quote
Old 12-24-2018, 01:29 PM   #12
Brett Merkey
Not Quite Dead
Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.
 
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
Quote:
Neither Sigil or Calibre lets you set the file type or S&R mode as part of the saved search
Calibre does not let you set the S&R mode but that is because the S&R mode is saved as part of the definition.

Perhaps there is some technical or user case reason why the type of file the search acts upon can not be saved. No problem, really. Just kind of anomalous.

Last edited by Brett Merkey; 12-24-2018 at 01:35 PM.
Brett Merkey is offline   Reply With Quote
Old 12-25-2018, 08:15 AM   #13
Thasaidon
Hedge Wizard
Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.
 
Thasaidon's Avatar
 
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
Quote:
Originally Posted by theducks View Post
One of the features of Sigil I make use of:
Search Groups (like folders). I have (also) USAGE type groups.
CSS S&R, Cleanup (messy code, de-wordify), Touchup (font size rename pt->em)
You can treat the group as a folder or you can RUN the group with a couple of clicks
These techniques sound very useful. I will be sorting mine into usage groups.

I have tried to run an existing group but cannot find the right couple of clicks. Could you give me a hint please.
Thasaidon is offline   Reply With Quote
Old 12-25-2018, 12:05 PM   #14
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: 29,792
Karma: 54830978
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 Thasaidon View Post
These techniques sound very useful. I will be sorting mine into usage groups.

I have tried to run an existing group but cannot find the right couple of clicks. Could you give me a hint please.
This really is a Sigil forum question.
The Group only works from the Saved Search Window (not the context menu)
SELECT the group title: Click the Load Search button: <your choice on the how to run>
theducks is offline   Reply With Quote
Old 12-25-2018, 08:33 PM   #15
Thasaidon
Hedge Wizard
Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.Thasaidon ought to be getting tired of karma fortunes by now.
 
Thasaidon's Avatar
 
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
Quote:
Originally Posted by theducks View Post
This really is a Sigil forum question.
The Group only works from the Saved Search Window (not the context menu)
SELECT the group title: Click the Load Search button: <your choice on the how to run>
You are quite right I should have asked this in the Sigil forum. It just never occurred to me after I saw your post.

Thank you very much for the info.
Thasaidon is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CSS not working (specifically bold & font size) kaonevar Editor 10 10-10-2014 12:47 AM
can't reduce font size of headline using extra css scissors Recipes 5 12-23-2013 03:45 AM
Formatting sgc-toc.css font-size phossler Sigil 13 09-07-2013 12:37 PM
How to change the font-size in the body tag in css? naisren Conversion 2 10-01-2012 05:52 PM
Calibre has no choice on font size unit in css? naisren ePub 6 09-30-2012 09:41 AM


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


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