summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/glossaries/makeglossaries
diff options
context:
space:
mode:
authorDr. Clea F. Rees <cfrees@imapmail.org>2008-12-28 23:49:33 +0000
committerDr. Clea F. Rees <cfrees@imapmail.org>2008-12-28 23:49:33 +0000
commit7051fa90f609a783739882d5f945d4c11bf44c48 (patch)
treed51c96157c87cc798fa65f22cfec5559d7df9b3a /Master/texmf-dist/scripts/glossaries/makeglossaries
parentb82fe98b309f7cf832c3dca6f124c2f5c48af80f (diff)
glossaries update 2008/12/28
git-svn-id: svn://tug.org/texlive/trunk@11739 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/glossaries/makeglossaries')
-rwxr-xr-xMaster/texmf-dist/scripts/glossaries/makeglossaries444
1 files changed, 422 insertions, 22 deletions
diff --git a/Master/texmf-dist/scripts/glossaries/makeglossaries b/Master/texmf-dist/scripts/glossaries/makeglossaries
index 3b9f1cb6b48..0e9ea00ef8a 100755
--- a/Master/texmf-dist/scripts/glossaries/makeglossaries
+++ b/Master/texmf-dist/scripts/glossaries/makeglossaries
@@ -2,8 +2,8 @@
# File : makeglossaries
# Author : Nicola Talbot
-# Version : 1.4 (2008/05/10)
-# Description: simple Perl script that calls makeindex.
+# Version : 1.5 (2008/12/26)
+# Description: simple Perl script that calls makeindex or xindy.
# Intended for use with "glossaries.sty" (saves having to remember
# all the various switches)
@@ -28,6 +28,9 @@
# Also makeglossaries and makeglossaries.
#
# History:
+# v1.5 (2008-12-26) :
+# * added support for xindy
+# * picks up ordering information from aux file
# v1.4 (2008-05-10) :
# * added support for filenames with spaces.
# v1.3 (2008-03-08) :
@@ -44,15 +47,19 @@
use Getopt::Std;
use strict;
+use vars qw($opt_q $opt_t $opt_o $opt_s $opt_p $opt_g $opt_c $opt_r
+ $opt_l $opt_i $opt_L $opt_n $opt_C);
-$Getopt::Std::STANDARD_HELP_VERSION = 1;
-my $version="1.3 (2008-03-08)";
+$Getopt::Std::STANDARD_HELP_VERSION = 1;
-my($opt_q, $opt_t, $opt_o, $opt_s, $opt_p, $opt_g, $opt_c, $opt_r,
- $opt_l, $opt_i)=("","","","","","","","","","");
+my $version="1.5 (2008-12-26)";
-getopts('s:o:t:p:ilqrcg');
+# v1.5 added -L <lang> for xindy (but language can be specified in
+# .tex file)
+# v1.5 added -n (print the command that would be issued but
+# don't actually run the command)
+getopts('s:o:t:p:L:C:ilqrcgn');
unless ($#ARGV == 0)
{
@@ -65,6 +72,11 @@ my %exttype = (
main => {in=>'glo', out=>'gls', 'log'=>'glg'},
);
+# v1.5 define require languages for xindy
+
+my %language = ();
+my %codepage = ();
+
my $ext = '';
my $name = $ARGV[0];
@@ -85,7 +97,11 @@ if (length($ARGV[0]) > 3 and substr($ARGV[0],-4,1) eq ".")
}
}
-my $istfile = "$name.ist";
+my $istfile = "";
+
+# should letter ordering be used? (v1.5 added)
+
+my $letterordering = defined($opt_l);
# check aux file for other glossary types
# and for ist file name
@@ -101,7 +117,7 @@ if (open AUXFILE, "$name.aux")
$exttype{$1}{'out'} = $3;
$exttype{$1}{'in'} = $4;
- if (!$opt_q)
+ unless ($opt_q)
{
print "added glossary type '$1' ($2,$3,$4)\n";
}
@@ -114,6 +130,44 @@ if (open AUXFILE, "$name.aux")
# check if double quotes were added to \jobname
$istfile=~s/^"(.*)"\.ist$/$1.ist/;
}
+
+ # v1.5 added
+ if (m/\\\@xdylanguage\s*{([^}]+)}{([^}]*)}/)
+ {
+ $language{$1} = $2;
+ }
+
+ # v1.5 added
+ if (m/\\\@gls\@codepage\s*{([^}]+)}{([^}]*)}/)
+ {
+ $codepage{$1} = $2;
+ }
+
+ # v1.5 added
+ # Allow -l switch to override specification in aux file
+ unless (defined($opt_l))
+ {
+ if (m/\\\@glsorder\s*{([^}]+)}/)
+ {
+ my $ordering = $1;
+
+ if ($ordering eq "word")
+ {
+ $letterordering = 0;
+ }
+ elsif ($ordering eq "letter")
+ {
+ $letterordering = 1;
+ }
+ else
+ {
+ print STDERR
+ "WARNING: Unknown ordering '$letterordering'\n",
+ "Assuming word ordering\n";
+ $letterordering = 0;
+ }
+ }
+ }
}
close AUXFILE;
@@ -123,6 +177,23 @@ else
print STDERR "Unable to open $name.aux: $!\n";
}
+# has the style file been specified?
+unless ($istfile)
+{
+ die "No \\\@istfilename found in '$name.aux'.\n",
+ "Did your LaTeX run fail?\n",
+ "Did your LaTeX run produce any output?\n";
+}
+
+# v1.5 save the general xindy switches
+
+my $xdyopts = '';
+
+unless ($opt_L eq "")
+{
+ $xdyopts .= " -L $opt_L";
+}
+
# save all the general makeindex switches
my $mkidxopts = '';
@@ -132,14 +203,16 @@ if ($opt_i)
$mkidxopts .= " -i";
}
-if ($opt_l)
+if ($letterordering)
{
$mkidxopts .= " -l";
+ $xdyopts .= " -M ord/letorder";
}
if ($opt_q)
{
$mkidxopts .= " -q";
+ $xdyopts .= " -q";
}
if ($opt_r)
@@ -167,16 +240,29 @@ unless ($opt_s eq "")
$istfile = $opt_s;
}
+# Use xindy if style file ends with .xdy otherwise use makeindex
+
+my $usexindy = $istfile=~m/\.xdy\Z/;
+
if ($ext ne '')
{
+ # an extension has been specified, so only process
+ # the specified file
my %thistype = %{$exttype{'main'}}; #default
+ my $thislang = "";
+ my $thiscodepage = "";
+
foreach my $type (keys %exttype)
{
if ($exttype{$type}{'in'} eq $ext)
{
%thistype = %{$exttype{$type}};
+ $thislang = $language{$type};
+
+ $thiscodepage = $codepage{$type};
+
last;
}
}
@@ -203,11 +289,21 @@ if ($ext ne '')
$transcript = $opt_t;
}
- &makeindex("$name.$ext",$outfile,$transcript,$istfile,
- $mkidxopts,$opt_q);
+ if ($usexindy)
+ {
+ &xindy("$name.$ext", $outfile, $transcript,$istfile,
+ $thislang, $thiscodepage, $xdyopts, $opt_q, $opt_n);
+ }
+ else
+ {
+ &makeindex("$name.$ext",$outfile,$transcript,$istfile,
+ $mkidxopts,$opt_q, $opt_n);
+ }
}
else
{
+ # no file extension specified so process all glossary types
+
foreach my $type (keys %exttype)
{
my %thistype = %{$exttype{$type}};
@@ -238,8 +334,17 @@ else
$transcript = $opt_t;
}
- &makeindex($inputfile,$outfile,$transcript,
- $istfile,$mkidxopts,$opt_q);
+ if ($usexindy)
+ {
+ &xindy($inputfile,$outfile,$transcript,$istfile,
+ $language{$type},$codepage{$type},
+ $xdyopts,$opt_q,$opt_n);
+ }
+ else
+ {
+ &makeindex($inputfile,$outfile,$transcript,
+ $istfile,$mkidxopts,$opt_q,$opt_n);
+ }
}
else
{
@@ -249,7 +354,7 @@ else
}
sub makeindex{
- my($in,$out,$trans,$ist,$rest,$quiet) = @_;
+ my($in,$out,$trans,$ist,$rest,$quiet,$dontexec) = @_;
my($name,$cmdstr,$buffer,$n,$i,$j);
my(@stuff,@item);
@@ -260,26 +365,321 @@ sub makeindex{
print "makeindex $cmdstr\n";
}
- `makeindex $cmdstr`;
+ unless ($dontexec)
+ {
+ open STATUS, "makeindex $cmdstr 2>&1 |"
+ or die "Can't fork: $!\n";
+
+ my $status = '';
+
+ while (<STATUS>)
+ {
+ $status .= $_;
+ }
+
+ close STATUS;
+
+ if ($?)
+ {
+ my $errno = $?;
+
+ if (open LOGFILE, ">>$trans")
+ {
+ print LOGFILE "\n$status";
+ close LOGFILE;
+ }
+ else
+ {
+ print STDERR "Unable to open '$trans' $!\n";
+ }
+
+ die "Call to makeindex failed (errno=$errno):\n", $status;
+ }
+
+ print $status;
+ }
+}
+
+sub xindy{
+ my($in,$out,$trans,$ist,$language,$codepage,$rest,$quiet,
+ $dontexec) = @_;
+ my($cmdstr, $langparam, $main);
+ my($module);
+
+ $module = $ist;
+ $module=~s/\.xdy\Z//;
+
+ # map babel names to xindy names
+ if ($language eq "frenchb")
+ {
+ $language = "french";
+ }
+ elsif ($language=~/^n?germanb?$/)
+ {
+ $language = "german";
+ }
+ elsif ($language eq "magyar")
+ {
+ $language = "hungarian";
+ }
+ elsif ($language eq "lsorbian")
+ {
+ $language = "lower-sorbian";
+ }
+ elsif ($language eq "norsk")
+ {
+ $language = "norwegian";
+ }
+ elsif ($language eq "portuges")
+ {
+ $language = "portuguese";
+ }
+ elsif ($language eq "russianb")
+ {
+ $language = "russian";
+ }
+ elsif ($language eq "slovene")
+ {
+ $language = "slovenian";
+ }
+ elsif ($language eq "ukraineb")
+ {
+ $language = "ukrainian";
+ }
+ elsif ($language eq "usorbian")
+ {
+ $language = "upper-sorbian";
+ }
+
+ if ($language)
+ {
+ $langparam = "-L $language";
+ }
+ else
+ {
+ $langparam = "";
+ }
+
+ # most languages work with xindy's default codepage, but
+ # some don't, so if the codepage isn't specific, check
+ # the known cases that will generate an error
+ # and supply a default. (For all other cases, it's up to the
+ # user to supply a codepage.)
+
+ if ($codepage eq '')
+ {
+ if ($language eq 'dutch')
+ {
+ $codepage = "ij-as-ij";
+ }
+ elsif ($language eq 'german')
+ {
+ $codepage = "din";
+ }
+ elsif ($language eq 'gypsy')
+ {
+ $codepage = "northrussian";
+ }
+ elsif ($language eq 'hausa')
+ {
+ $codepage = "utf";
+ }
+ elsif ($language eq 'klingon')
+ {
+ $codepage = "utf";
+ }
+ elsif ($language eq 'latin')
+ {
+ $codepage = "utf";
+ }
+ elsif ($language eq 'mongolian')
+ {
+ $codepage = "cyrillic";
+ }
+ elsif ($language eq 'slovak')
+ {
+ $codepage = "small";
+ }
+ elsif ($language eq 'spanish')
+ {
+ $codepage = "modern";
+ }
+ elsif ($language eq 'vietnamese')
+ {
+ $codepage = "utf";
+ }
+ }
+
+ my $codepageparam = "";
+
+ if ($codepage)
+ {
+ $codepageparam = "-C $codepage";
+ }
+
+ $main = join(' ',
+ "-I xindy",
+ "-M \"$module\"",
+ "-t \"$trans\"",
+ "-o \"$out\"",
+ "\"$in\"");
+
+ $cmdstr = join(' ', $rest, $langparam, $codepageparam, $main);
+
+ unless ($quiet)
+ {
+ print "xindy $cmdstr\n";
+ }
+
+ unless ($dontexec)
+ {
+ open STATUS, "xindy $cmdstr 2>&1 |" or die "Can't fork: $!\n";
+
+ my $status = '';
+ my $warnings = "";
+ my $retry ="";
+
+ while (<STATUS>)
+ {
+ $status .= $_;
+
+ $warnings .= $_ if /WARNING:/;
+ }
+
+ close STATUS;
+
+ if ($status=~/Cannot locate xindy module for language ([^\s]+) in codepage ([^\s]+)/)
+ {
+ $cmdstr = join(' ', $rest, $langparam, $main);
+
+ unless ($quiet)
+ {
+ my $message = "$&\nRetrying using default codepage.\n";
+
+ print STDERR $message;
+
+ $retry .= $message;
+
+ print "xindy $cmdstr\n";
+ }
+
+ open STATUS, "xindy $cmdstr 2>&1 |"
+ or die "Can't fork: $!\n";
+
+ $status = '';
+
+ while (<STATUS>)
+ {
+ $status .= $_;
+ }
+
+ close STATUS;
+ }
+
+ if ($status=~/Cannot locate xindy module for language ([^\s]+)/
+ and $1 ne 'general')
+ {
+ $cmdstr = join(' ', $rest, "-L general", $main);
+
+ unless ($quiet)
+ {
+ my $message = "$&\nRetrying with -L general\n";
+
+ print STDERR $message;
+ $retry .= $message;
+
+ print "xindy $cmdstr\n";
+ }
+
+ open STATUS, "xindy $cmdstr 2>&1 |"
+ or die "Can't fork: $!\n";
+
+ $status = '';
+
+ while (<STATUS>)
+ {
+ $status .= $_;
+ }
+
+ close STATUS;
+ }
+
+ if ($?)
+ {
+ my $errno = $?;
+
+ if (open LOGFILE, ">>$trans")
+ {
+ print LOGFILE "\n$status";
+ close LOGFILE;
+ }
+ else
+ {
+ print STDERR "Unable to open '$trans' $!\n";
+ }
+
+ if ($language)
+ {
+ die "Call to xindy failed (errno=$errno):\n", $status;
+ }
+ else
+ {
+ # If the language hasn't been set, then it may be
+ # because the document doesn't contain
+ # \printglossaries/\printglossary or it may be
+ # because the user has a customized style file that
+ # contains the language settings.
+
+ die "Call to xindy failed (errno=$errno):\n", $status,
+ "\n\nNo language detected.",
+ "\nHave you remembered to use \\printglossary\n",
+ "or \\printglossaries in your document?\n\n";
+ }
+ }
+
+ print $status;
+
+ if (open LOGFILE, ">>$trans")
+ {
+ print LOGFILE "\n$warnings";
+
+ if ($retry)
+ {
+ print LOGFILE "\nmakeglossaries messages:\n\n", $retry;
+ }
+
+ close LOGFILE;
+ }
+ else
+ {
+ print STDERR "Unable to open '$trans' $!\n";
+ }
+
+ }
}
sub HELP_MESSAGE{
print "\nSyntax : makeglossaries [options] <filename>\n\n";
print "For use with the glossaries package to pass relevant\n";
- print "files to makeindex\n\n";
+ print "files to makeindex or xindy\n\n";
print "<filename>\tBase name of glossary file(s). This should\n";
print "\t\tbe the name of your main LaTeX document without any\n";
print "\t\textension.\n";
- print "\nOptions:\n";
+ print "\n General Options:\n";
+ print "-o <gls>\tUse <gls> as the output file.\n";
+ print "-q\t\tQuiet mode\n";
+ print "-s <sty>\tEmploy <sty> as the style file\n";
+ print "-t <log>\tEmploy <log> as the transcript file\n";
+
+ print "\n Xindy Options:\n";
+ print "-L <language>\tUse <language>.\n";
+
+ print "\n Makeindex Options:\n";
print "-c\t\tCompress intermediate blanks\n";
print "-g\t\tEmploy German word ordering\n";
print "-l\t\tLetter ordering\n";
- print "-o <gls>\tUse <gls> as the output file.\n";
print "-p <num>\tSet the starting page number to be <num>\n";
- print "-q\t\tQuiet mode\n";
print "-r\t\tDisable implicit page range formation\n";
- print "-s <sty>\tEmploy <sty> as the style file\n";
- print "-t <log>\tEmploy <log> as the transcript file\n";
print "\nSee makeindex documentation for further details on these ";
print "options\n";
}