Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 06-29-2021, 03:28 AM   #1
halloleo
Groupie
halloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 156
Karma: 12649
Join Date: Feb 2020
Device: iPad
Have the series number in the generated cover only when it is not zero

The subtitle for generated book covers contains the Series name plus the Series number. This is acchive with the following template code:

Code:
{series:'test($, strcat("<i>", $, "</i> - ", raw_field("formatted_series_index")), "")'}
In some books I have set the series number to zero and then I only want the series name, but not the number in the sub title. - How can I achieve this on the book cover?

I looked for a "greater than" test in the Template Program Modesection of the doco, but couldn't figure it out...
halloleo is offline   Reply With Quote
Old 06-29-2021, 04:50 AM   #2
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by halloleo View Post
I looked for a "greater than" test in the Template Program Modesection of the doco, but couldn't figure it out...
Use either the 'if' expression or the 'cmp' function.
chaley is offline   Reply With Quote
Advert
Old 06-29-2021, 08:59 AM   #3
halloleo
Groupie
halloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 156
Karma: 12649
Join Date: Feb 2020
Device: iPad
Thanks for chiming in @chaley!

I tried the "if" expression path, because I do not really need the numeric comparison, a string comparison against "0" should be enough.

However I get an error. The full code for my sub title expression looks like this:

Code:
{series:'test($, strcat("<i>", $, "</i>", program: if raw_field("formatted_series_index") == "0" then "" else raw_field("formatted_series_index"),"<br>"), "")'}
{#version:'test($, strcat("<b>", $, "</b>"),"")'}
and I always see the message "Template error Formatter" complaining about not enough closing brackets - but I think the brackets are correct. What do I do wromg?
halloleo is offline   Reply With Quote
Old 06-29-2021, 09:31 AM   #4
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
There are several errors.
  • The word "program:" is valid only at the beginning of a GPM template. You are using TPM so you don't need 'program'.
  • You are missing the closing 'fi' for the 'if'.
  • The raw_field() function returns 'None' for an undefined field. Because of that, comparing against the string "0" won't work. Numeric comparisons do work because the recognize "None" and change it internally to zero.
Here is a corrected version of your template, indented so I could read it.
Code:
{series:'
	test($,
		 strcat(
			"<i>",
			$,
			"</i>",
			if raw_field("formatted_series_index") ==# 0
				then ""
				else raw_field("formatted_series_index")
			fi,
			"<br>"),
		 "")'}
{#version:'test($, strcat("<b>", $, "</b>"),"")'}
Personally, I would use TPM for something this complicated. For example:
Code:
program:
	if $series then
		if $$#formatted_series_index ==# 0 then
			dex = ""
		else
			dex = $$#formatted_series_index
		fi;
		s = strcat("<i>", $series, "</i>", dex, "<br>")
	else
		s = ''
	fi;
	if $#version
	then
		v = strcat("<b>", $#version, "</b>")
	else
		v = ''
	fi;
	strcat(s, v)
I strongly suspect that you need a space after the > in "</i>"
chaley is offline   Reply With Quote
Old 06-29-2021, 10:08 AM   #5
halloleo
Groupie
halloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 156
Karma: 12649
Join Date: Feb 2020
Device: iPad
Thanks a lot @chaley!

That's great tip to convert the complete tetemplatee to TPM. I didn't know that's possible. It's soo much easier!

Basically I went with your TPM solution, I just made a few adjustments to your version to accommodate better my setup. For completeness I list that here:

Code:
program:
	if $series then
		if $$formatted_series_index == "0" then
			dex = ""
		else
			dex = strcat(" - ",$$formatted_series_index)
		fi;
		s = strcat("<i>", $series, "</i>", dex, "<br>")
	else
		s = ''
	fi;
	if $#version
	then
		v = strcat("<b>", $#version, "</b>")
	else
		v = ''
	fi;
	strcat(s, v)
Again, thanks a lot!
halloleo is offline   Reply With Quote
Advert
Old 06-29-2021, 11:16 AM   #6
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
What is the lookup name "formatted_series_index"? There is no standard column with that name and it isn't a custom column because it is missing the leading '#'?
chaley is offline   Reply With Quote
Old 06-29-2021, 05:56 PM   #7
halloleo
Groupie
halloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 156
Karma: 12649
Join Date: Feb 2020
Device: iPad
I disagree (not that I'm a calibre expert): The default template for the subtitle was:

Code:
{series:'test($, strcat("<i>", $, "</i> - ", raw_field("formatted_series_index")), "")'}
So I understand formatted_series_index is a standard field related to series.
halloleo is offline   Reply With Quote
Old 06-30-2021, 04:22 AM   #8
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,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by halloleo View Post
I disagree (not that I'm a calibre expert): The default template for the subtitle was:

Code:
{series:'test($, strcat("<i>", $, "</i> - ", raw_field("formatted_series_index")), "")'}
So I understand formatted_series_index is a standard field related to series.
For those who come across this thread later, the above is only partially true. The template is being evaluated in the context of generating a cover, which is the only place in calibre where the field "formatted_series_index" is valid.
chaley is offline   Reply With Quote
Old 06-30-2021, 04:29 AM   #9
halloleo
Groupie
halloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterhalloleo can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
Posts: 156
Karma: 12649
Join Date: Feb 2020
Device: iPad
Quote:
Originally Posted by chaley View Post
The template is being evaluated in the context of generating a cover, which is the only place in calibre where the field "formatted_series_index" is valid.
Wow, this is very interesting! Didn't know it. Thanks @chaley.
halloleo is offline   Reply With Quote
Reply

Tags
series name, series number, template language


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tags for author sort, series and series number? griffitts Calibre 4 02-06-2020 11:37 AM
Margin cutting off portion of number generated from <li> stephenTOS Kindle Formats 5 07-07-2017 02:28 PM
Can series-number metadata be a number range? Suffolk Punch Calibre 4 04-29-2017 01:53 PM
Generated Cover Error dvd8n Calibre 3 07-16-2013 01:01 PM
How do I change the generated cover? DarkAbsynthe Calibre 2 10-29-2010 10:22 PM


All times are GMT -4. The time now is 02:01 AM.


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