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 07-18-2018, 06:56 PM   #1
Latios
Member
Latios began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jul 2018
Device: Kindle 4
{author_sort}. How to template-save the author's last name in capital letters?

Hello,

When I am using "saving ebooks to disc", there is a template that I can use to create the file name of that ebook that it is going to be save.

Today, I am wondering about the {author_sort}.

For example, I have a book where the author is "Aldous Huxley", and the title is "Brave New World".

If I use the template "{author_sort}.{title}", the new ebook file name will be:
Huxley, Aldous. Brave New World

But I would like to have the last name in capital letters. How can I make it to be like this: ???
HUXLEY, Aldous. Brave New World

How can I do that?

Thanks!

Last edited by Latios; 07-19-2018 at 12:38 AM.
Latios is offline   Reply With Quote
Old 07-22-2018, 03:08 PM   #2
Latios
Member
Latios began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jul 2018
Device: Kindle 4
has anybody been able to do it or know how to do it?
Latios is offline   Reply With Quote
Advert
Old 10-28-2018, 01:00 AM   #3
Latios
Member
Latios began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jul 2018
Device: Kindle 4
any luck?? anyone knows??
Latios is offline   Reply With Quote
Old 10-28-2018, 01:50 AM   #4
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,532
Karma: 26944418
Join Date: Mar 2012
Location: Sydney Australia
Device: none
There are string case changing and string manipulation functions in the Template language, see ==>> Function classification

BR
BetterRed is offline   Reply With Quote
Old 10-28-2018, 10:55 PM   #5
Latios
Member
Latios began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jul 2018
Device: Kindle 4
Thanks!! I have been reading it and trying options.

The only problem is that the command {author_sort} automatically grabs both FirstName and LastName and organizes them like "Huxley, Aldous"

So with the string case functions, it looks that I just can do either all capital letters or all lower letters.

How can I make ONLY the Last name to be in capital letters like "HUXLEY, Aldous"??
Latios is offline   Reply With Quote
Advert
Old 10-29-2018, 02:15 AM   #6
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Assuming all the author_sort names are in the format "LN, FN", then the following seems to work:

Code:
{author_sort:'strcat(uppercase(list_item($,0,',')),', ',list_item($,1,','))'}
The problem with that is if you have a book by Madonna or Cher.

And thinking about this, the following will work for those cases as well:
Code:
{author_sort:'contains($,",",strcat(uppercase(list_item($,0,",")),", ",list_item($,1,",")),uppercase($))'}
davidfor is offline   Reply With Quote
Old 10-29-2018, 04:39 AM   #7
Latios
Member
Latios began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jul 2018
Device: Kindle 4
YES, IT WORKS VERY GOOD!

I just tried this one:
Code:
{author_sort:'contains($,",",strcat(uppercase(list_item($,0,",")),", ",list_item($,1,",")),uppercase($))'}
And I get:
- MADONNA
- HUXLEY, Aldous

So good!!! I couldnt even get to this point myself.

But now the only problem is when there is more than one author.

For example, with two authors:
When Author sort's metadata shows: Smith, Sam & Dallas, Ken
...applying the code you gave me, comes up like: SMITH, Sam & Dallas

For example, with more than two:
When Author sort's metadata shows: Ronald, Alex & Chan, Liu & Tiffany, Megan
...applying the code you gave me, comes up like: RONALD, Alex & Chan

It's weird, because it either omits the second author's first name, or also the other authors. I have tried other options, but it is going beyond my knowledge...

Last edited by Latios; 10-29-2018 at 04:52 AM.
Latios is offline   Reply With Quote
Old 10-29-2018, 05:11 PM   #8
Latios
Member
Latios began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jul 2018
Device: Kindle 4
I think I am getting close how to fix it:

I have modified the code template like this:

Code:
{author_sort:'contains($,",",strcat(uppercase(list_item($,0,",")),", ",list_item($,1,","),", ",list_item($,2,","),", ",list_item($,3,",")),uppercase($))'}
And this is the new outcome:

When Author sort's metadata shows: Smith, Sam & Dallas, Ken
...applying the code you gave me, comes up like: SMITH, Sam & Dallas, Ken

For example, with more than two:
When Author sort's metadata shows: Ronald, Alex & Chan, Liu & Tiffany, Megan
...applying the code you gave me, comes up like: RONALD, Alex & Chan, Liu & Megan, Tiffany

The only thing missing now is to make the second and following last name's author into capital letters.

what am I missing?
Latios is offline   Reply With Quote
Old 10-29-2018, 10:33 PM   #9
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by Latios View Post
I think I am getting close how to fix it:

I have modified the code template like this:

Code:
{author_sort:'contains($,",",strcat(uppercase(list_item($,0,",")),", ",list_item($,1,","),", ",list_item($,2,","),", ",list_item($,3,",")),uppercase($))'}
And this is the new outcome:

When Author sort's metadata shows: Smith, Sam & Dallas, Ken
...applying the code you gave me, comes up like: SMITH, Sam & Dallas, Ken

For example, with more than two:
When Author sort's metadata shows: Ronald, Alex & Chan, Liu & Tiffany, Megan
...applying the code you gave me, comes up like: RONALD, Alex & Chan, Liu & Megan, Tiffany
What I did didn't handle multiple authors.
Quote:
The only thing missing now is to make the second and following last name's author into capital letters.

what am I missing?
For two names, it is:

Code:
{author_sort:'contains($,",",strcat(uppercase(list_item($,0,",")),", ",strcat(list_item(list_item($,1,","),0,"&")," & ",uppercase(list_item(list_item($,1,","),1,"&"))),", ",list_item($,2,","),", ",list_item($,3,",")),uppercase($))'}
But, doing it this way, means you need to know what is the maximum number of authors in the library. I think I have one with 17 authors, this would get absurd.

The way to do it is with a template function. To do this:
Open the calibre preferences and go to "Template functions"
  1. In "Function" put "author_sort_capitalized".
  2. In "Argument count" put "-1"
  3. In "Program code" paste the following:
    Code:
    def evaluate(self, formatter, kwargs, mi, locals):
        sort_data = mi.author_sort_map
        if not sort_data:
            return ''
        names = []
        for n in mi.authors:
            if n.strip():
                comma_index = sort_data.get(n).find(',')
                if comma_index > 0:
                    new_name = sort_data.get(n)[:comma_index].upper()
                    new_name += sort_data.get(n)[comma_index:]
                else:
                    new_name = sort_data.get(n).upper()
                names.append(new_name)
        return " & ".join(n for n in names)
    The formatting is important.
  4. Press the "Create" button.
  5. Press the "Apply" button and close the preferences.
  6. Where you want to use this put:
    Code:
    {:author_sort_capitalized()}

That seems to work here. There is probably a better way to do it, but, that's what comes to mind at the moment.
davidfor is offline   Reply With Quote
Old 10-30-2018, 09:52 AM   #10
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,728
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by davidfor View Post
That seems to work here. There is probably a better way to do it, but, that's what comes to mind at the moment.
A template function is probably the best because it is the fastest. However, should you want to do it in the template language, this seems to work.
Code:
program: list_re_group(field('author_sort'), ' & ', '.', '(.*?)(,|$)(.*)', '{$:uppercase()}')
It first separates the list of authors, Then for each author it applies a regexp to find the value before the comma and uppercases that value. If there isn't a comma then the entire author is uppercased.
chaley is offline   Reply With Quote
Old 10-30-2018, 07:51 PM   #11
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by chaley View Post
A template function is probably the best because it is the fastest. However, should you want to do it in the template language, this seems to work.
Code:
program: list_re_group(field('author_sort'), ' & ', '.', '(.*?)(,|$)(.*)', '{$:uppercase()}')
It first separates the list of authors, Then for each author it applies a regexp to find the value before the comma and uppercases that value. If there isn't a comma then the entire author is uppercased.
Well, I did say there was probably a better way to do it

I'm not sure if I had read the description of the list_re and list_re_group functions. If I did, they didn't sink in. But, with that example, it's obvious what they do.
davidfor is offline   Reply With Quote
Old 10-31-2018, 05:04 AM   #12
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,728
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
For completeness, here is the same solution in template program mode instead of general program mode:
Code:
{author_sort:'list_re_group($, ' & ', '.', '(.*?)(,|$)(.*)', '[[$:uppercase()]]')'}
chaley is offline   Reply With Quote
Old 11-02-2018, 05:56 PM   #13
Latios
Member
Latios began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Jul 2018
Device: Kindle 4
@davidfor and @chaley !! IT COMPLETLY WORKS WITH EVERY SITUATION!!

One author, two, three, four... single word authors.. etc etc.

nothing else to say but thank you and that you are great!!!!
Latios is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nicknames - capital vs. small letters bordovy Lounge 41 07-27-2015 07:27 PM
formatting issue re: capital letters go missing! Russellsstudent Kindle Formats 2 03-15-2013 09:20 AM
{author} gives author_sort in template? Jellby Calibre 2 01-21-2013 02:25 PM
FN LN, author_sort, Initials dot, ", Jr", author template? unboggling Library Management 0 08-09-2012 08:40 PM
Chapters are just All Capital letters kevn57 Conversion 4 01-18-2012 07:42 PM


All times are GMT -4. The time now is 03:15 PM.


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