View Single Post
Old 01-10-2016, 01:57 PM   #718
miajoshua
Mia
miajoshua began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Jan 2015
Device: iPad Air 2, Marvin, Calibre
Hi, I've been starting to experiment in using templates and composite columns to configure the way ebooks look on my Kindle 3. I use to read things on my ipad before. I've did the 3 composite column thing and now am trying the one column #special_title, but can't figure out how I can change the way to adjust for the decision between picking when to use the shortened title or the initial title.

the code according to the guide is:

Quote:
Custom column:
Name: #special_title
Template: (the following with all leading spaces removed)
program:
# compute the equivalent of the composite fields and store them in local variables
stripped = re(field('series'), '^(A|The|An)\s+', '');
shortened = shorten(stripped, 4, '-' ,4);
initials = re(stripped, '[^\w]*(\w?)[^\s]+(\s|$)', '\1');

# Format the series index. Ends up as empty if there is no series index.
# Note that leading and trailing spaces will be removed by the formatter,
# so we cannot add them here. We will do that in the strcat below.
# Also note that because we are in 'program' mode, we can freely use
# curly brackets in strings, something we cannot do in template mode.
s_index = template('{series_index:0>2.0f}');

# print(stripped, shortened, initials, s_index);

# Now concatenate all the bits together. The switch picks between
# initials and shortened, depending on whether there is a space
# in stripped. We then add the brackets around s_index if it is
# not empty. Finally, add the title. As this is the last function in
# the program, its value will be returned.
strcat(
switch( stripped,
'.\s', initials,
'.', shortened,
field('series')),
test(s_index, strcat(' [', s_index, '] '), ''),
field('title'));

Plugboard expression:
Template:{#special_title}
Destination field: title
Can I ask which part do I change to choose how many spaces in the title before I use the "initial" version of the title in the final product? Thanks!
miajoshua is offline   Reply With Quote