<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w

# mathscinet.PL - automates getting bibtex references from MathSciNet
#
# Author:       Michael Tweedale &lt;m.tweedale@bristol.ac.uk&gt;
# Version:      0.1
# Licence:      GPL

use LWP::UserAgent;
use URI::URL;
use URI::Escape;
use Getopt::Long;

$VERSION='0.1';
$curbox=4; # MathSciNet form has boxes for search terms numbered 4...7
$search="";
$ua=new LWP::UserAgent;
$hdrs=new HTTP::Headers(Accept =&gt; 'text/html',
  User_Agent =&gt; "mathscinet.PL $VERSION");

sub version()
{
  print STDERR &lt;&lt; "EOF";
mathscinet $VERSION
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License &lt;http://www.gnu.org/licenses/gpl.html&gt;.
There is NO WARRANTY, to the extent permitted by law.

Written by Michael Tweedale &lt;m.tweedale\@bristol.ac.uk&gt;.
EOF
}

sub usage()
{
  print STDERR &lt;&lt; "EOF";
Usage: $0 SEARCH...
Gets references from MathSciNet in bibtex format.

-t, --title    phrase from the title of the article or book
-a, --author   name of one of the authors
-j, --journal  journal the article appeared in
-s, --series   series the book appeared in
-m, --MR       Math Reviews number
    --help     display this help and exit
    --version  output version information and exit

Example 1: $0 -t "free+groups" -t trees -a bestvina
Example 2: $0 -a serre -j annals
Example 3: $0 -a brown -s "graduate+texts"
EOF
}

sub addterm($$)
{
  $curbox&lt;=7 || die("cannot use more than 4 search terms");
  $search .= "&amp;pg$curbox=" . uri_escape($_[0]) . "&amp;s$curbox="
  . uri_escape($_[1]) . "&amp;co$curbox=AND";
  $curbox++;
}

GetOptions('title|t=s' =&gt; sub { addterm("TI",$_[1]); },
  'author|a=s' =&gt; sub { addterm("AUCN",$_[1]); },
  'journal|j=s' =&gt; sub { addterm("JOUR",$_[1]); },
  'series|s=s' =&gt; sub { addterm("SE",$_[1]); },
  'MR|m=s' =&gt; sub { addterm("MR",$_[1]); },
  'help|h' =&gt; sub { usage(); exit 0; },
  'version|v' =&gt; sub { version(); exit 0; });

$search ne "" || usage() &amp;&amp; die("no search terms found");
$url=new URI::URL(
    "http://www.ams.org/mathscinet/search/publications.html?fmt=bibtex$search");
$req=new HTTP::Request(GET, $url, $hdrs);
$resp=$ua-&gt;request($req);

$resp-&gt;is_success ||
  print STDERR $resp-&gt;message . "\n" &amp;&amp;
  die("failed to get search results from MathSciNet");
$resp-&gt;as_string =~ /No publications results/ &amp;&amp;
  die("no results for this search");

map {
  print $_, (( $_=~ '^}') ? "\n\n" : "\n")
    if ((/^\s*&lt;pre&gt;/ .. /^\s*&lt;\/pre&gt;/) &amp;&amp; ! m{^\s*&lt;/?pre&gt;})
} split "\n", $resp-&gt;as_string;

</pre></body></html>