texlive[68650] trunk: ctanbib (25oct23)

commits+karl at tug.org commits+karl at tug.org
Wed Oct 25 22:01:02 CEST 2023


Revision: 68650
          https://tug.org/svn/texlive?view=revision&revision=68650
Author:   karl
Date:     2023-10-25 22:01:02 +0200 (Wed, 25 Oct 2023)
Log Message:
-----------
ctanbib (25oct23)

Modified Paths:
--------------
    trunk/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib
    trunk/Master/texmf-dist/doc/man/man1/ctanbib.1
    trunk/Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf
    trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf
    trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex
    trunk/Master/texmf-dist/scripts/ctanbib/ctanbib

Modified: trunk/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib
===================================================================
--- trunk/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib	2023-10-25 20:00:51 UTC (rev 68649)
+++ trunk/Build/source/texk/texlive/linked_scripts/ctanbib/ctanbib	2023-10-25 20:01:02 UTC (rev 68650)
@@ -21,21 +21,31 @@
 local pkgurl = false
 local msg = [[ctanbib - convert ctan package information to bibtex format
 Usage:
-ctanbib [options] name1 name2 ...
+ctanbib [options] PKGNAME1 PKGNAME2 ...
+
+Look up the Catalogue entry for each PKGNAME on CTAN (at
+https://ctan.org/xml/2.0/pkg/PKGNAME), and convert relevant information
+to a BibTeX entry.
+
+By default, the url field in the output entry is the package's home
+field value if that is specified in the Catalogue entry; if it isn't,
+https://ctan.org/pkg/PKGNAME is used.
+
 Available options:
-  -c,--ctan       Use CTAN URL instead of the package homepage 
-  -C,--ctanpath   Use package's CTAN path as URL
+  -c,--ctan       Always use CTAN /pkg/ url instead of the package homepage 
+  -C,--ctanpath   Use the package's CTAN path as url (e.g.: /support/ctanbib)
   -e,--entrytype  (default manual)  Change entry type
   -h,--help       Print this message
-  -p,--pkgname    Put the package name in a \ctanbibpkgname command
+  -p,--pkgname    Wrap the package name in a \ctanbibpkgname command
   -v,--version    Print version info
-  ]]
+
+ctanbib package page: https://ctan.org/pkg/ctanbib]]
 local args = lapp(msg)
 if args.help then
   print(msg)
   os.exit(0)
 elseif args.version then
-  print "ctanbib version 0.2c"
+  print "ctanbib version 0.2d"
   os.exit(0)
 elseif args.ctan then
   pkgurl = true
@@ -58,7 +68,7 @@
 end
 
 local authors_url = "https://ctan.org/xml/2.0/authors"
-local license_url = "http://www.ctan.org/xml/2.0/licenses"
+local license_url = "https://www.ctan.org/xml/2.0/licenses"
 
 -- change that for different title scheme
 local titleformat = "The %s package"
@@ -65,13 +75,13 @@
 
 local bibtexformat = [[
 @manual{$package,
-title = {$title},
-subtitle = {$subtitle},
-author = {$author},
-url = {$url},
-urldate = {$urldate}, 
-date = {$date},
-version = {$version},
+  title = {$title},
+  subtitle = {$subtitle},
+  author = {$author},
+  url = {$url},
+  urldate = {$urldate}, 
+  date = {$date},
+  version = {$version},
 }
 ]]
 
@@ -159,6 +169,10 @@
   for _, author in ipairs(a) do
     table.insert(retrieved_authors, get_author(author))
   end
+  -- CTAN returns authors in the random order. to fix that, we sort them. 
+  -- I know that it is not a good solution for non-latin and accented names.
+  -- We could use Lua-UCA for the sorting, but I feel it is a bit of overkill.
+  table.sort(retrieved_authors)
   return table.concat(retrieved_authors," and ")
 end
 
@@ -199,6 +213,23 @@
   end
 end
 
+
+local get_copyright_date = function(record)
+  -- we must get the latest <copyright>, because it contains the latest date
+  local copyright_tbl = record:query_selector("copyright")
+  local copyright = copyright_tbl[#copyright_tbl]
+  if copyright  then
+    local year = copyright:get_attribute("year") 
+    if year then
+      -- year can hold a range of year. we will chose the newest date
+      return year:match("(%d+)$")
+    end
+
+  end
+  
+end
+
+
 local ctan_url = function(record, pkgname)
   return "https://ctan.org/pkg/"..pkgname
 end
@@ -244,6 +275,9 @@
     e.url = ctan_path(record)
   end
   e.version, e.date = get_version(record)
+  if not e.date then 
+    e.date = get_copyright_date(record)
+  end
   e.urldate = os.date("%Y-%m-%d")
 
   local result = compile(bibtexformat, e)

Modified: trunk/Master/texmf-dist/doc/man/man1/ctanbib.1
===================================================================
--- trunk/Master/texmf-dist/doc/man/man1/ctanbib.1	2023-10-25 20:00:51 UTC (rev 68649)
+++ trunk/Master/texmf-dist/doc/man/man1/ctanbib.1	2023-10-25 20:01:02 UTC (rev 68650)
@@ -1,6 +1,6 @@
 .\" Manpage for ctanbib.
 .\" Contact michal.h21 at gmail.com to correct errors or typos.
-.TH ctanbib 1 "18 Sep 2023" "0.2c" "ctanbib man page"
+.TH ctanbib 1 "25 Oct 2023" "0.2d" "ctanbib man page"
 .SH NAME
 ctanbib
 \- retrieve bibliographic information for packages hosted on CTAN.
@@ -9,17 +9,28 @@
 .SH DESCRIPTION
 This command can retrieve bibliographic information for TeX packages hosted on
 CTAN in the BibTeX format.
+
+
+Look up the Catalogue entry for each PKGNAME on CTAN (at
+https://ctan.org/xml/2.0/pkg/PKGNAME), and convert relevant information
+to a BibTeX entry.
+
+By default, the url field in the output entry is the package's home
+field value if that is specified in the Catalogue entry; if it isn't,
+https://ctan.org/pkg/PKGNAME is used.
+
 .SH OPTIONS
 .IP -c,--ctan 
-use @ctan type instead of @manual. The difference between the two is that the
-url field contains package CTAN path, instead of link to the package.
+Always use CTAN /pkg/ url instead of the package homepage 
 .IP -C,--CTAN 
-like --ctan option, but use original url instead of CTAN path.
+Use the package's CTAN path as url (e.g.: /support/ctanbib)
+.IP -e,--entrytype 
+(default manual)  Change entry type
 .IP -h,--help 
 print the help message.
 .IP -p,--pkgname
-put the package name in a \ctanbibpkgname command. This command can be
-redefined in the document for the desired formatting.
+Wrap the package name in a \ctanbibpkgname command
+This command can be redefined in the document for the desired formatting.
 .IP -v,--version 
 print the version info.
 .SH EXAMPLES
@@ -32,13 +43,13 @@
 .nf
 .ft CW
 @manual{latex,
-title = {The Latex package},
-subtitle = {A TeX macro package that defines LaTeX},
-author = {Lamport, Leslie and The LaTeX Team},
-url = {http://www.latex-project.org/},
-urldate = {2018-08-23}, 
-date = {2018-04-01},
-version = {PL 5}
+  title = {The Latex package},
+  subtitle = {A TeX macro package that defines LaTeX},
+  author = {Lamport, Leslie and The LaTeX Team},
+  url = {http://www.latex-project.org/},
+  urldate = {2018-08-23}, 
+  date = {2018-04-01},
+  version = {PL 5}
 }
 .ft R
 .fi

Modified: trunk/Master/texmf-dist/doc/man/man1/ctanbib.man1.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex	2023-10-25 20:00:51 UTC (rev 68649)
+++ trunk/Master/texmf-dist/doc/support/ctanbib/ctanbib-doc.tex	2023-10-25 20:01:02 UTC (rev 68650)
@@ -1,4 +1,4 @@
-\documentclass{ltxdoc}
+\documentclass[11pt]{ltxdoc}
 \newcommand\package[1]{\texttt{#1}}
 \usepackage{longtable}
 \usepackage{tabularx}
@@ -18,7 +18,14 @@
 \section{Introduction}
 This package provides script named \package{ctanbib} which can be used for retrieving of the bibliographic information for packages hosted on CTAN.
 
+It looks up the Catalogue entry for each PKGNAME on CTAN (at
+\url{https://ctan.org/xml/2.0/pkg/PKGNAME}), and convert relevant information
+to a BibTeX entry.
 
+By default, the url field in the output entry is the package's home
+field value if that is specified in the Catalogue entry; if it isn't,
+\url{https://ctan.org/pkg/PKGNAME is used}.
+
 \section{Usage}
 
 
@@ -37,11 +44,11 @@
 \section{Available options}
 
 \begin{description}
-  \item[-c,-\/-ctan] use the CTAN package entry as package URL instead of URL provided by the package.
-  \item[-C,-\/-ctanpath]   use package's CTAN path as URL
+  \item[-c,-\/-ctan] always use CTAN /pkg/ url instead of the package homepage 
+  \item[-C,-\/-ctanpath] use the package's CTAN path as url (e.g.: /support/ctanbib)
   \item[-e,-\/-entrypoint] explicitly set the Bib\TeX\ entry type.
   \item[-h,-\/-help] print the help message.
-  \item[-p,-\/-pkgname] Put the package name in a \verb|\ctanbibpkgname| command.
+  \item[-p,-\/-pkgname] wrap the package name in a \verb|\ctanbibpkgname| command.
   \item[-v,-\/-version] print the version info.
 \end{description}
 
@@ -53,17 +60,17 @@
 \end{verbatim}
 
 
-\noindent This invocation will print data in the Bib\LaTeX\ format to the standard output:
+\noindent This invocation will print data in the Bib(La)\TeX\ format to the standard output:
 
 \begin{verbatim}
 @manual{latex,
-title = {The latex package},
-subtitle = {A TeX macro package that defines LaTeX},
-author = {{The LaTeX Team} and Lamport, Leslie},
-url = {http://www.latex-project.org/},
-urldate = {2021-06-26},
-date = {},
-version = {2021-06-01},
+  title = {The latex package},
+  subtitle = {A TeX macro package that defines LaTeX},
+  author = {{The LaTeX Team} and Lamport, Leslie},
+  url = {http://www.latex-project.org/},
+  urldate = {2021-06-26},
+  date = {},
+  version = {2021-06-01},
 }
 \end{verbatim}
 
@@ -79,10 +86,10 @@
 
 \begin{verbatim}
 @manual{latex,
-title = {The latex package},
-...
-url = {https://ctan.org/pkg/latex},
-...
+  title = {The latex package},
+  ...
+  url = {https://ctan.org/pkg/latex},
+  ...
 }
 \end{verbatim}
 
@@ -96,9 +103,9 @@
 
 \begin{verbatim}
 @manual{biblatex,
-...
-url = {/macros/latex/contrib/biblatex},
-...
+  ...
+  url = {/macros/latex/contrib/biblatex},
+  ...
 }
 \end{verbatim}
 
@@ -114,7 +121,7 @@
 
 \begin{verbatim}
 @ctan{latex,
-...
+  ...
 }
 \end{verbatim}
 
@@ -154,6 +161,12 @@
 \section{Changelog}
 
 \begin{changelog}
+  \change{2023-10-25}{Version 0.2d released}
+  \change{2023-10-20}{Sort authors alphabetically}
+  \change{2023-10-19}{Updated the \verb|--help| message}
+  \change{2023-10-16}{Use larger font in the documentation}
+  \change{2023-10-16}{Indent the Bib\TeX\ entry by two spaces}
+  \change{2023-10-08}{Get date from the copyright field if we cannot retrieve it from version}
   \change{2023-09-18}{Version 0.2c released}
   \change{2023-09-14}{Renamed the \verb|--tugboat| option to \verb|--pkgname|}
   \change{2023-09-12}{Don't capitalize package names}

Modified: trunk/Master/texmf-dist/scripts/ctanbib/ctanbib
===================================================================
--- trunk/Master/texmf-dist/scripts/ctanbib/ctanbib	2023-10-25 20:00:51 UTC (rev 68649)
+++ trunk/Master/texmf-dist/scripts/ctanbib/ctanbib	2023-10-25 20:01:02 UTC (rev 68650)
@@ -21,21 +21,31 @@
 local pkgurl = false
 local msg = [[ctanbib - convert ctan package information to bibtex format
 Usage:
-ctanbib [options] name1 name2 ...
+ctanbib [options] PKGNAME1 PKGNAME2 ...
+
+Look up the Catalogue entry for each PKGNAME on CTAN (at
+https://ctan.org/xml/2.0/pkg/PKGNAME), and convert relevant information
+to a BibTeX entry.
+
+By default, the url field in the output entry is the package's home
+field value if that is specified in the Catalogue entry; if it isn't,
+https://ctan.org/pkg/PKGNAME is used.
+
 Available options:
-  -c,--ctan       Use CTAN URL instead of the package homepage 
-  -C,--ctanpath   Use package's CTAN path as URL
+  -c,--ctan       Always use CTAN /pkg/ url instead of the package homepage 
+  -C,--ctanpath   Use the package's CTAN path as url (e.g.: /support/ctanbib)
   -e,--entrytype  (default manual)  Change entry type
   -h,--help       Print this message
-  -p,--pkgname    Put the package name in a \ctanbibpkgname command
+  -p,--pkgname    Wrap the package name in a \ctanbibpkgname command
   -v,--version    Print version info
-  ]]
+
+ctanbib package page: https://ctan.org/pkg/ctanbib]]
 local args = lapp(msg)
 if args.help then
   print(msg)
   os.exit(0)
 elseif args.version then
-  print "ctanbib version 0.2c"
+  print "ctanbib version 0.2d"
   os.exit(0)
 elseif args.ctan then
   pkgurl = true
@@ -58,7 +68,7 @@
 end
 
 local authors_url = "https://ctan.org/xml/2.0/authors"
-local license_url = "http://www.ctan.org/xml/2.0/licenses"
+local license_url = "https://www.ctan.org/xml/2.0/licenses"
 
 -- change that for different title scheme
 local titleformat = "The %s package"
@@ -65,13 +75,13 @@
 
 local bibtexformat = [[
 @manual{$package,
-title = {$title},
-subtitle = {$subtitle},
-author = {$author},
-url = {$url},
-urldate = {$urldate}, 
-date = {$date},
-version = {$version},
+  title = {$title},
+  subtitle = {$subtitle},
+  author = {$author},
+  url = {$url},
+  urldate = {$urldate}, 
+  date = {$date},
+  version = {$version},
 }
 ]]
 
@@ -159,6 +169,10 @@
   for _, author in ipairs(a) do
     table.insert(retrieved_authors, get_author(author))
   end
+  -- CTAN returns authors in the random order. to fix that, we sort them. 
+  -- I know that it is not a good solution for non-latin and accented names.
+  -- We could use Lua-UCA for the sorting, but I feel it is a bit of overkill.
+  table.sort(retrieved_authors)
   return table.concat(retrieved_authors," and ")
 end
 
@@ -199,6 +213,23 @@
   end
 end
 
+
+local get_copyright_date = function(record)
+  -- we must get the latest <copyright>, because it contains the latest date
+  local copyright_tbl = record:query_selector("copyright")
+  local copyright = copyright_tbl[#copyright_tbl]
+  if copyright  then
+    local year = copyright:get_attribute("year") 
+    if year then
+      -- year can hold a range of year. we will chose the newest date
+      return year:match("(%d+)$")
+    end
+
+  end
+  
+end
+
+
 local ctan_url = function(record, pkgname)
   return "https://ctan.org/pkg/"..pkgname
 end
@@ -244,6 +275,9 @@
     e.url = ctan_path(record)
   end
   e.version, e.date = get_version(record)
+  if not e.date then 
+    e.date = get_copyright_date(record)
+  end
   e.urldate = os.date("%Y-%m-%d")
 
   local result = compile(bibtexformat, e)



More information about the tex-live-commits mailing list.