From 79a64fdb4965f1fff7dceac63aa36d92748f2709 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 21 Sep 2019 21:52:54 +0000 Subject: ctanbib (21sep19) git-svn-id: svn://tug.org/texlive/trunk@52145 c570f23f-e606-0410-a88d-b1316a301751 --- .../texk/texlive/linked_scripts/ctanbib/ctanbib | 57 +++++++++++++++++---- Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf | Bin 20182 -> 20186 bytes .../texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf | Bin 34395 -> 34681 bytes .../texmf-dist/doc/support/ctanbib/ctanbib-doc.tex | 2 + Master/texmf-dist/scripts/ctanbib/ctanbib | 57 +++++++++++++++++---- 5 files changed, 94 insertions(+), 22 deletions(-) diff --git a/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib b/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib index 10666696b56..21adfd46792 100755 --- a/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib +++ b/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib @@ -27,7 +27,7 @@ Available options: ]]) os.exit(1) elseif arg[1]=="--version" or arg[1]=="-v" then - print "ctanbib version v0.1c" + print "ctanbib version 0.1d" os.exit(1) elseif arg[1]=="--ctan" or arg[1]=="-c" then table.remove(arg, 1) @@ -35,7 +35,8 @@ elseif arg[1]=="--ctan" or arg[1]=="-c" then end local pkgname = arg[1] -local url = "https://www.ctan.org/xml/pkg/" .. pkgname +local url = "https://www.ctan.org/xml/2.0/pkg/" .. pkgname .. "?author-name=true" +local authors_url = "https://ctan.org/xml/2.0/authors" -- change that for different title scheme local titleformat = "The %s package" @@ -76,18 +77,52 @@ local bibtex_escape = function(a) end) end +-- we need to use this method temporarily because of a bug in +-- CTAN API +local author_list +local fetch_author_list = function() + if author_list then return author_list end + local authors = load_xml(authors_url) + author_list = {} + for _, author in ipairs(authors:query_selector("author")) do + -- save all authors under they ID + local id = author:get_attribute("id") + author_list[id] = author + end + return author_list +end + +local process_author = function(author) + local current = {} + current[#current+1] = author:get_attribute("familyname") + current[#current+1] = author:get_attribute("givenname") + -- the author is an organization + if #current == 1 then + return "{" .. current[1] .. "}" + elseif #current > 1 then + return table.concat(current, ", ") + end + return nil -- no author +end + +-- get the author name and surname +local get_author = function(author) + local name = process_author(author) + if name then return name end + -- if the package XML doesn't contain author name, + -- we need to fetch the authors list from CTAN and find + -- it here + local author_list = fetch_author_list() + local id = author:get_attribute("id") + -- try to find the author id in list of authors + -- if everything fails, just return an empty group + return process_author(author_list[id]) or "{}" +end + local get_authors = function(a) local retrieved_authors = {} for _, author in ipairs(a) do - local current = {} - current[#current+1] = author:get_attribute("familyname") - current[#current+1] = author:get_attribute("givenname") - -- the author is an organization - if #current == 1 then - table.insert(retrieved_authors, "{" .. current[1] .. "}") - else - table.insert(retrieved_authors, table.concat(current, ", ")) - end + table.insert(retrieved_authors, get_author(author)) end return table.concat(retrieved_authors," and ") end diff --git a/Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf b/Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf index 2843f5c494c..975df448c6f 100644 Binary files a/Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf and b/Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf differ diff --git a/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf b/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf index f82b9bba95f..b665ab7762e 100644 Binary files a/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf and b/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf differ diff --git a/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex b/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex index 23a6525fd99..651d0058e6c 100644 --- a/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex +++ b/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex @@ -99,6 +99,8 @@ it's eventual release on CTAN. \section{Changelog} \begin{changelog} + \change{2019-09-21}{Try to find the author in full CTAN author list if the author cannot be found in the package info} + \change{2019-09-16}{Use the CTAN API 2.0 to fetch the package info} \change{2019-05-04}{Version 0.1c released} \change{2019-05-04}{Use the \texttt{curl} command to download the package info} \change{2019-05-04}{Added information about the need to have the \texttt{curl} command installed} diff --git a/Master/texmf-dist/scripts/ctanbib/ctanbib b/Master/texmf-dist/scripts/ctanbib/ctanbib index 10666696b56..21adfd46792 100755 --- a/Master/texmf-dist/scripts/ctanbib/ctanbib +++ b/Master/texmf-dist/scripts/ctanbib/ctanbib @@ -27,7 +27,7 @@ Available options: ]]) os.exit(1) elseif arg[1]=="--version" or arg[1]=="-v" then - print "ctanbib version v0.1c" + print "ctanbib version 0.1d" os.exit(1) elseif arg[1]=="--ctan" or arg[1]=="-c" then table.remove(arg, 1) @@ -35,7 +35,8 @@ elseif arg[1]=="--ctan" or arg[1]=="-c" then end local pkgname = arg[1] -local url = "https://www.ctan.org/xml/pkg/" .. pkgname +local url = "https://www.ctan.org/xml/2.0/pkg/" .. pkgname .. "?author-name=true" +local authors_url = "https://ctan.org/xml/2.0/authors" -- change that for different title scheme local titleformat = "The %s package" @@ -76,18 +77,52 @@ local bibtex_escape = function(a) end) end +-- we need to use this method temporarily because of a bug in +-- CTAN API +local author_list +local fetch_author_list = function() + if author_list then return author_list end + local authors = load_xml(authors_url) + author_list = {} + for _, author in ipairs(authors:query_selector("author")) do + -- save all authors under they ID + local id = author:get_attribute("id") + author_list[id] = author + end + return author_list +end + +local process_author = function(author) + local current = {} + current[#current+1] = author:get_attribute("familyname") + current[#current+1] = author:get_attribute("givenname") + -- the author is an organization + if #current == 1 then + return "{" .. current[1] .. "}" + elseif #current > 1 then + return table.concat(current, ", ") + end + return nil -- no author +end + +-- get the author name and surname +local get_author = function(author) + local name = process_author(author) + if name then return name end + -- if the package XML doesn't contain author name, + -- we need to fetch the authors list from CTAN and find + -- it here + local author_list = fetch_author_list() + local id = author:get_attribute("id") + -- try to find the author id in list of authors + -- if everything fails, just return an empty group + return process_author(author_list[id]) or "{}" +end + local get_authors = function(a) local retrieved_authors = {} for _, author in ipairs(a) do - local current = {} - current[#current+1] = author:get_attribute("familyname") - current[#current+1] = author:get_attribute("givenname") - -- the author is an organization - if #current == 1 then - table.insert(retrieved_authors, "{" .. current[1] .. "}") - else - table.insert(retrieved_authors, table.concat(current, ", ")) - end + table.insert(retrieved_authors, get_author(author)) end return table.concat(retrieved_authors," and ") end -- cgit v1.2.3