Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 04-29-2014, 04:50 AM   #1
Maverynthia
Enthusiast
Maverynthia began at the beginning.
 
Maverynthia's Avatar
 
Posts: 47
Karma: 10
Join Date: May 2011
Device: Samsung Galaxy 3 8.0 /Samsung Galaxy S5 / PC
Save Template Help

So I'm trying to get Calibre to use the first letter of a series name and if not that, the title of the book, only the help docs are archaic to understand and don't provide enough examples.

I found this:
{#series:'ifempty($, field('#genre'))'}

But I'm not using metadata at all, just 'series' or if empty 'title'
Which get's me:
{series:'ifempty($, field("title"))'}/{series} [{series_index}] - {title} ({author})
BUT... where do I put in the '.1' for only the series or title letter.
Maverynthia is offline   Reply With Quote
Old 04-29-2014, 04:10 PM   #2
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: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
series and title are types of metadata...

I am not entirely clear on what you want to see. Can you give a sample book and how you wish to see it saved?

Also, if you post your template question here: https://www.mobileread.com/forums/sho...d.php?t=100949
on the dedicated templates thread, more people can see and hopefully answer.
eschwartz is offline   Reply With Quote
Advert
Old 05-05-2014, 04:06 AM   #3
Maverynthia
Enthusiast
Maverynthia began at the beginning.
 
Maverynthia's Avatar
 
Posts: 47
Karma: 10
Join Date: May 2011
Device: Samsung Galaxy 3 8.0 /Samsung Galaxy S5 / PC
I thought that topic was only for POSTING templates not asking about help. Thus the new topic. Maybe this can be merged?

As for what I want, let's take two imaginary books:

The Caterpillar's Day [Happy Bugs #1] by Some Person
There is A Cat Here by That Peep

I basically wanted them sorted into folder's like this:

H/Happy Bugs [1] - The Caterpillar's Day (Some Person)
T/There is A Cat Here (That Peep)

Basically the first letter of the series and if no series then the title becomes the folder, then they are placed in their own folder by series/title
I can get it to do the LETTER for a folder, but I don't know how to set it to fall back on the title if there is no series.
Maverynthia is offline   Reply With Quote
Old 05-05-2014, 11:28 AM   #4
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: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
No big deal, it works just fine here too. But the other thread is handy since I and several other template gurus are subscribed already, so we are sure to see questions.

To answer your question, template programming mode (that's where we get to use functions) looks like this:
Code:
{fieldname:formatting:'function(arguments)'|prefix|suffix}
The four sections -- metadata field, formatting, function(s), and prefix-suffix pair -- are each optional. The ":" divides each section (except the last). The one after "fieldname" is required, even if there is no fieldname, if anyhing other than "{fieldname}" is being used. So if you just use a function, you need to begin with ":" -- same goes with separating the fieldname and prefix-suffix (even though normally there is no separator).

".1" is formatting, so you will want to use
Code:
{series:.1:'ifempty($, field("title"))'}/{series}{series_index:| [|] - }{title} ({authors})
I took the liberty of making the brackets space and hyphen around the series_index dependent on there being one, by using a prefix-suffix pair.

Last edited by eschwartz; 05-19-2014 at 11:05 AM. Reason: template typo -- thanks, chaley!
eschwartz is offline   Reply With Quote
Old 05-19-2014, 08:39 AM   #5
Maverynthia
Enthusiast
Maverynthia began at the beginning.
 
Maverynthia's Avatar
 
Posts: 47
Karma: 10
Join Date: May 2011
Device: Samsung Galaxy 3 8.0 /Samsung Galaxy S5 / PC
OK thanks I'll bookmark this thread for the section breakdown. I don't remember seeing that in the template help, or if it WAS there, it was more confusing than this example.

However when I try to use the code I get:
calibre, version 1.37.0
ERROR: Invalid template:
The template {series:.1:'ifempty($, field("title"))'}/{series}{series_index| [|] - }{title} ({authors}) is invalid:
string indices must be integers, not unicode

Last edited by Maverynthia; 05-19-2014 at 08:42 AM.
Maverynthia is offline   Reply With Quote
Advert
Old 05-19-2014, 08:44 AM   #6
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: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
You're Welcome.

The template help said this in a less straightforward way. I may need to fix that.
eschwartz is offline   Reply With Quote
Old 05-19-2014, 10:34 AM   #7
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,850
Karma: 7035877
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Maverynthia View Post
However when I try to use the code I get:
calibre, version 1.37.0
ERROR: Invalid template:
The template {series:.1:'ifempty($, field("title"))'}/{series}{series_index| [|] - }{title} ({authors}) is invalid:
string indices must be integers, not unicode
You are missing a ":" between "series_index" and its following "|". The template should be
Code:
{series:.1:'ifempty($, field("title"))'}/{series}{series_index:| [|] - }{title} ({authors})
chaley is offline   Reply With Quote
Old 05-19-2014, 10:51 AM   #8
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: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Thanks chaley! I made a typo.

Fixed in my post, too. I even added an explanation -- is it good?

Last edited by eschwartz; 05-19-2014 at 11:07 AM.
eschwartz is offline   Reply With Quote
Old 05-19-2014, 11:50 AM   #9
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,850
Karma: 7035877
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by eschwartz View Post
Thanks chaley! I made a typo.
Easy to do.
Quote:
Fixed in my post, too. I even added an explanation -- is it good?
I am the wrong person to ask. Because of a misspent youth studying formal regular languages in the 70s I very much prefer something like extended BNF notation for the syntax of regular languages. I struggle with textual descriptions, translating them in my head to figure out how the language parses. That said, reading yours, it seems correct.

FWIW: here is an extended BNF-like grammar for templates. Text in quotes represent tokens. The square brackets indicate what is between them is optional. I didn't bother with the grammar for the functions. The two variants could be easily expressed in one grammar but I chose not to introduce the or (|) operator.
Code:
"{" [ "field name" ] [ [ ":" [ "formatting" ] ] [ ":" "single Function" ] [ "|" [ "prefix" ] "|" [ "suffix" ] ] ] "}"

or

"{" [ "field name" ] [ [ ":" [ "formatting" ] ] [ ":'" "Template Program" "'" ] [ "|" [ "prefix" ] "|" [ "suffix" ] ] ] "}"
Some interesting things to note. According to the grammar:
  • {} is a valid template. This is true.
  • {:} is also a valid template.
  • {::'function()'} is valid
  • {::function()} is valid but probably meaningless for semantic reasons. There is no value to pass as the implied first argument.
Well, enough fun.

Last edited by chaley; 05-19-2014 at 12:39 PM. Reason: Fixed grammar. See next post for details.
chaley is offline   Reply With Quote
Old 05-19-2014, 12:20 PM   #10
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: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Thanks for the mention of BNF! I've been learning everything myself as I come across stuff -- I learn in my spare time, this isn't part of my curriculum, yet -- so I appreciate any time someone mentions anything I haven't come across yet. (I was wondering a bit what some description were that turns out to be BNF.)

According to Kovid's docs (and thus my understanding),
Code:
{authors:uppercase()|prefix|suffix}
is valid but the way you describe it, it must be
Code:
{authors:uppercase():|prefix|suffix}
Is this optional, or did you/kovid make a mistake?

I'd test it out myself but I typed this on my Kindle Touch.

Last edited by eschwartz; 05-19-2014 at 12:23 PM.
eschwartz is offline   Reply With Quote
Old 05-19-2014, 12:37 PM   #11
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,850
Karma: 7035877
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by eschwartz View Post
Thanks for the mention of BNF! I've been learning everything myself as I come across stuff -- I learn in my spare time, this isn't part of my curriculum, yet -- so I appreciate any time someone mentions anything I haven't come across yet. (I was wondering a bit what some description were that turns out to be BNF.)

According to Kovid's docs (and thus my understanding),
Code:
{authors:uppercase()|prefix|suffix}
is valid but the way you describe it, it must be
Code:
{authors:uppercase():|prefix|suffix}
Is this optional, or did you/kovid make a mistake?

I'd test it out myself but I typed this on my Kindle Touch.
I made a mistake in the grammar. That colon should not precede the bar.

It should be
Code:
"{" [ "field name" ] [ [ ":" [ "formatting" ] ] [ ":" "single Function" ] [ "|" [ "prefix" ] "|" [ "suffix" ] ] ] "}"

or

"{" [ "field name" ] [ [ ":" [ "formatting" ] ] [ ":'" "Template Program" "'" ] [ "|" [ "prefix" ] "|" [ "suffix" ] ] ] "}"
I think I messed up because I was struggling to deal with the alternation for Template Program Mode and for the optional formatting. Or perhaps because my brain no longer works as well as it once did.
chaley is offline   Reply With Quote
Reply

Tags
sort by letter, templates

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help on a Save to Disk template Dammie Library Management 15 12-16-2013 09:51 AM
Save Template question ltwally Library Management 4 04-11-2013 06:15 PM
Need help on a Save to Disk template fidvo Library Management 2 08-12-2012 03:34 PM
A little help with a save template...? Belfaborac Library Management 2 02-04-2011 09:47 PM
save to disk template speakingtohe Calibre 9 05-29-2010 06:02 AM


All times are GMT -4. The time now is 06:51 PM.


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