06-19-2015, 11:37 AM | #1 |
Junior Member
Posts: 8
Karma: 10
Join Date: Jan 2015
Device: none
|
Plugboard for series numbering (decimals & no decimals)
Hello all!
Before I begin, I just want to let you guys know I'm fairly new to calibre, so please be patient with me. I have a bunch of books in series where there are novellas. I've been trying to look for a solution to get the numbering to appear as [01.5] if on the 'Series' column in calibre it appears as 1.50. As of right now, this is what I have on my plugboard now is: {series}{series_index:0>2s| [|] }{title} which works just fine if the series numbering has no decimals. So what if the series does have novellas and I want to use decimals? How would I have to change the plugboard so it changes to the way I want it to? (My guess is I would need to use an 'if statement' & 'regex', but I'm not sure 100% sure.) Just an example of how I want the books to show up on my Kindle: SeriesName [01] Title A SeriesName [01.5] Title B SeriesName [02] Title C SeriesName [02.5] Title D SeriesName [03] Title E By the way, if I changed my mind and don't want a leading zero, do I just take out '0>2s'? Thanks in advance! |
06-19-2015, 11:49 AM | #2 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Use the formatting operator: "4.1f" -- four characters, 2 leading, one decimal, one following the decimal.
0> -- indicates the filler symbol, and that it gets added to the > front. |
Advert | |
|
06-19-2015, 12:46 PM | #3 | |
Junior Member
Posts: 8
Karma: 10
Join Date: Jan 2015
Device: none
|
Quote:
But would you happen to know how I would change it so that it only formats that way if I have decimal numbers? So numbers like 2.50 would change to 2.5, but numbers like 1, 2, 3, etc. stay like 01, 02, 03? Sorry if I'm not providing a clear explanation! |
|
06-19-2015, 01:41 PM | #4 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
I guess you could then regex the number to strip trailing zeroes and periods. But that might require raising the complexity to a General Program Mode template -- I believe formatting comes after functions.
So: Code:
program: formatted_series = finish_formatting( field('series_index'), '4.1f', '', '' ); stripped_series = re( formatted_series, '^ \[(.*)[.0]+\]$', ' [\1] ' ); # Add together the final result strcat( field('series'), stripped_series, field('title') ); |
06-19-2015, 04:46 PM | #5 | |
Junior Member
Posts: 8
Karma: 10
Join Date: Jan 2015
Device: none
|
Quote:
Do you mind explaining to me what '^ ' and '$' from '^ \[(.*)[.0]+\]$' does? If I remember correctly, ^ means negate? I'm not quite sure what the $ at the end does though. Also, do we not need to escape the brackets from ' [\1] '? Sorry for asking so many questions! Last edited by lina.w; 06-19-2015 at 04:50 PM. |
|
Advert | |
|
06-19-2015, 04:58 PM | #6 |
Grand Sorcerer
Posts: 6,235
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
^ out of an expression means beginning of text and $ the end of the text.
|
06-19-2015, 05:10 PM | #7 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@eschwartz: the following fragment detects float vs integer. It might eliminate the need to regexp?
Code:
program: dex=field('series_index'); i=format_number(dex, "{:02d}"); f=format_number(dex, "{:04.1f}"); isInt=cmp(f, i, '', 'yes', ''); result=test(isInt, i, f) |
06-19-2015, 06:06 PM | #8 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
chaley -- good idea! I haven't really used cmp before, in case you couldn't tell.
lina.w -- pretend I didn't write that. Tested this time. Code:
program: formatted_series = finish_formatting( field('series_index'), '0>4.1f', #fixed ' [', #fixed '] ' #fixed ); stripped_series = re( formatted_series, '\.0+', #fixed '' ); # Add together the final result strcat( field('series'), stripped_series, field('title') ); Code:
program: sidx=field('series_index'); i=format_number(sidx, "{:02d}"); f=format_number(sidx, "{:04.1f}"); isInt=cmp(f, i, '', 'yes', ''); final_sidx=finish_formatting( test(isInt, i, f), '', ' [', '] ' ); # Add together the final result strcat( field('series'), final_sidx, field('title') ); Last edited by eschwartz; 06-19-2015 at 06:12 PM. |
06-19-2015, 06:10 PM | #9 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
As for your questions about regex, they are fine. As Terisa said, the "^$" are beginning and ending anchors.
Certain characters like [] are reserved in regex and need to be escaped, but only in the pattern match, not the replacement text. Because we cannot replace with a pattern or character set. |
06-19-2015, 06:42 PM | #10 | |
Junior Member
Posts: 8
Karma: 10
Join Date: Jan 2015
Device: none
|
Quote:
And thank you Terisa de morgan & chaley for helping out & answering my questions too. You guys are awesome! * * e d i t e d * * this is just a minor problem, but now that I've got the formatting the way I want to, I'm just wondering why [01.5] appears before [01]? Say if I have a series with books with the following numberings [01], [02], and [03]. If I have a novella that goes between each, it should be in this order: [01], [01.5], [02], [02.5], [03], but the current order is [01.5], [01], [02.5], [02], [03]. I'm guessing there is no way to work around fixing this, so would my only option to getting the ordering right be going back to the previous formatting method? Last edited by lina.w; 06-19-2015 at 06:59 PM. |
|
06-20-2015, 07:46 AM | #11 | ||
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
|
||
12-31-2015, 03:41 PM | #12 |
Enthusiast
Posts: 35
Karma: 10
Join Date: Feb 2011
Device: Kindle Paperwhite, Kobo Aura One
|
I have been following this thread and am totally confused.
Where and how do I input the above mentioned code into Calibre? Sorry for sounding dumb, but I don't have a clue about programming. Any help will be greatly appreciated. |
12-31-2015, 04:27 PM | #13 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
copy-paste it into a template definition.
custom column or Metadata plugboard, they all use the same language and parser. If you right-click an input box in the plugboards definitions, it will allow you to open the Template Editor. |
01-06-2016, 05:14 AM | #14 | |
Junior Member
Posts: 2
Karma: 10
Join Date: Jan 2016
Device: Kindle Paper White
|
Quote:
Sorry to be dense, I know nothing of programming. I was interested in doing the same thing that the OP but can't figure out where exactly to add the spaces. I've copied the following code into the editor and have tried spaces in different spots but to no avail. (I did break it a couple of times though To add a space would it also be ' ' ? I didn't want the [ ] that the OP used and wanted a # and I figured out how to do that. Just stuck on this bit. Thanks for any help! Code that I inserted: program: sidx=field('series_index'); i=format_number(sidx, "{:02d}"); f=format_number(sidx, "{:04.1f}"); isInt=cmp(f, i, '', 'yes', ''); final_sidx=finish_formatting( test(isInt, i, f), '', ' #', ' ' ); # Add together the final result strcat( field('series'), final_sidx, field('title') ); |
|
01-20-2016, 09:14 PM | #15 | ||
Groupie
Posts: 156
Karma: 12092
Join Date: May 2014
Device: Kobo Libra 2
|
This thread is exactly what I was looking for, thank you everyone. But I am stuck in the same place others were; getting the display order correct.
Quote:
Quote:
Has anyone found a way to get them to sort properly? (I'm using an up-to-date Kindle Voyage, if that makes a difference.) |
||
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to have 3 decimals | Arrow | Library Management | 3 | 12-16-2014 07:42 AM |
Series Numbering .... | GeoffC | Library Management | 3 | 05-02-2014 06:11 AM |
Series numbering sometimes incorrect | DrChiper | Library Management | 4 | 01-19-2012 10:56 AM |
Kindle Annotations vs Plugboard rename Title with series initials/numbering | Gwen Morse | Devices | 2 | 09-05-2011 12:58 PM |
Series Numbering | adrian1944 | Calibre | 3 | 10-17-2010 01:59 PM |