18 Sept 2025 (in calibre 8.10.100)
- A new function 'f_string()' that formats text similarly to python's 'f' strings.
f_string(string) -- interpret string similar to how python interprets f strings. The indended use is to simplify long sequences of str & str or strcat(a,b,c) expressions.
Text between braces ({ and }) must be General Program Mode template expressions. The expressions, which can be expression lists, are evaluated in the current context (current book and local variables). Text not between braces is passed through unchanged.
Examples: - f_string('Here is the title: {$title}') - returns the string with {$title} replaced with the title of the current book. For example, if the book's title is 20,000 Leagues Under the Sea then the f_string() returns "Here is the title: 20,000 Leagues Under the Sea".
- Assuming the current date is 18 Sept 2025, this f_string()
Code:
f_string("Today's date: the {d = today(); format_date(d, 'd')} of {format_date(d, 'MMMM')}, {format_date(d, 'yyyy')}")
returns the string Today's date: the 18 of September, 2025. Note the expression list (an assignment then an if statement) used in the first { ... } group to assign today's date to a local variable.
- If the book is book #3 in a series named Foo that has 5 books then this template
Code:
program:
if $series then
series_count = book_count('series:"""=' & $series & '"""', 0);
return f_string("{$series}, book {$series_index} of {series_count}")
fi;
return 'This book is not in a series'
returns "Foo, book 3 of 5".