| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
# File : makeglossaries |
| 4 |
# Author : Nicola Talbot |
| 5 |
# Version : 4.7 |
| 6 |
# Description: simple Perl script that calls makeindex or xindy. |
| 7 |
# Intended for use with "glossaries.sty" (saves having to remember |
| 8 |
# all the various switches) |
| 9 |
|
| 10 |
# This file is distributed as part of the glossaries LaTeX package. |
| 11 |
# Copyright 2007-2025 Nicola L.C. Talbot |
| 12 |
# This work may be distributed and/or modified under the |
| 13 |
# conditions of the LaTeX Project Public License, either version 1.3 |
| 14 |
# of this license or any later version. |
| 15 |
# The latest version of this license is in |
| 16 |
# http://www.latex-project.org/lppl.txt |
| 17 |
# and version 1.3 or later is part of all distributions of LaTeX |
| 18 |
# version 2005/12/01 or later. |
| 19 |
# |
| 20 |
# This work has the LPPL maintenance status `maintained'. |
| 21 |
# |
| 22 |
# The Current Maintainer of this work is Nicola Talbot. |
| 23 |
|
| 24 |
# This work consists of the files glossaries.dtx and glossaries.ins |
| 25 |
# and the derived files glossaries.sty, glossaries-prefix.sty, |
| 26 |
# glossary-hypernav.sty, glossary-inline.sty, glossary-list.sty, |
| 27 |
# glossary-long.sty, glossary-longbooktabs.sty, glossary-longragged.sty, |
| 28 |
# glossary-mcols.sty, glossary-super.sty, glossary-superragged.sty, |
| 29 |
# glossary-tree.sty, glossaries-compatible-207.sty, |
| 30 |
# glossaries-compatible-307.sty, glossaries-accsupp.sty, |
| 31 |
# glossaries-babel.sty, glossaries-polyglossia.sty, glossaries.l2h. |
| 32 |
# Also makeglossaries and makeglossaries-lite.lua. |
| 33 |
|
| 34 |
my $version="4.7 (2025-05-14)"; |
| 35 |
|
| 36 |
# History: |
| 37 |
# v4.7: |
| 38 |
# * allow dots in base name and allow ".aux" extension to be |
| 39 |
# specified. |
| 40 |
# v4.51 - v4.6 |
| 41 |
# * No change. (Version number updated in line with glossaries.sty) |
| 42 |
# v4.50: |
| 43 |
# * Added -e (don't fix encap clashes) |
| 44 |
# * Add check for glsignore with encap clashes |
| 45 |
# * Don't fix encap clash if counter or prefix different |
| 46 |
# * Added check for illegal page |
| 47 |
# * Added brazil, brazilian, canadian and canadien mappings |
| 48 |
# v4.48-4.49: |
| 49 |
# * No change. (Version number updated in line with glossaries.sty) |
| 50 |
# v4.47: |
| 51 |
# * Added hybrid instructions if record option detected but not |
| 52 |
# \makeglossaries |
| 53 |
# * Added quote_if_spaced subroutine |
| 54 |
# v4.35 - v4.46: |
| 55 |
# * No change. (Version number updated in line with glossaries.sty) |
| 56 |
# v4.34: |
| 57 |
# * Added check for \glsxtr@resource |
| 58 |
# v4.33: |
| 59 |
# * Version number synchronized with glossaries.sty |
| 60 |
# v2.21: |
| 61 |
# * Fixed spelling of \GlsAddXdyLocation |
| 62 |
# * Adjusted range encap clash |
| 63 |
# v2.20 (2016/12/16) |
| 64 |
# * Added check for \glsxtr@makeglossaries |
| 65 |
# v2.19 (2016/05/27) |
| 66 |
# * Improved check in &parse_for_xindy_nosort |
| 67 |
# v2.18 (2016/01/24) |
| 68 |
# * Added &parse_for_xindy_nosort to help diagnose xindy's empty |
| 69 |
# index key warning/error. |
| 70 |
# * Added check for makeindex's multiple encap warning. |
| 71 |
# v2.17 (2015/11/30) |
| 72 |
# * Escaped { in regular expressions. |
| 73 |
# http://www.dickimaw-books.com/cgi-bin/bugtracker.cgi?action=view&key=101 |
| 74 |
# v2.16 (2015/06/28) |
| 75 |
# * Added check for "german" and codepage that doesn't contain |
| 76 |
# "din5007", "duden" or "braille". If missing, "din5007-" is |
| 77 |
# prefixed to the codepage. |
| 78 |
# v2.15 (2014/07/30) |
| 79 |
# * Removed hard-coded three character extension assumption |
| 80 |
# www.dickimaw-books.com/cgi-bin/bugtracker.cgi?action=view&key=55 |
| 81 |
# * Added message to indicate the number of ignored glossaries |
| 82 |
# when the extension is specified. |
| 83 |
# v2.14 (2014/03/06) |
| 84 |
# * Added -Q and -k options |
| 85 |
# v2.13 (2014/01/21) |
| 86 |
# * Added check for leading and trailing quotes in filename |
| 87 |
# v2.12 (2014/01/20) |
| 88 |
# * Added check for '*' in istfilename |
| 89 |
# * Fixed bug report |
| 90 |
# http://www.dickimaw-books.com/cgi-bin/bugtracker.cgi?action=view&key=33 |
| 91 |
# * Added error text hashes |
| 92 |
# v2.11 (2014/01/17): |
| 93 |
# * Added check for backslashes in -x, -m and -d paths |
| 94 |
# * Added double-quotes around $appname in &run_app |
| 95 |
# v2.10 (2013/12/01): |
| 96 |
# * initialise $language to suppress warnings |
| 97 |
# v2.09 (2013-11-12): |
| 98 |
# * added check for -q switch when issuing warnings. |
| 99 |
# v2.08 (2013-10-14): |
| 100 |
# * added -x and -m options |
| 101 |
# v2.07 (2013-06-17): |
| 102 |
# * added check for success on chdir if -d used |
| 103 |
# * added dialect map |
| 104 |
# v2.06 (2013-04-21): |
| 105 |
# * added "din5007" as default if language is set to "german" |
| 106 |
# v2.05 (2012-11-12): |
| 107 |
# * added -d option |
| 108 |
# v2.04 (2012-04-19): |
| 109 |
# * fixed bug in &scan_aux |
| 110 |
# v2.03 (2011-04-12): |
| 111 |
# * added warning about possibly needing 'nomain' package option |
| 112 |
# v2.02 (2011-04-2): |
| 113 |
# * Prints version number at start of run unless -q |
| 114 |
# * Added more diagnostics. |
| 115 |
# v2.01 (2010-09-29): |
| 116 |
# * Added 'use warnings' |
| 117 |
# v2.0 (2010-06-30) : |
| 118 |
# * Made file handle local in &scan_aux |
| 119 |
# v1.9 (2010-06-14) : |
| 120 |
# * Check for \@input |
| 121 |
# v1.8 (2009-11-03) : |
| 122 |
# * Create an empty output file if the input file is empty |
| 123 |
# without calling xindy/makeindex |
| 124 |
# v1.7 (2009-09-23) : |
| 125 |
# * Issue warning rather than error when empty/non existent file |
| 126 |
# checks fail |
| 127 |
# v1.6 (2009-05-24) : |
| 128 |
# * main glossary no longer automatically added |
| 129 |
# (only added if information in aux file) |
| 130 |
# * if file extension is specified, check added to ensure it |
| 131 |
# corresponds to a known glossary extension. |
| 132 |
# * added file existence test and file empty test |
| 133 |
# v1.5 (2008-12-26) : |
| 134 |
# * added support for xindy |
| 135 |
# * picks up ordering information from aux file |
| 136 |
# v1.4 (2008-05-10) : |
| 137 |
# * added support for filenames with spaces. |
| 138 |
# v1.3 (2008-03-08) : |
| 139 |
# * changed first line from /usr/bin/perl -w to /usr/bin/env perl |
| 140 |
# (Thanks to Karl Berry for suggesting this.) |
| 141 |
# v1.2 (2008-03-02) : |
| 142 |
# * added support for --help and --version |
| 143 |
# * improved error handling |
| 144 |
# v1.1 (2008-02-13) : |
| 145 |
# * added -w and strict |
| 146 |
# * added check to ensure .tex file not passed to makeglossaries |
| 147 |
# |
| 148 |
# v1.0 (2007-05-10) : Initial release. |
| 149 |
|
| 150 |
use Getopt::Std; |
| 151 |
use strict; |
| 152 |
# v2.01 added the following line |
| 153 |
use warnings; |
| 154 |
# v2.05 added $opt_d |
| 155 |
# v2.08 added $opt_x and $opt_m |
| 156 |
# v4.50 added $opt_e |
| 157 |
use vars qw($opt_q $opt_t $opt_o $opt_s $opt_p $opt_g $opt_c $opt_r |
| 158 |
$opt_l $opt_i $opt_L $opt_n $opt_C $opt_d $opt_x $opt_m $opt_Q |
| 159 |
$opt_k $opt_e); |
| 160 |
|
| 161 |
|
| 162 |
$Getopt::Std::STANDARD_HELP_VERSION = 1; |
| 163 |
|
| 164 |
# v1.5 added -L <lang> for xindy (but language can be specified in |
| 165 |
# .tex file) |
| 166 |
# v1.5 added -n (print the command that would be issued but |
| 167 |
# don't actually run the command) |
| 168 |
getopts('s:o:t:p:L:C:ilqQkrcgnd:x:m:e'); |
| 169 |
|
| 170 |
unless ($#ARGV == 0) |
| 171 |
{ |
| 172 |
die "makeglossaries: Need exactly one file argument.\n", |
| 173 |
"Use `makeglossaries --help' for help.\n"; |
| 174 |
} |
| 175 |
|
| 176 |
# v2.02: added: |
| 177 |
print "makeglossaries version $version\n" unless ($opt_q); |
| 178 |
|
| 179 |
# v2.07: added babel dialect -> xindy language map: |
| 180 |
my %languagemap = |
| 181 |
( |
| 182 |
'american' => 'english', |
| 183 |
'austrian' => 'german', |
| 184 |
'brazil' => 'portuguese',# v4.50 |
| 185 |
'brazilian' => 'portuguese',# v4.50 |
| 186 |
'british' => 'english', |
| 187 |
'canadian' => 'english',# v4.50 |
| 188 |
'canadien' => 'french',# v4.50 |
| 189 |
'francais' => 'french', |
| 190 |
'frenchb' => 'french', |
| 191 |
'germanb' => 'german', |
| 192 |
'lsorbian' => 'lower-sorbian', |
| 193 |
'magyar' => 'hungarian', |
| 194 |
'naustrian' => 'german', |
| 195 |
'ngermanb' => 'german', |
| 196 |
'ngerman' => 'german', # v2.16 |
| 197 |
'norsk' => 'norwegian', |
| 198 |
'portuges' => 'portuguese', |
| 199 |
'russianb' => 'russian', |
| 200 |
'slovene' => 'slovenian', |
| 201 |
'UKenglish' => 'english', |
| 202 |
'USenglish' => 'english', |
| 203 |
'ukraineb' => 'ukrainian', |
| 204 |
'usorbian' => 'upper-sorbian' |
| 205 |
); |
| 206 |
|
| 207 |
# v2.07 added check for success and for -q |
| 208 |
# v2.05 added: |
| 209 |
|
| 210 |
if ($opt_d) |
| 211 |
{ |
| 212 |
# v2.11 check for backslash character if on Windows |
| 213 |
$opt_d=~s/\\/\//g if $^O=~/Win/; |
| 214 |
|
| 215 |
if (chdir $opt_d) |
| 216 |
{ |
| 217 |
print "Changed to '$opt_d'\n" unless ($opt_q); |
| 218 |
} |
| 219 |
else |
| 220 |
{ |
| 221 |
die "Unable to chdir to '$opt_d' $!\n"; |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
# v2.02: added: |
| 226 |
# v2.19: changed value |
| 227 |
my $xdynotist = 2; |
| 228 |
# v2.13: removed |
| 229 |
#my $needcompatibilitymode=2; |
| 230 |
|
| 231 |
# v2.13: added $istnotfound |
| 232 |
my $istnotfound = 3; |
| 233 |
|
| 234 |
# v2.13: added error text: |
| 235 |
my %makeindex_error_text = |
| 236 |
( |
| 237 |
$xdynotist => "Style name indicates makeindex, but may be in xindy format.\n" |
| 238 |
. "Remember to use \\setStyleFile to specify the name\n" |
| 239 |
. "of the style file rather than redefining \\istfilename\n" |
| 240 |
. "explicitly.", |
| 241 |
$istnotfound => "Style file not found. (Have you used \\noist by mistake?)" |
| 242 |
); |
| 243 |
|
| 244 |
my %xindy_error_text = |
| 245 |
( |
| 246 |
'nosort' => "Sort key required for entries only containing command names.", |
| 247 |
'istnotxdy' => |
| 248 |
"Style name has xdy extension, but may be in makeindex format.\n" |
| 249 |
. "Remember to use \\setStyleFile to specify the name\n" |
| 250 |
. "of the style file rather than redefining \\istfilename\n" |
| 251 |
. "explicitly.", |
| 252 |
'missingendquote' => |
| 253 |
"You may have missed a \" character in a command such as \\GlsAddXdyLocation.", |
| 254 |
'nolanguage' => |
| 255 |
"No language detected.\nHave you remembered to use \\printglossary\n". |
| 256 |
"or \\printglossaries in your document?", |
| 257 |
'nomain' => |
| 258 |
"\nRemember to use package option 'nomain' if you don't\n". |
| 259 |
"want to use the main glossary.", |
| 260 |
#v2.21: fixed spelling of \GlsAddXdyLocation |
| 261 |
#v4.50: added reference to esclocations |
| 262 |
'badlocation' => |
| 263 |
"You may have forgotten to add a location \n" |
| 264 |
. "class with \\GlsAddXdyLocation or you may have \n" |
| 265 |
. "the format incorrect or you may need \nthe package option esclocations=true.\n", |
| 266 |
'comp207' => "You may need to add 'compatible-2.07' package option.", |
| 267 |
'noxdyfile' => "Style file not found. (Have you used \\noist by mistake?)" |
| 268 |
); |
| 269 |
|
| 270 |
# define known extensions |
| 271 |
|
| 272 |
# v1.6: removed adding main glossary here as there's no guarantee |
| 273 |
# that it's been used. If it has been used, the information will |
| 274 |
# be picked up later in the aux file |
| 275 |
my %exttype = ( |
| 276 |
# main => {in=>'glo', out=>'gls', 'log'=>'glg'}, |
| 277 |
); |
| 278 |
|
| 279 |
# v1.5 define require languages for xindy |
| 280 |
|
| 281 |
my %language = (); |
| 282 |
my %codepage = (); |
| 283 |
|
| 284 |
my $ext = ''; |
| 285 |
my $name = $ARGV[0]; |
| 286 |
|
| 287 |
# v2.13 added: |
| 288 |
#$name=~s/^"(.*)"$/$1/; |
| 289 |
# v2.15: fix provided by Herb Schulz to allow for extensions that |
| 290 |
# aren't exactly three characters: |
| 291 |
# (HS) changes fix for 3 character extension limit |
| 292 |
my ($basename,$extension) = ($name =~ m/^(.*?)(?:\.([^\.]*))?$/); |
| 293 |
# (HS) end of changes fix for 3 character extension limit |
| 294 |
|
| 295 |
# make sure $extension is defined. (If there was no match in the |
| 296 |
# above, it cause an uninitialised error later.) |
| 297 |
|
| 298 |
# v4.7: allow for dots in basename |
| 299 |
$extension = 'aux' unless ($extension); |
| 300 |
|
| 301 |
my $auxname = $basename; |
| 302 |
|
| 303 |
if ($name=~m/\.aux$/i) |
| 304 |
{ |
| 305 |
$auxname = $name; |
| 306 |
} |
| 307 |
else |
| 308 |
{ |
| 309 |
$auxname .= ".aux"; |
| 310 |
|
| 311 |
unless (-e $auxname) |
| 312 |
{ |
| 313 |
if (-e "$name.aux") |
| 314 |
{ |
| 315 |
$basename = $name; |
| 316 |
$extension = 'aux'; |
| 317 |
$auxname = "$name.aux"; |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
# Make sure users don't try passing the tex file: |
| 323 |
|
| 324 |
# (HS) changes fix for 3 character extension limit |
| 325 |
if (lc($extension) eq 'tex') |
| 326 |
{ |
| 327 |
die("Don't pass the tex file to makeglossaries:\n" |
| 328 |
."either omit the extension or use aux to make all the glossaries, " |
| 329 |
."or specify one of the glossary files, e.g. $name.glo, to " |
| 330 |
."make just that glossary.\n") |
| 331 |
} |
| 332 |
# (HS) end of fix for 3 character extension limit |
| 333 |
|
| 334 |
if ($extension eq 'aux') |
| 335 |
{ |
| 336 |
$ext = ''; |
| 337 |
} |
| 338 |
else |
| 339 |
{ |
| 340 |
$ext = $extension; |
| 341 |
} |
| 342 |
|
| 343 |
$name = $basename; |
| 344 |
|
| 345 |
# v2.01 add check to see if aux file exists |
| 346 |
|
| 347 |
unless (-e $auxname) |
| 348 |
{ |
| 349 |
die "Auxiliary file '$auxname' doesn't exist. Have you run LaTeX?\n"; |
| 350 |
} |
| 351 |
|
| 352 |
my $istfile = ""; |
| 353 |
|
| 354 |
my $glslist = ""; |
| 355 |
|
| 356 |
# should letter ordering be used? (v1.5 added) |
| 357 |
|
| 358 |
my $letterordering = defined($opt_l); |
| 359 |
|
| 360 |
# v2.19 added: |
| 361 |
my $extramkidxopts = ''; |
| 362 |
|
| 363 |
# v4.34 added: |
| 364 |
my $foundbib2glsresource = ''; |
| 365 |
|
| 366 |
# Check aux file for other glossary types, |
| 367 |
# style file name and various other bits of information. |
| 368 |
|
| 369 |
&scan_aux($name); |
| 370 |
|
| 371 |
# has the style file been specified? |
| 372 |
unless ($istfile) |
| 373 |
{ |
| 374 |
if ($foundbib2glsresource) |
| 375 |
{ |
| 376 |
# v4.47 added extra hybrid instructions |
| 377 |
die "Found \\glsxtr\@resource in '$name.aux',\n", |
| 378 |
"but not found \\\@istfilename.\n", |
| 379 |
"You need to run bib2gls not makeglossaries.\n", |
| 380 |
"If you have used record=alsoindex or record=hybrid\n", |
| 381 |
"then add \\makeglossaries to your preamble.\n"; |
| 382 |
} |
| 383 |
else |
| 384 |
{ |
| 385 |
die "No \\\@istfilename found in '$name.aux'.\n", |
| 386 |
"Did your LaTeX run fail?\n", |
| 387 |
"Did your LaTeX run produce any output?\n", |
| 388 |
"Did you remember to use \\makeglossaries?\n"; |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
# v2.08 added $xindyapp and $makeindexapp |
| 393 |
# By default assume they are on the operating system's path |
| 394 |
my $xindyapp = ($opt_x ? $opt_x :'xindy'); |
| 395 |
my $makeindexapp = ($opt_m ? $opt_m :'makeindex'); |
| 396 |
|
| 397 |
my $fixencapclash = ($opt_e ? 0 : 1); |
| 398 |
|
| 399 |
# v2.11 check for backslash character if on Windows |
| 400 |
if ($^O=~/Win/) |
| 401 |
{ |
| 402 |
$xindyapp=~s/\\/\//g; |
| 403 |
$makeindexapp=~s/\\/\//g; |
| 404 |
} |
| 405 |
|
| 406 |
# v1.5 save the general xindy switches |
| 407 |
|
| 408 |
my $xdyopts = ''; |
| 409 |
|
| 410 |
# v2.01 replaced 'unless ($opt_L eq "")' with 'if ($opt_L)' |
| 411 |
if ($opt_L) |
| 412 |
{ |
| 413 |
$xdyopts .= " -L $opt_L"; |
| 414 |
} |
| 415 |
|
| 416 |
# save all the general makeindex switches |
| 417 |
|
| 418 |
my $mkidxopts = ''; |
| 419 |
|
| 420 |
if ($opt_i) |
| 421 |
{ |
| 422 |
# This option is of limited use as the basename must be supplied to |
| 423 |
# makeglossaries |
| 424 |
$mkidxopts .= " -i"; |
| 425 |
} |
| 426 |
|
| 427 |
if ($letterordering) |
| 428 |
{ |
| 429 |
$mkidxopts .= " -l"; |
| 430 |
$xdyopts .= " -M ord/letorder"; |
| 431 |
} |
| 432 |
|
| 433 |
if ($opt_q) |
| 434 |
{ |
| 435 |
# v2.01 removed following lines. (This script now deals with |
| 436 |
# printing messages to STDOUT.) |
| 437 |
#$mkidxopts .= " -q"; |
| 438 |
#$xdyopts .= " -q"; |
| 439 |
} |
| 440 |
|
| 441 |
if ($opt_r) |
| 442 |
{ |
| 443 |
$mkidxopts .= " -r"; |
| 444 |
} |
| 445 |
|
| 446 |
if ($opt_c) |
| 447 |
{ |
| 448 |
$mkidxopts .= " -c"; |
| 449 |
} |
| 450 |
|
| 451 |
if ($opt_g) |
| 452 |
{ |
| 453 |
$mkidxopts .= " -g"; |
| 454 |
} |
| 455 |
|
| 456 |
# v2.01 replaced 'unless ($opt_p eq "")' with 'if ($opt_p)' |
| 457 |
if ($opt_p) |
| 458 |
{ |
| 459 |
$mkidxopts .= " -p $opt_p"; |
| 460 |
} |
| 461 |
|
| 462 |
if ($extramkidxopts) |
| 463 |
{ |
| 464 |
$mkidxopts .= " $extramkidxopts"; |
| 465 |
} |
| 466 |
|
| 467 |
# v2.01 replaced 'unless ($opt_s eq "")' with 'if ($opt_s)' |
| 468 |
if ($opt_s) |
| 469 |
{ |
| 470 |
# v2.01 check if user has specified -s <file>.ist but aux file |
| 471 |
# indicates .xdy ought to be used and vice-versa. Also check if |
| 472 |
# requested style file exists |
| 473 |
|
| 474 |
unless (-e $opt_s) |
| 475 |
{ |
| 476 |
die "\n", |
| 477 |
"Requested style file '$opt_s' doesn't exist.\n\n"; |
| 478 |
} |
| 479 |
|
| 480 |
if ($istfile=~/\.xdy$/ and $opt_s!~/\.xdy$/) |
| 481 |
{ |
| 482 |
die "\n", |
| 483 |
"The auxiliary file indicates that you should be using xindy,\n", |
| 484 |
"but you have specified makeindex style file '$opt_s'\n", |
| 485 |
"Make sure you don't specify 'xindy' as a package option if\n", |
| 486 |
"you want to use makeindex.\n\n", |
| 487 |
"\\usepackage[makeindex]{glossaries}\n\n"; |
| 488 |
} |
| 489 |
elsif ($istfile!~/\.xdy$/ and $opt_s=~/\.xdy$/) |
| 490 |
{ |
| 491 |
die "\n", |
| 492 |
"The auxiliary file indicates that you should be using\n", |
| 493 |
"makeindex, but you have specified xindy style file '$opt_s'.\n", |
| 494 |
"Make sure you specify 'xindy' as a package option if you\n", |
| 495 |
"want to use xindy.\n\n", |
| 496 |
"\\usepackage[xindy]{glossaries}\n\n"; |
| 497 |
} |
| 498 |
|
| 499 |
$istfile = $opt_s; |
| 500 |
} |
| 501 |
|
| 502 |
# Use xindy if style file ends with .xdy otherwise use makeindex |
| 503 |
|
| 504 |
my $usexindy = ($istfile=~m/\.xdy\Z/); |
| 505 |
|
| 506 |
if ($ext) |
| 507 |
{ |
| 508 |
# an extension has been specified, so only process |
| 509 |
# the specified file |
| 510 |
|
| 511 |
# v1.6 %thistype is no longer given a default value |
| 512 |
my %thistype; |
| 513 |
|
| 514 |
my $thislang = ""; |
| 515 |
my $thiscodepage = ""; |
| 516 |
|
| 517 |
my @types = ($glslist ? split /,/, $glslist : keys %exttype); |
| 518 |
|
| 519 |
foreach my $type (@types) |
| 520 |
{ |
| 521 |
if ($exttype{$type}{'in'} eq $ext) |
| 522 |
{ |
| 523 |
%thistype = %{$exttype{$type}}; |
| 524 |
|
| 525 |
$thislang = $language{$type}; |
| 526 |
|
| 527 |
$thiscodepage = $codepage{$type}; |
| 528 |
|
| 529 |
last; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
# v1.6 If %thistype hasn't been defined, then the given |
| 534 |
# extension doesn't correspond to any known glossary type |
| 535 |
|
| 536 |
# v2.01 replaced deprecated 'defined(%thistype)' with %thistype |
| 537 |
unless (%thistype) |
| 538 |
{ |
| 539 |
die "The file extension '$ext' doesn't correspond to any\n", |
| 540 |
"known glossary extension. Try running makeglossaries\n", |
| 541 |
"without an extension, e.g. makeglossaries \"$name\".\n"; |
| 542 |
} |
| 543 |
|
| 544 |
my $outfile; |
| 545 |
|
| 546 |
# v2.01 replaced 'if ($opt_o eq "")' with 'unless ($opt_o)' |
| 547 |
unless ($opt_o) |
| 548 |
{ |
| 549 |
$outfile = "$name.$thistype{out}"; |
| 550 |
} |
| 551 |
else |
| 552 |
{ |
| 553 |
$outfile = $opt_o; |
| 554 |
} |
| 555 |
|
| 556 |
my $transcript; |
| 557 |
|
| 558 |
# v2.01 replaced 'if ($opt_t eq "")' with 'unless ($opt_t)' |
| 559 |
unless ($opt_t) |
| 560 |
{ |
| 561 |
$transcript = "$name.$thistype{'log'}"; |
| 562 |
} |
| 563 |
else |
| 564 |
{ |
| 565 |
$transcript = $opt_t; |
| 566 |
} |
| 567 |
|
| 568 |
# v2.01 remove old transcript file |
| 569 |
|
| 570 |
unless ($opt_n) |
| 571 |
{ |
| 572 |
unlink($transcript); |
| 573 |
} |
| 574 |
|
| 575 |
if ($usexindy) |
| 576 |
{ |
| 577 |
&xindy("$name.$ext", $outfile, $transcript,$istfile, |
| 578 |
$thislang, $thiscodepage, $xdyopts, $opt_q, $opt_n, $xindyapp); |
| 579 |
} |
| 580 |
else |
| 581 |
{ |
| 582 |
&makeindex("$name.$ext",$outfile,$transcript,$istfile, |
| 583 |
$mkidxopts,$opt_q, $opt_n, $makeindexapp, $fixencapclash); |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
# v2.15 added: |
| 588 |
|
| 589 |
my $num_omitted = $#types; |
| 590 |
|
| 591 |
if ($num_omitted == 1) |
| 592 |
{ |
| 593 |
print "1 glossary ignored.\n" unless $opt_q; |
| 594 |
} |
| 595 |
elsif ($num_omitted > 1) |
| 596 |
{ |
| 597 |
print "$num_omitted glossaries ignored.\n" unless $opt_q; |
| 598 |
} |
| 599 |
} |
| 600 |
else |
| 601 |
{ |
| 602 |
# no file extension specified so process all glossary types |
| 603 |
|
| 604 |
my @types = ($glslist ? split /,/, $glslist : keys %exttype); |
| 605 |
|
| 606 |
foreach my $type (@types) |
| 607 |
{ |
| 608 |
my %thistype = %{$exttype{$type}}; |
| 609 |
|
| 610 |
my $inputfile = "$name.$thistype{in}"; |
| 611 |
|
| 612 |
my $outfile; |
| 613 |
|
| 614 |
# v2.01 changed 'if ($opt_o eq "")' with 'unless ($opt_o)' |
| 615 |
unless ($opt_o) |
| 616 |
{ |
| 617 |
$outfile = "$name.$thistype{out}"; |
| 618 |
} |
| 619 |
else |
| 620 |
{ |
| 621 |
$outfile = $opt_o; |
| 622 |
} |
| 623 |
|
| 624 |
# v1.7 print warnings to STDOUT instead of STDERR |
| 625 |
|
| 626 |
# v1.6 added file existence test |
| 627 |
unless (-e $inputfile) |
| 628 |
{ |
| 629 |
# v2.09 suppress warning if -q switch in use |
| 630 |
print "Warning: File '$inputfile' doesn't exist.\n", |
| 631 |
"*** Skipping glossary '$type'. ***\n" unless ($opt_q); |
| 632 |
next; |
| 633 |
} |
| 634 |
|
| 635 |
unless (-r $inputfile) |
| 636 |
{ |
| 637 |
print "Warning: No read access for '$inputfile' $!\n", |
| 638 |
"*** Skipping glossary '$type'. ***\n" unless ($opt_q); |
| 639 |
next; |
| 640 |
} |
| 641 |
|
| 642 |
my $transcript; |
| 643 |
|
| 644 |
# v2.01 changed 'if ($opt_t eq "")' with 'unless ($opt)' |
| 645 |
unless ($opt_t) |
| 646 |
{ |
| 647 |
$transcript = "$name.$thistype{'log'}"; |
| 648 |
} |
| 649 |
else |
| 650 |
{ |
| 651 |
$transcript = $opt_t; |
| 652 |
} |
| 653 |
|
| 654 |
# v1.6 added file empty test |
| 655 |
if (-z $inputfile) |
| 656 |
{ |
| 657 |
my $message = |
| 658 |
"Warning: File '$inputfile' is empty.\n". |
| 659 |
"Have you used any entries defined in glossary '$type'?\n"; |
| 660 |
|
| 661 |
if ($type eq 'main') |
| 662 |
{ |
| 663 |
$message .= |
| 664 |
"Remember to use package option 'nomain' if you\n". |
| 665 |
"don't want to use the main glossary.\n"; |
| 666 |
} |
| 667 |
|
| 668 |
# v2.09 suppress warning if -q switch in use |
| 669 |
warn $message unless $opt_q; |
| 670 |
|
| 671 |
# Write warning to transcript file. |
| 672 |
|
| 673 |
if (open TRANSFD, ">$transcript") |
| 674 |
{ |
| 675 |
print TRANSFD $message; |
| 676 |
close TRANSFD; |
| 677 |
} |
| 678 |
|
| 679 |
# create an empty output file and move on to the next glossary |
| 680 |
|
| 681 |
if (open OFD, ">$outfile") |
| 682 |
{ |
| 683 |
print OFD "\\null\n"; |
| 684 |
close OFD; |
| 685 |
} |
| 686 |
else |
| 687 |
{ |
| 688 |
warn "Unable to create '$outfile' $!\n"; |
| 689 |
} |
| 690 |
|
| 691 |
next; |
| 692 |
} |
| 693 |
|
| 694 |
# v2.01 remove old transcript file |
| 695 |
|
| 696 |
unless ($opt_n) |
| 697 |
{ |
| 698 |
unlink($transcript); |
| 699 |
} |
| 700 |
|
| 701 |
if ($usexindy) |
| 702 |
{ |
| 703 |
&xindy($inputfile,$outfile,$transcript,$istfile, |
| 704 |
$language{$type},$codepage{$type}, |
| 705 |
$xdyopts,$opt_q,$opt_n, $xindyapp); |
| 706 |
} |
| 707 |
else |
| 708 |
{ |
| 709 |
&makeindex($inputfile,$outfile,$transcript, |
| 710 |
$istfile,$mkidxopts,$opt_q,$opt_n, $makeindexapp, $fixencapclash); |
| 711 |
} |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
sub scan_aux{ |
| 716 |
my $name = shift; |
| 717 |
|
| 718 |
# v2.0 added |
| 719 |
local(*AUXFILE); |
| 720 |
|
| 721 |
if (open AUXFILE, "$name.aux") |
| 722 |
{ |
| 723 |
while (<AUXFILE>) |
| 724 |
{ |
| 725 |
#v2.14 added |
| 726 |
if (m/\\\@gls\@reference/ and not $glslist) |
| 727 |
{ |
| 728 |
die "Your document has used \\makenoidxglossaries\n", |
| 729 |
"You don't need makeindex or xindy.\n"; |
| 730 |
} |
| 731 |
|
| 732 |
if (m/\\glsxtr\@makeglossaries\{(.*)\}/) |
| 733 |
{ |
| 734 |
#v2.20 added |
| 735 |
|
| 736 |
$glslist = $1; |
| 737 |
|
| 738 |
unless ($opt_q) |
| 739 |
{ |
| 740 |
print "only processing subset '$glslist'\n"; |
| 741 |
} |
| 742 |
} |
| 743 |
elsif (m/\\\@input\{(.+)\.aux\}/) |
| 744 |
{ |
| 745 |
# v1.9 added |
| 746 |
# v2.17 escaped { in regex |
| 747 |
&scan_aux($1); |
| 748 |
|
| 749 |
# v2.04 added |
| 750 |
# (Fix provided by Daniel Grund) |
| 751 |
next; |
| 752 |
} |
| 753 |
elsif (m/\\\@newglossary\s*\{(.*)\}\{(.*)\}\{(.*)\}\{(.*)\}/) |
| 754 |
{ |
| 755 |
# v2.17 escaped { in regex |
| 756 |
|
| 757 |
$exttype{$1}{'log'} = $2; |
| 758 |
$exttype{$1}{'out'} = $3; |
| 759 |
$exttype{$1}{'in'} = $4; |
| 760 |
|
| 761 |
unless ($opt_q) |
| 762 |
{ |
| 763 |
print "added glossary type '$1' ($2,$3,$4)\n"; |
| 764 |
} |
| 765 |
} |
| 766 |
elsif (m/\\\@istfilename\s*\{([^}]*)\}/) |
| 767 |
{ |
| 768 |
# v2.17 escaped { in regex |
| 769 |
|
| 770 |
$istfile = $1; |
| 771 |
|
| 772 |
# check if double quotes were added to \jobname |
| 773 |
# v2.12 added check for xdy (bug ID 33) |
| 774 |
$istfile=~s/^"(.*)"\.(ist|xdy)$/$1.$2/; |
| 775 |
|
| 776 |
# v2.12 if on Windows, substitute any '*' with ' ' |
| 777 |
# to compensate for MiKTeX bug |
| 778 |
# http://sourceforge.net/p/miktex/bugs/2301/ |
| 779 |
|
| 780 |
if ($^O=~/Win/) |
| 781 |
{ |
| 782 |
$istfile=~tr/\*/ /; |
| 783 |
} |
| 784 |
} |
| 785 |
elsif (m/\\\@xdylanguage\s*\{([^}]+)\}\{([^}]*)\}/) |
| 786 |
{ |
| 787 |
# v1.5 added |
| 788 |
# v2.17 escaped { in regex |
| 789 |
|
| 790 |
$language{$1} = $2; |
| 791 |
} |
| 792 |
elsif (m/\\\@gls\@codepage\s*\{([^}]+)\}\{([^}]*)\}/) |
| 793 |
{ |
| 794 |
# v1.5 added |
| 795 |
# v2.17 escaped { in regex |
| 796 |
|
| 797 |
$codepage{$1} = $2; |
| 798 |
} |
| 799 |
elsif (m/\\\@gls\@extramakeindexopts\{(.*)\}/) |
| 800 |
{ |
| 801 |
# v2.19 added |
| 802 |
|
| 803 |
$extramkidxopts .= $1; |
| 804 |
} |
| 805 |
elsif (m/\\glsxtr\@resource/) |
| 806 |
{ |
| 807 |
# v4.34 added |
| 808 |
|
| 809 |
# No error at this point as a hybrid method is allowed. |
| 810 |
# Error only occurs if no \@istfilename found. |
| 811 |
|
| 812 |
$foundbib2glsresource = 1; |
| 813 |
} |
| 814 |
|
| 815 |
# v1.5 added |
| 816 |
# Allow -l switch to override specification in aux file |
| 817 |
unless (defined($opt_l)) |
| 818 |
{ |
| 819 |
# v2.17 escaped { in regex |
| 820 |
if (m/\\\@glsorder\s*\{([^}]+)\}/) |
| 821 |
{ |
| 822 |
my $ordering = $1; |
| 823 |
|
| 824 |
if ($ordering eq "word") |
| 825 |
{ |
| 826 |
$letterordering = 0; |
| 827 |
} |
| 828 |
elsif ($ordering eq "letter") |
| 829 |
{ |
| 830 |
$letterordering = 1; |
| 831 |
} |
| 832 |
else |
| 833 |
{ |
| 834 |
warn |
| 835 |
"Unknown ordering '$ordering'\n", |
| 836 |
"Assuming word ordering\n" unless ($opt_q); |
| 837 |
$letterordering = 0; |
| 838 |
} |
| 839 |
} |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
close AUXFILE; |
| 844 |
} |
| 845 |
else |
| 846 |
{ |
| 847 |
warn "Unable to open $name.aux: $!\n"; |
| 848 |
} |
| 849 |
} |
| 850 |
|
| 851 |
# v4.47 new |
| 852 |
# Issue #129 was specifically about the Lua script but it's |
| 853 |
# likely the same problem would occur with this Perl script given |
| 854 |
# the same version of cmd.exe |
| 855 |
sub quote_if_spaced{ |
| 856 |
my ($str) = @_; |
| 857 |
|
| 858 |
if ($str=~/ /) |
| 859 |
{ |
| 860 |
$str = "\"$str\""; |
| 861 |
} |
| 862 |
|
| 863 |
$str; |
| 864 |
} |
| 865 |
|
| 866 |
# v2.01 new subroutine run_app added |
| 867 |
sub run_app{ |
| 868 |
my($appname, $appargs, $trans, $quiet, $dontexec) = @_; |
| 869 |
|
| 870 |
local(*STATUS); |
| 871 |
|
| 872 |
my $status = ''; |
| 873 |
my $warnings = ''; |
| 874 |
my $errno = 0; |
| 875 |
my $log = ''; |
| 876 |
|
| 877 |
print "$appname $appargs\n" if ($dontexec or not $quiet); |
| 878 |
|
| 879 |
return if ($dontexec); |
| 880 |
|
| 881 |
# v4.47 |
| 882 |
my $cmdstr = "e_if_spaced($appname) . " $appargs"; |
| 883 |
|
| 884 |
# v2.11 added double-quotes around $appname |
| 885 |
# v2.14 added -k switch |
| 886 |
if (not $opt_k and open (STATUS, "$cmdstr 2>&1 |")) |
| 887 |
{ |
| 888 |
while (<STATUS>) |
| 889 |
{ |
| 890 |
print unless ($quiet); |
| 891 |
|
| 892 |
$warnings .= $_ if (/WARNING:/); |
| 893 |
|
| 894 |
$status .= $_ unless (/^[\w]+ing/ or /^Finished/ or /^Usage:/); |
| 895 |
|
| 896 |
$log .= $_; |
| 897 |
} |
| 898 |
|
| 899 |
close STATUS; |
| 900 |
} |
| 901 |
else |
| 902 |
{ |
| 903 |
unless ($opt_k) |
| 904 |
{ |
| 905 |
$warnings = "Unable to fork \"$appname\" with redirection $!\n"; |
| 906 |
|
| 907 |
# v2.14 added check for quiet switches |
| 908 |
warn $warnings, |
| 909 |
"Retrying without redirection.\n" unless ($quiet or $opt_Q); |
| 910 |
} |
| 911 |
|
| 912 |
$status = `$cmdstr`; |
| 913 |
|
| 914 |
$log = $status; |
| 915 |
|
| 916 |
print $status unless ($quiet); |
| 917 |
} |
| 918 |
|
| 919 |
if ($?) |
| 920 |
{ |
| 921 |
# v2.14 Fixed error number assignment |
| 922 |
$errno = ($? >> 8); |
| 923 |
|
| 924 |
# v2.14 Added check for existence of transcript |
| 925 |
unless (-e $trans) |
| 926 |
{ |
| 927 |
$log .= "\n$appname didn't create a transcript.\n"; |
| 928 |
|
| 929 |
if (not $appname=~/\//) |
| 930 |
{ |
| 931 |
# No path specified |
| 932 |
$log .= "Check that $appname has been installed and\nis on your system's PATH.\n"; |
| 933 |
|
| 934 |
if (defined $ENV{PATH}) |
| 935 |
{ |
| 936 |
$log .= "Your PATH environment variable is set to: \n" |
| 937 |
. $ENV{PATH} . "\n"; |
| 938 |
} |
| 939 |
else |
| 940 |
{ |
| 941 |
$log .= "I'm sorry, I can't detect your PATH environment variable\n"; |
| 942 |
} |
| 943 |
|
| 944 |
$log .= "Try manually running:\n\"$appname\" $appargs\n"; |
| 945 |
} |
| 946 |
elsif (not -e $appname) |
| 947 |
{ |
| 948 |
if ($^O=~/Win/) |
| 949 |
{ |
| 950 |
if (-e "$appname.exe" or -e "$appname.bat") |
| 951 |
{ |
| 952 |
$log .= "Try manually running:\n\"$appname\" $appargs\n"; |
| 953 |
} |
| 954 |
else |
| 955 |
{ |
| 956 |
$log .= "File '$appname' doesn't exist.\n"; |
| 957 |
} |
| 958 |
} |
| 959 |
else |
| 960 |
{ |
| 961 |
$log .= "File '$appname' doesn't exist.\n"; |
| 962 |
} |
| 963 |
} |
| 964 |
else |
| 965 |
{ |
| 966 |
$log .= "Try manually running:\n\"$appname\" $appargs\n"; |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
if (open LOGFILE, ">>$trans") |
| 971 |
{ |
| 972 |
print LOGFILE "\n\n*** Unable to execute: '\"$appname\" $appargs' ***\n\n"; |
| 973 |
print LOGFILE "Failed with error code $errno.\n\n"; |
| 974 |
|
| 975 |
if ($log) |
| 976 |
{ |
| 977 |
print LOGFILE "Status report:\n\n"; |
| 978 |
print LOGFILE "$log", "\n"; |
| 979 |
} |
| 980 |
|
| 981 |
print LOGFILE "Warnings:\n\n",$warnings, "\n" if $warnings; |
| 982 |
close LOGFILE; |
| 983 |
} |
| 984 |
else |
| 985 |
{ |
| 986 |
warn "Unable to open '$trans' $!\n"; |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
my $accepted = 1; |
| 991 |
my $rejected = 0; |
| 992 |
|
| 993 |
if ($log=~/\((\d+) entries accepted, (\d+) rejected\)/) |
| 994 |
{ |
| 995 |
$accepted = $1; |
| 996 |
$rejected = $2; |
| 997 |
} |
| 998 |
|
| 999 |
if ($accepted == 0 or $rejected > 0 |
| 1000 |
or ( ($log=~/(\d+) warnings?/ and $1 gt 0)) |
| 1001 |
or $log=~/not found/) |
| 1002 |
{ |
| 1003 |
# Attempt to diagnose what's gone wrong |
| 1004 |
|
| 1005 |
if (open TRANS, $trans) |
| 1006 |
{ |
| 1007 |
while (<TRANS>) |
| 1008 |
{ |
| 1009 |
if (/Index style file .* not found/) |
| 1010 |
{ |
| 1011 |
$errno = $istnotfound; |
| 1012 |
last; |
| 1013 |
} |
| 1014 |
elsif (/Unknown specifier ;/) |
| 1015 |
{ |
| 1016 |
$errno = $xdynotist; |
| 1017 |
last; |
| 1018 |
} |
| 1019 |
elsif (/## Warning \(.*\):\s*$/ or /^!! Input index error/) |
| 1020 |
{ |
| 1021 |
# v4.50: added check for Input index error |
| 1022 |
$warnings .= $_ . <TRANS>; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
|
| 1026 |
close TRANS; |
| 1027 |
} |
| 1028 |
|
| 1029 |
} |
| 1030 |
|
| 1031 |
return ($status, $warnings, $errno); |
| 1032 |
} |
| 1033 |
|
| 1034 |
# v2.08 added $app parameter |
| 1035 |
sub makeindex{ |
| 1036 |
my($in,$out,$trans,$ist,$rest,$quiet,$dontexec,$app,$repairencaps) = @_; |
| 1037 |
|
| 1038 |
my $args = "$rest -s \"$ist\" -t \"$trans\" -o \"$out\" \"$in\""; |
| 1039 |
|
| 1040 |
# v2.01 replaced code with call to &run_app |
| 1041 |
|
| 1042 |
my ($status, $warnings, $errno) |
| 1043 |
= &run_app($app, $args, $trans, $quiet, $dontexec); |
| 1044 |
|
| 1045 |
return if ($dontexec); |
| 1046 |
|
| 1047 |
if ($errno) |
| 1048 |
{ |
| 1049 |
my $diagnostic = ''; |
| 1050 |
|
| 1051 |
if ($makeindex_error_text{$errno}) |
| 1052 |
{ |
| 1053 |
$diagnostic = $makeindex_error_text{$errno}; |
| 1054 |
} |
| 1055 |
else |
| 1056 |
{ |
| 1057 |
$diagnostic = "Can't find diagnostic message for error code $errno"; |
| 1058 |
} |
| 1059 |
|
| 1060 |
if (open LOGFILE, ">>$trans") |
| 1061 |
{ |
| 1062 |
print LOGFILE "\nmakeglossaries diagnostic messages:\n$diagnostic\n"; |
| 1063 |
close LOGFILE; |
| 1064 |
} |
| 1065 |
|
| 1066 |
die "\n***Call to makeindex failed***\n", |
| 1067 |
($diagnostic ? |
| 1068 |
"\nPossible cause of problem:\n\n". $diagnostic . "\n\n": |
| 1069 |
"\n" |
| 1070 |
), |
| 1071 |
"Exit status: $errno. Check '$trans' for details\n"; |
| 1072 |
} |
| 1073 |
|
| 1074 |
# 2.18: added check and repair for multiple encaps |
| 1075 |
if ($warnings) |
| 1076 |
{ |
| 1077 |
warn $warnings unless $quiet; |
| 1078 |
|
| 1079 |
my $multiencaps = $repairencaps and ($warnings=~/multiple encaps/); |
| 1080 |
|
| 1081 |
# 4.50: added check for illegal page and cs in page |
| 1082 |
|
| 1083 |
my $illegalpage = ($warnings=~/Illegal [A-Za-z]+ (number|digit)/); |
| 1084 |
|
| 1085 |
# 'Illegal space within numerals in second argument' |
| 1086 |
# and 'No closing delimiter for second argument' most likely |
| 1087 |
# mean that a command has ended up in the location |
| 1088 |
|
| 1089 |
my $csinlocation = ($warnings=~/(Illegal space|No closing delimiter).* second argument/); |
| 1090 |
|
| 1091 |
# 4.50: added check for illegal page number |
| 1092 |
if ($multiencaps or $illegalpage or $csinlocation) |
| 1093 |
{ |
| 1094 |
unless ($quiet) |
| 1095 |
{ |
| 1096 |
my $msg = ''; |
| 1097 |
|
| 1098 |
if ($multiencaps) |
| 1099 |
{ |
| 1100 |
$msg = "multiple encaps"; |
| 1101 |
} |
| 1102 |
|
| 1103 |
if ($illegalpage) |
| 1104 |
{ |
| 1105 |
if ($msg) |
| 1106 |
{ |
| 1107 |
$msg .= ', '; |
| 1108 |
} |
| 1109 |
|
| 1110 |
$msg .= "illegal page number"; |
| 1111 |
} |
| 1112 |
|
| 1113 |
if ($csinlocation) |
| 1114 |
{ |
| 1115 |
if ($msg) |
| 1116 |
{ |
| 1117 |
$msg .= ', '; |
| 1118 |
} |
| 1119 |
|
| 1120 |
$msg .= "potential LaTeX commands in location"; |
| 1121 |
} |
| 1122 |
|
| 1123 |
print "Encap/location issue: $msg detected. Attempting to remedy.\n"; |
| 1124 |
|
| 1125 |
print "Reading $in...\n"; |
| 1126 |
} |
| 1127 |
|
| 1128 |
my $page_invalid_regex = '[^a-zA-Z0-9\.]'; |
| 1129 |
my $pagecomp = '.'; |
| 1130 |
my $regexpagecomp = '\.'; |
| 1131 |
|
| 1132 |
if ($illegalpage) |
| 1133 |
{ |
| 1134 |
# get the page compositor from the .ist file |
| 1135 |
if (open INFD, $ist) |
| 1136 |
{ |
| 1137 |
while (<INFD>) |
| 1138 |
{ |
| 1139 |
if (/page_compositor "(.)"/) |
| 1140 |
{ |
| 1141 |
$pagecomp = $1; |
| 1142 |
last; |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
close INFD; |
| 1147 |
} |
| 1148 |
else |
| 1149 |
{ |
| 1150 |
warn "Can't open '$ist' $!\n"; |
| 1151 |
} |
| 1152 |
|
| 1153 |
if ($pagecomp eq '.' or $pagecomp eq '-' |
| 1154 |
or $pagecomp eq '\\'or $pagecomp eq ']') |
| 1155 |
{ |
| 1156 |
$regexpagecomp = "\\$pagecomp"; |
| 1157 |
} |
| 1158 |
else |
| 1159 |
{ |
| 1160 |
$regexpagecomp = $pagecomp; |
| 1161 |
} |
| 1162 |
|
| 1163 |
if ($pagecomp ne '.') |
| 1164 |
{ |
| 1165 |
$page_invalid_regex = "[^a-zA-Z0-9$regexpagecomp]"; |
| 1166 |
} |
| 1167 |
} |
| 1168 |
|
| 1169 |
# if $in can't be opened at this point something wrong |
| 1170 |
# has occurred (otherwise how did makeindex manage to open |
| 1171 |
# it?) |
| 1172 |
|
| 1173 |
open INFD, $in or die "Can't open '$in' $!\n"; |
| 1174 |
|
| 1175 |
my @entries = (); |
| 1176 |
|
| 1177 |
while (<INFD>) |
| 1178 |
{ |
| 1179 |
# The encap usually starts with setentrycounter but may have |
| 1180 |
# ( or ) to indicate the start or end of a range. |
| 1181 |
# The encap will be glsseeformat for cross-references. |
| 1182 |
# \glossentry and \subglossentry may be preceded by |
| 1183 |
# \glsnonextpages or \glsnextpages |
| 1184 |
|
| 1185 |
if (/\\glossaryentry\{(.*(?:\\glossentry|\\subglossentry\{\d+\}))\{([^\|]*)\}\|([^\|]*)\}\{(.*)\}$/) |
| 1186 |
{ |
| 1187 |
my %entry = |
| 1188 |
( |
| 1189 |
'entry' => "$1\{$2\}", |
| 1190 |
'label' => $2, |
| 1191 |
'encap' => $3, |
| 1192 |
'location' => $4, |
| 1193 |
'counter'=>'', |
| 1194 |
'prefix'=>'' |
| 1195 |
); |
| 1196 |
|
| 1197 |
# Find the page counter (not available with |
| 1198 |
# cross-references) |
| 1199 |
if ($entry{'encap'}=~/setentrycounter\[(.*)\]\{([a-zA-Z0-9]+)\}"\\/) |
| 1200 |
{ |
| 1201 |
$entry{'prefix'} = $1; |
| 1202 |
$entry{'counter'} = $2; |
| 1203 |
} |
| 1204 |
|
| 1205 |
# First move any commands out of the location. |
| 1206 |
if ($csinlocation) |
| 1207 |
{ |
| 1208 |
my $loc = $entry{'location'}; |
| 1209 |
my $encap = $entry{'encap'}; |
| 1210 |
|
| 1211 |
# This is only designed for locations in the form |
| 1212 |
# \cs{num} but allow for \protect\cs |
| 1213 |
if ($loc=~m/^(?:\\protect *)?\\([A-Za-z\@]+) *\{(.*)\}$/) |
| 1214 |
{ |
| 1215 |
my $cs = $1; |
| 1216 |
$loc = $2; |
| 1217 |
|
| 1218 |
# Normal glossary indexing will have the encap |
| 1219 |
# start with setentrycounter[prefix]{counter} |
| 1220 |
# This won't match a cross-reference (see) but |
| 1221 |
# that has its location always set to Z. |
| 1222 |
|
| 1223 |
if ($encap=~/^(setentrycounter\[.*\]\{.*\}"\\)(.*)$/) |
| 1224 |
{ |
| 1225 |
$entry{'encap'} = "$1glslocationcstoencap\{$2\}\{$cs\}"; |
| 1226 |
|
| 1227 |
unless ($quiet) |
| 1228 |
{ |
| 1229 |
print "Invalid location '$entry{location}' detected for entry '$entry{label}'. Replaced with '$loc'\n"; |
| 1230 |
} |
| 1231 |
} |
| 1232 |
elsif (not $quiet) |
| 1233 |
{ |
| 1234 |
warn "Invalid location '$entry{location}' detected for entry '$entry{label}' has unexpected encap '$encap'. Location replaced with '$loc'\n"; |
| 1235 |
} |
| 1236 |
|
| 1237 |
$entry{'location'} = $loc; |
| 1238 |
} |
| 1239 |
} |
| 1240 |
|
| 1241 |
if ($illegalpage) |
| 1242 |
{ |
| 1243 |
my $loc = $entry{'location'}; |
| 1244 |
|
| 1245 |
if ($loc=~s/($page_invalid_regex)+/$pagecomp/g) |
| 1246 |
{ |
| 1247 |
unless ($quiet) |
| 1248 |
{ |
| 1249 |
print "Invalid location '$entry{location}' detected for entry '$entry{label}'. Replaced with '$loc'\n"; |
| 1250 |
} |
| 1251 |
|
| 1252 |
} |
| 1253 |
|
| 1254 |
if ($loc=~s/^($regexpagecomp)+//) |
| 1255 |
{ |
| 1256 |
unless ($quiet) |
| 1257 |
{ |
| 1258 |
print "Invalid location '$entry{location}' (starts with page compositor) detected for entry '$entry{label}'. Replaced with '$loc'\n"; |
| 1259 |
} |
| 1260 |
} |
| 1261 |
|
| 1262 |
if ($loc=~s/($regexpagecomp)+$//) |
| 1263 |
{ |
| 1264 |
unless ($quiet) |
| 1265 |
{ |
| 1266 |
print "Invalid location '$entry{location}' (ends with page compositor) detected for entry '$entry{label}'. Replaced with '$loc'\n"; |
| 1267 |
} |
| 1268 |
} |
| 1269 |
|
| 1270 |
if ($loc eq '') |
| 1271 |
{ |
| 1272 |
unless ($quiet) |
| 1273 |
{ |
| 1274 |
print "Invalid empty location detected for entry '$entry{label}'. Replaced with 0 (encap: glsignore).\n"; |
| 1275 |
} |
| 1276 |
|
| 1277 |
$loc = '0'; |
| 1278 |
$entry{'encap'} = 'glsignore'; |
| 1279 |
} |
| 1280 |
|
| 1281 |
$entry{'location'} = $loc; |
| 1282 |
} |
| 1283 |
|
| 1284 |
my $add = 1; |
| 1285 |
|
| 1286 |
if ($multiencaps) |
| 1287 |
{ |
| 1288 |
for (my $idx = 0; $idx <= $#entries; $idx++) |
| 1289 |
{ |
| 1290 |
my $existing = $entries[$idx]; |
| 1291 |
|
| 1292 |
#v4.50: added check for prefix and counter |
| 1293 |
# Since the encap includes the prefix and |
| 1294 |
# counter information, the same location and |
| 1295 |
# format for different counters or prefixes |
| 1296 |
# will be considered an encap clash by |
| 1297 |
# makeindex, but shouldn't be merged. |
| 1298 |
|
| 1299 |
if ($entry{'entry'} eq $existing->{'entry'} |
| 1300 |
and $entry{'location'} eq $existing->{'location'} |
| 1301 |
and $entry{'prefix'} eq $existing->{'prefix'} |
| 1302 |
and $entry{'counter'} eq $existing->{'counter'} |
| 1303 |
and $entry{'encap'} ne $existing->{'encap'}) |
| 1304 |
{ |
| 1305 |
unless ($quiet) |
| 1306 |
{ |
| 1307 |
if ($entry{'counter'} eq '' and $entry{'location'} eq 'Z') |
| 1308 |
{ |
| 1309 |
print "Encap clash for entry '$entry{label}' possibly caused by multiple cross-reference instances\n"; |
| 1310 |
} |
| 1311 |
else |
| 1312 |
{ |
| 1313 |
print "Encap clash detected for entry '$entry{label}', counter: '$entry{counter}', location: '$entry{location}'. Encap '$entry{encap}' clashes with '$existing->{'encap'}'\n"; |
| 1314 |
} |
| 1315 |
} |
| 1316 |
|
| 1317 |
$add = 0 if ($add == 1); |
| 1318 |
|
| 1319 |
# Range encaps should take precedence. |
| 1320 |
|
| 1321 |
if ($entry{'encap'}=~/^[\(\)]/) |
| 1322 |
{ |
| 1323 |
$add = 2; |
| 1324 |
|
| 1325 |
if ($existing->{'encap'}=~/^[\(\)]/) |
| 1326 |
{ |
| 1327 |
# too complicated, keep both |
| 1328 |
|
| 1329 |
last; |
| 1330 |
} |
| 1331 |
else |
| 1332 |
{ |
| 1333 |
# remove existing |
| 1334 |
|
| 1335 |
splice @entries, $idx, 1; |
| 1336 |
|
| 1337 |
$idx--; |
| 1338 |
} |
| 1339 |
} |
| 1340 |
elsif ($existing->{'encap'}=~/^[\(\)]/) |
| 1341 |
{ |
| 1342 |
if ($entry{'encap'}=~/^[\(\)]/) |
| 1343 |
{ |
| 1344 |
# too complicated, keep both |
| 1345 |
|
| 1346 |
$add = 1; |
| 1347 |
last; |
| 1348 |
} |
| 1349 |
# (otherwise drop new entry) |
| 1350 |
} |
| 1351 |
elsif (&encap_overrides($entry{'encap'}, |
| 1352 |
$existing->{'encap'})) |
| 1353 |
{ |
| 1354 |
$entries[$idx] = \%entry; |
| 1355 |
} |
| 1356 |
} |
| 1357 |
} |
| 1358 |
} |
| 1359 |
|
| 1360 |
push @entries, \%entry if $add > 0; |
| 1361 |
} |
| 1362 |
else |
| 1363 |
{ |
| 1364 |
warn "Abandoning attempt. Can't parse: $_" unless $quiet; |
| 1365 |
|
| 1366 |
close INFD; |
| 1367 |
return; |
| 1368 |
} |
| 1369 |
} |
| 1370 |
|
| 1371 |
close INFD; |
| 1372 |
|
| 1373 |
if (open OUTFD, ">$in") |
| 1374 |
{ |
| 1375 |
print "Writing $in...\n" unless $quiet; |
| 1376 |
|
| 1377 |
foreach my $entry (@entries) |
| 1378 |
{ |
| 1379 |
print OUTFD '\\glossaryentry{', |
| 1380 |
$entry->{'entry'}, '|', |
| 1381 |
$entry->{'encap'}, '}{', |
| 1382 |
$entry->{'location'}, '}', "\n"; |
| 1383 |
} |
| 1384 |
|
| 1385 |
close OUTFD; |
| 1386 |
|
| 1387 |
print "Retrying\n" unless $quiet; |
| 1388 |
|
| 1389 |
&makeindex($in,$out,$trans,$ist,$rest,$quiet,$dontexec,$app,0); |
| 1390 |
} |
| 1391 |
else |
| 1392 |
{ |
| 1393 |
warn "Can't open '$in' $!\n" unless $quiet; |
| 1394 |
} |
| 1395 |
} |
| 1396 |
} |
| 1397 |
} |
| 1398 |
|
| 1399 |
# 2.18 new |
| 1400 |
# This is a subroutine in case of possible extension. |
| 1401 |
# For example, what happens in the event of 'textbf' and 'emph'? |
| 1402 |
# Should one override the other or be combined? Combining is harder |
| 1403 |
# as it would need a corresponding LaTeX command. (bib2gls deals |
| 1404 |
# with this better through its --map-formats switcn.) |
| 1405 |
# 2.21 check for range encap moved earlier |
| 1406 |
# 4.50 add check for glsignore |
| 1407 |
|
| 1408 |
sub encap_overrides{ |
| 1409 |
my ($newencap, $existing) = @_; |
| 1410 |
|
| 1411 |
if ($newencap=~/\\glsignore\s*$/) |
| 1412 |
{ |
| 1413 |
return 0; |
| 1414 |
} |
| 1415 |
elsif ($existing=~/\\glsignore\s*$/) |
| 1416 |
{ |
| 1417 |
return 1; |
| 1418 |
} |
| 1419 |
|
| 1420 |
($existing=~/\\glsnumberformat\s*$/ or $newencap!~/\\glsnumberformat\s*$/ ) |
| 1421 |
} |
| 1422 |
|
| 1423 |
# v2.08 added $app parameter |
| 1424 |
sub xindy{ |
| 1425 |
my($in,$out,$trans,$ist,$language,$codepage,$rest,$quiet, |
| 1426 |
$dontexec, $app) = @_; |
| 1427 |
my($args, $langparam, $main, $retry); |
| 1428 |
my($module); |
| 1429 |
|
| 1430 |
$module = $ist; |
| 1431 |
$module=~s/\.xdy\Z//; |
| 1432 |
|
| 1433 |
if ($language) |
| 1434 |
{ |
| 1435 |
# map babel names to xindy names |
| 1436 |
|
| 1437 |
$language = $languagemap{$language} if ($languagemap{$language}); |
| 1438 |
|
| 1439 |
$langparam = "-L $language"; |
| 1440 |
} |
| 1441 |
else |
| 1442 |
{ |
| 1443 |
$langparam = ""; |
| 1444 |
# v2.10 initialise $language to suppress warnings |
| 1445 |
$language = ""; |
| 1446 |
} |
| 1447 |
|
| 1448 |
# most languages work with xindy's default codepage, but |
| 1449 |
# some don't, so if the codepage isn't specified, check |
| 1450 |
# the known cases that will generate an error |
| 1451 |
# and supply a default. (For all other cases, it's up to the |
| 1452 |
# user to supply a codepage.) |
| 1453 |
# |
| 1454 |
# Now that glossaries.sty v4.50 will default to 'utf8' if |
| 1455 |
# \inputencodingname hasn't been defined or is empty, this also |
| 1456 |
# needs to check 'utf8'. |
| 1457 |
|
| 1458 |
# v2.01 changed 'if ($codepage eq "")' to 'unless ($codepage)' |
| 1459 |
# v4.50 changed to conditional to include encoding without modifiers |
| 1460 |
|
| 1461 |
if ($codepage eq '' or $codepage=~/^utf8|latin\d+|cp\d+$/) |
| 1462 |
{ |
| 1463 |
if ($language eq 'dutch') |
| 1464 |
{ |
| 1465 |
if ($codepage eq '') |
| 1466 |
{ |
| 1467 |
$codepage = "ij-as-ij"; |
| 1468 |
} |
| 1469 |
else |
| 1470 |
{ |
| 1471 |
$codepage = "ij-as-ij-$codepage"; |
| 1472 |
} |
| 1473 |
} |
| 1474 |
elsif ($language eq 'german') |
| 1475 |
{ |
| 1476 |
if ($codepage eq '') |
| 1477 |
{ |
| 1478 |
$codepage = "din5007"; |
| 1479 |
} |
| 1480 |
else |
| 1481 |
{ |
| 1482 |
$codepage = "din5007-$codepage"; |
| 1483 |
} |
| 1484 |
} |
| 1485 |
elsif ($language eq 'gypsy') |
| 1486 |
{ |
| 1487 |
if ($codepage eq '') |
| 1488 |
{ |
| 1489 |
$codepage = "northrussian"; |
| 1490 |
} |
| 1491 |
else |
| 1492 |
{ |
| 1493 |
$codepage = "northrussian-$codepage"; |
| 1494 |
} |
| 1495 |
} |
| 1496 |
elsif ($language eq 'hausa' and $codepage eq '') |
| 1497 |
{ |
| 1498 |
$codepage = "utf8"; |
| 1499 |
} |
| 1500 |
elsif ($language eq 'klingon' and $codepage eq '') |
| 1501 |
{ |
| 1502 |
$codepage = "utf8"; |
| 1503 |
} |
| 1504 |
elsif ($language eq 'latin' and $codepage eq '') |
| 1505 |
{ |
| 1506 |
$codepage = "utf8"; |
| 1507 |
} |
| 1508 |
elsif ($language eq 'mongolian') |
| 1509 |
{ |
| 1510 |
if ($codepage eq '') |
| 1511 |
{ |
| 1512 |
$codepage = "cyrillic"; |
| 1513 |
} |
| 1514 |
else |
| 1515 |
{ |
| 1516 |
$codepage = "cyrillic-$codepage"; |
| 1517 |
} |
| 1518 |
} |
| 1519 |
elsif ($language eq 'slovak') |
| 1520 |
{ |
| 1521 |
if ($codepage eq '') |
| 1522 |
{ |
| 1523 |
$codepage = "small"; |
| 1524 |
} |
| 1525 |
else |
| 1526 |
{ |
| 1527 |
$codepage = "small-$codepage"; |
| 1528 |
} |
| 1529 |
} |
| 1530 |
elsif ($language eq 'spanish') |
| 1531 |
{ |
| 1532 |
if ($codepage eq '') |
| 1533 |
{ |
| 1534 |
$codepage = "modern"; |
| 1535 |
} |
| 1536 |
else |
| 1537 |
{ |
| 1538 |
$codepage = "modern-$codepage"; |
| 1539 |
} |
| 1540 |
} |
| 1541 |
elsif ($language eq 'vietnamese') |
| 1542 |
{ |
| 1543 |
if ($codepage eq '') |
| 1544 |
{ |
| 1545 |
$codepage = "utf8"; |
| 1546 |
} |
| 1547 |
else |
| 1548 |
{ |
| 1549 |
$codepage = "utf8-$codepage"; |
| 1550 |
} |
| 1551 |
} |
| 1552 |
} |
| 1553 |
elsif ($language eq 'german' and $codepage!~/(din5007|duden|braille)/) |
| 1554 |
{ |
| 1555 |
#v2.16 added check for german din/duden |
| 1556 |
#v4.50 now redundant? may be removed in the next version |
| 1557 |
|
| 1558 |
$codepage = "din5007-$codepage"; |
| 1559 |
} |
| 1560 |
|
| 1561 |
|
| 1562 |
my $codepageparam = ""; |
| 1563 |
|
| 1564 |
if ($codepage) |
| 1565 |
{ |
| 1566 |
$codepageparam = "-C $codepage"; |
| 1567 |
} |
| 1568 |
|
| 1569 |
$main = join(' ', |
| 1570 |
"-I xindy", |
| 1571 |
"-M \"$module\"", |
| 1572 |
"-t \"$trans\"", |
| 1573 |
"-o \"$out\"", |
| 1574 |
"\"$in\""); |
| 1575 |
|
| 1576 |
$args = join(' ', $rest, $langparam, $codepageparam, $main); |
| 1577 |
|
| 1578 |
# v2.01 replaced code with call to &run_app |
| 1579 |
|
| 1580 |
my ($status, $warnings, $errno) |
| 1581 |
= &run_app($app, $args, $trans, $quiet, $dontexec); |
| 1582 |
|
| 1583 |
return if ($dontexec); |
| 1584 |
|
| 1585 |
if ($status=~/Cannot locate xindy module for language ([^\s]+) in codepage ([^\s]+)/) |
| 1586 |
{ |
| 1587 |
$args = join(' ', $rest, $langparam, $main); |
| 1588 |
|
| 1589 |
unless ($quiet) |
| 1590 |
{ |
| 1591 |
my $message = "$&\nRetrying using default codepage.\n"; |
| 1592 |
|
| 1593 |
warn $message; |
| 1594 |
|
| 1595 |
$retry .= $message; |
| 1596 |
} |
| 1597 |
|
| 1598 |
($status, $warnings, $errno) |
| 1599 |
= &run_app('xindy', $args, $trans, $quiet, $dontexec); |
| 1600 |
|
| 1601 |
} |
| 1602 |
|
| 1603 |
if ($status=~/Cannot locate xindy module for language ([^\s]+)/ |
| 1604 |
and $1 ne 'general') |
| 1605 |
{ |
| 1606 |
$args = join(' ', $rest, "-L general", $main); |
| 1607 |
|
| 1608 |
unless ($quiet) |
| 1609 |
{ |
| 1610 |
my $message = "$&\nRetrying with -L general\n"; |
| 1611 |
|
| 1612 |
warn $message; |
| 1613 |
$retry .= $message; |
| 1614 |
} |
| 1615 |
|
| 1616 |
($status, $warnings, $errno) |
| 1617 |
= &run_app('xindy', $args, $trans, $quiet, $dontexec); |
| 1618 |
|
| 1619 |
} |
| 1620 |
|
| 1621 |
if ($errno) |
| 1622 |
{ |
| 1623 |
# attempt further diagnostic |
| 1624 |
|
| 1625 |
my $diagnostic = ''; |
| 1626 |
|
| 1627 |
if ($status=~/index 0 should be less than the length of the string/m) |
| 1628 |
{ |
| 1629 |
$diagnostic = $xindy_error_text{nosort}; |
| 1630 |
|
| 1631 |
$diagnostic .= &parse_for_xindy_nosort($in); |
| 1632 |
} |
| 1633 |
elsif ($status=~/variable .+ has no value/m) |
| 1634 |
{ |
| 1635 |
# v2.19 fixed misspelt key |
| 1636 |
$diagnostic = $xindy_error_text{istnotxdy}; |
| 1637 |
} |
| 1638 |
elsif ($status=~/Could not find file /m) |
| 1639 |
{ |
| 1640 |
# v2.19 added |
| 1641 |
$diagnostic = $xindy_error_text{noxdyfile}; |
| 1642 |
} |
| 1643 |
elsif ($status=~/Possible read-error due to ill-formed string " :sep/m) |
| 1644 |
{ |
| 1645 |
$diagnostic = $xindy_error_text{missingendquote}; |
| 1646 |
} |
| 1647 |
elsif (not $language) |
| 1648 |
{ |
| 1649 |
# If the language hasn't been set, then it may be |
| 1650 |
# because the document doesn't contain |
| 1651 |
# \printglossaries/\printglossary or it may be |
| 1652 |
# because the user has a customized style file that |
| 1653 |
# contains the language settings. |
| 1654 |
|
| 1655 |
$diagnostic = $xindy_error_text{nolanguage}; |
| 1656 |
|
| 1657 |
if ($in eq 'glo') |
| 1658 |
{ |
| 1659 |
# or it may be that the user doesn't want to use the main |
| 1660 |
# glossary and has forgotten to suppress it with the |
| 1661 |
# "nomain" package option |
| 1662 |
|
| 1663 |
$diagnostic .= $xindy_error_text{nomain}; |
| 1664 |
} |
| 1665 |
} |
| 1666 |
|
| 1667 |
# v2.19 added: |
| 1668 |
if ($diagnostic and open LOGFILE, ">>$trans") |
| 1669 |
{ |
| 1670 |
print LOGFILE "\nmakeglossaries diagnostic messages:\n\n$diagnostic\n"; |
| 1671 |
close LOGFILE; |
| 1672 |
} |
| 1673 |
|
| 1674 |
die "\n***Call to xindy failed***\n", |
| 1675 |
($diagnostic ? |
| 1676 |
"\nPossible cause of problem:\n\n". $diagnostic . "\n\n": |
| 1677 |
"\n"), |
| 1678 |
"Check '$trans' for details\n"; |
| 1679 |
} |
| 1680 |
|
| 1681 |
# Check xindy warnings |
| 1682 |
|
| 1683 |
if ($status=~/^WARNING:/m) |
| 1684 |
{ |
| 1685 |
my $diagwarn = ''; |
| 1686 |
|
| 1687 |
if ($status=~/did not match any location-class/m) |
| 1688 |
{ |
| 1689 |
$diagwarn = $xindy_error_text{badlocation}; |
| 1690 |
} |
| 1691 |
|
| 1692 |
if ($status=~/unknown attribute `pageglsnumberformat'/m) |
| 1693 |
{ |
| 1694 |
$diagwarn .= $xindy_error_text{comp207}; |
| 1695 |
} |
| 1696 |
|
| 1697 |
if ($status=~/Would replace complete index key by empty string, ignoring/m) |
| 1698 |
{ |
| 1699 |
$diagwarn .= $xindy_error_text{nosort}; |
| 1700 |
$diagwarn .= &parse_for_xindy_nosort($in); |
| 1701 |
} |
| 1702 |
|
| 1703 |
if ($diagwarn) |
| 1704 |
{ |
| 1705 |
warn "\n**Warning:**\n\n", $diagwarn, "\n"; |
| 1706 |
|
| 1707 |
$warnings .= "\nmakeglossaries diagnostic messages:\n\n" |
| 1708 |
. $diagwarn; |
| 1709 |
} |
| 1710 |
} |
| 1711 |
|
| 1712 |
if ($retry or $warnings) |
| 1713 |
{ |
| 1714 |
if (open LOGFILE, ">>$trans") |
| 1715 |
{ |
| 1716 |
print LOGFILE "\n$warnings"; |
| 1717 |
|
| 1718 |
if ($retry) |
| 1719 |
{ |
| 1720 |
print LOGFILE "\nmakeglossaries messages:\n\n", $retry; |
| 1721 |
} |
| 1722 |
|
| 1723 |
close LOGFILE; |
| 1724 |
} |
| 1725 |
else |
| 1726 |
{ |
| 1727 |
warn "Unable to open '$trans' $!\n"; |
| 1728 |
} |
| 1729 |
} |
| 1730 |
} |
| 1731 |
|
| 1732 |
# v2.18 added: |
| 1733 |
sub parse_for_xindy_nosort{ |
| 1734 |
my ($in) = @_; |
| 1735 |
|
| 1736 |
my $msg = join("\n", "", |
| 1737 |
"Attempting to determine which entries have problem sort keys.", |
| 1738 |
"Parsing '$in'"); |
| 1739 |
|
| 1740 |
my %entries = (); |
| 1741 |
|
| 1742 |
if (open FD, $in) |
| 1743 |
{ |
| 1744 |
while (<FD>) |
| 1745 |
{ |
| 1746 |
# v2.19 extra conditions added |
| 1747 |
if (/:tkey \(\("((?:\\\\[a-zA-Z@]+ *)+)" "\\\\glossentry\{(.*)\}"\) \)/) |
| 1748 |
{ |
| 1749 |
my $label = $2; |
| 1750 |
|
| 1751 |
unless ($entries{$label}) |
| 1752 |
{ |
| 1753 |
$entries{$label}->{sort} = $label; |
| 1754 |
$entries{$label}->{suggestion} = $label; |
| 1755 |
$entries{$label}->{suggestion}=~s/([\\\s]+)//g; |
| 1756 |
|
| 1757 |
} |
| 1758 |
} |
| 1759 |
elsif (/:tkey \(\("(\\\\[a-zA-Z@]+ *{(?:\\\\[a-zA-Z@]+ *)+})+" "\\\\glossentry\{(.*)\}"\) \)/) |
| 1760 |
{ |
| 1761 |
# name in the form \cs{\cs} |
| 1762 |
my $label = $2; |
| 1763 |
|
| 1764 |
unless ($entries{$label}) |
| 1765 |
{ |
| 1766 |
$entries{$label}->{sort} = $1; |
| 1767 |
$entries{$label}->{suggestion} = $label; |
| 1768 |
$entries{$label}->{suggestion}=~s/^[a-zA-Z]+[:\-\.]//; |
| 1769 |
$entries{$label}->{suggestion}=~s/([^\w]+)//g; |
| 1770 |
} |
| 1771 |
} |
| 1772 |
elsif (/:tkey \(\("(\$\s*(?:\{?\\\\[a-zA-Z@]+ *\}?)+\$)" "\\\\glossentry\{(.*)\}"\) \)/) |
| 1773 |
{ |
| 1774 |
# name in the form $\cs$ |
| 1775 |
my $label = $2; |
| 1776 |
|
| 1777 |
unless ($entries{$label}) |
| 1778 |
{ |
| 1779 |
$entries{$label}->{sort} = $1; |
| 1780 |
$entries{$label}->{suggestion} = $label; |
| 1781 |
$entries{$label}->{suggestion}=~s/^[a-zA-Z]+[:\-\.]//; |
| 1782 |
$entries{$label}->{suggestion}=~s/([^\w]+)//g; |
| 1783 |
} |
| 1784 |
} |
| 1785 |
} |
| 1786 |
|
| 1787 |
close FD; |
| 1788 |
|
| 1789 |
my @labels = keys %entries; |
| 1790 |
|
| 1791 |
my $n = $#labels+1; |
| 1792 |
|
| 1793 |
if ($n == 0) |
| 1794 |
{ |
| 1795 |
$msg .= "\nCouldn't find anything! Sorry, I'm stumped."; |
| 1796 |
} |
| 1797 |
else |
| 1798 |
{ |
| 1799 |
$msg .= ($n == 1 ? "\n1 problematic entry found:\n" |
| 1800 |
: "\n$n problematic entries found:\n"); |
| 1801 |
|
| 1802 |
foreach my $label (@labels) |
| 1803 |
{ |
| 1804 |
my $thisentry = $entries{$label}; |
| 1805 |
|
| 1806 |
$msg .= "\nLabel: '$label'. Sort value : '$thisentry->{sort}'"; |
| 1807 |
$msg .= "\n(Try adding sort={$thisentry->{suggestion}} to the definition.)"; |
| 1808 |
} |
| 1809 |
} |
| 1810 |
} |
| 1811 |
else |
| 1812 |
{ |
| 1813 |
$msg .= "\nFailed to open '$in' $!\n"; |
| 1814 |
} |
| 1815 |
|
| 1816 |
$msg; |
| 1817 |
} |
| 1818 |
|
| 1819 |
sub HELP_MESSAGE{ |
| 1820 |
print "\nSyntax : makeglossaries [options] <filename>\n\n"; |
| 1821 |
print "For use with the glossaries package to pass relevant\n"; |
| 1822 |
print "files to makeindex or xindy.\n\n"; |
| 1823 |
print "<filename>\tBase name of glossary file(s). This should\n"; |
| 1824 |
print "\t\tbe the name of your main LaTeX document without any\n"; |
| 1825 |
print "\t\textension.\n"; |
| 1826 |
print "\nGeneral Options:\n\n"; |
| 1827 |
print "-o <gls>\tUse <gls> as the output file.\n"; |
| 1828 |
print "\t\t(Don't use -o if you have more than one glossary.)\n"; |
| 1829 |
print "-q\t\tQuiet mode.\n"; |
| 1830 |
print "-Q\t\tSilence unable to fork warning.\n"; |
| 1831 |
print "-k\t\tDon't try to use piped redirection.\n"; |
| 1832 |
print "-l\t\tLetter ordering.\n"; |
| 1833 |
print "-s <sty>\tEmploy <sty> as the style file.\n"; |
| 1834 |
print "-t <log>\tEmploy <log> as the transcript file.\n"; |
| 1835 |
print "\t\t(Don't use -t if you have more than one glossary\n"; |
| 1836 |
print "\t\tor the transcripts will be overwritten.)\n"; |
| 1837 |
print "-d <directory>\tDirectory in which the .aux, .glo etc files are located.\n", |
| 1838 |
"\t\t(Default is the directory in which <filename> resides.)\n"; |
| 1839 |
print "-n\t\tPrint the command that would normally be executed,\n", |
| 1840 |
"\t\tbut don't execute it.\n"; |
| 1841 |
|
| 1842 |
print "\nXindy Options:\n\n"; |
| 1843 |
print "-L <language>\tUse <language>.\n"; |
| 1844 |
print "-x <file>\tFull path to xindy executable.\n", |
| 1845 |
"\t\t(Default assumes xindy is on the operating system's path.)\n"; |
| 1846 |
|
| 1847 |
print "\nMakeindex Options:\n"; |
| 1848 |
print "(See makeindex documentation for further details on these "; |
| 1849 |
print "options.)\n\n"; |
| 1850 |
print "-c\t\tCompress intermediate blanks.\n"; |
| 1851 |
print "-e\t\tDon't attempt to fix multiple encaps.\n"; |
| 1852 |
print "-g\t\tEmploy German word ordering.\n"; |
| 1853 |
print "-p <num>\tSet the starting page number to be <num>.\n"; |
| 1854 |
print "-r\t\tDisable implicit page range formation.\n"; |
| 1855 |
print "-m <file>\tFull path to makeindex executable.\n", |
| 1856 |
"\t\t(Default assumes makeindex is on the operating system's path.)\n"; |
| 1857 |
} |
| 1858 |
|
| 1859 |
sub VERSION_MESSAGE{ |
| 1860 |
|
| 1861 |
my $verYear = ''; |
| 1862 |
|
| 1863 |
if ($version=~/(\d{4})-\d{2}-\d{2}/) |
| 1864 |
{ |
| 1865 |
$verYear = "-$1"; |
| 1866 |
} |
| 1867 |
|
| 1868 |
print "Makeglossaries Version $version\n"; |
| 1869 |
print "Copyright (C) 2007$verYear Nicola L C Talbot\n"; |
| 1870 |
print "This material is subject to the LaTeX Project Public License.\n"; |
| 1871 |
} |
| 1872 |
|
| 1873 |
1; |
| 1874 |
|
| 1875 |
=head1 NAME |
| 1876 |
|
| 1877 |
makeglossaries - Calls makeindex/xindy for LaTeX documents using glossaries package |
| 1878 |
|
| 1879 |
=head1 SYNOPSIS |
| 1880 |
|
| 1881 |
B<makeglossaries> [B<-o> I<file>] [B<-q>] [B<-Q>] [B<-k>] [B<-n>] |
| 1882 |
[B<-s> I<file>] [B<-t> I<file>] [B<-L> I<language>] [B<-c>] [B<-g>] [B<-l>] |
| 1883 |
[B<-p> I<num>] [B<-r>] [B<-d> I<aux dir>] [B<-m> I<file>] [B<-x> I<file>] |
| 1884 |
[B<-e>] [B<--version>] [B<--help>] I<filename> |
| 1885 |
|
| 1886 |
=head1 DESCRIPTION |
| 1887 |
|
| 1888 |
B<makeglossaries> is designed for use with LaTeX documents that |
| 1889 |
use the glossaries package. |
| 1890 |
|
| 1891 |
The mandatory argument I<filename> should be the name of the aux |
| 1892 |
file. The B<.aux> extension may be omitted but is best included where the |
| 1893 |
filename includes additional dots in its name to avoid ambiguity. |
| 1894 |
|
| 1895 |
Alternatively, the I<filename> may be the name of a |
| 1896 |
specific glossary file if only one glossary should be processed (for |
| 1897 |
example, when working on a draft document). In this case, the aux |
| 1898 |
file is still expected to exist and is inferred from the basename of |
| 1899 |
I<filename>. |
| 1900 |
|
| 1901 |
B<makeglossaries> will read the auxiliary file to determine whether |
| 1902 |
B<makeindex> or B<xindy> should be called. All the information |
| 1903 |
required to be passed to the relevant indexing application should |
| 1904 |
also be contained in the auxiliary file, but may be overridden by |
| 1905 |
the option arguments to B<makeglossaries>. |
| 1906 |
|
| 1907 |
|
| 1908 |
=head1 OPTIONS |
| 1909 |
|
| 1910 |
=over 4 |
| 1911 |
|
| 1912 |
=item B<-e> |
| 1913 |
|
| 1914 |
Don't attempt to repair multiple encaps or illegal page number (B<makeindex> only). |
| 1915 |
|
| 1916 |
=item B<-c> |
| 1917 |
|
| 1918 |
Compress intermediate blanks (B<makeindex> only). |
| 1919 |
|
| 1920 |
=item B<-d> I<aux dir> |
| 1921 |
|
| 1922 |
Specify the directory the .aux, .glo etc files are located. |
| 1923 |
Defaults to the parent directory of the base file I<filename>. |
| 1924 |
|
| 1925 |
=item B<-g> |
| 1926 |
|
| 1927 |
Employ German word ordering (B<makeindex> only). |
| 1928 |
|
| 1929 |
=item B<-k> |
| 1930 |
|
| 1931 |
Don't try forking with piped redirection. (Lessens the |
| 1932 |
effect of -q) |
| 1933 |
|
| 1934 |
=item B<-l> |
| 1935 |
|
| 1936 |
Letter ordering. |
| 1937 |
|
| 1938 |
=item B<-L> I<language> |
| 1939 |
|
| 1940 |
This option only has an effect if B<xindy> is called. Sets the |
| 1941 |
language. See B<xindy> documentation for further details. |
| 1942 |
|
| 1943 |
=item B<-m> I<file> |
| 1944 |
|
| 1945 |
Specify the full path name for B<makeindex> to I<file> in the |
| 1946 |
event that B<makeindex> isn't on the operating system's path. |
| 1947 |
|
| 1948 |
=item B<-n> |
| 1949 |
|
| 1950 |
Print the commands that would normally be executed but don't run them. |
| 1951 |
|
| 1952 |
=item B<-o> I<file> |
| 1953 |
|
| 1954 |
Use I<file> as the output file. (Only suitable for documents |
| 1955 |
containing a single glossary, otherwise each glossary will be |
| 1956 |
overridden.) |
| 1957 |
|
| 1958 |
=item B<-p> I<num> |
| 1959 |
|
| 1960 |
Sets the starting page number to be I<num> (B<makeindex> only). |
| 1961 |
|
| 1962 |
=item B<-q> |
| 1963 |
|
| 1964 |
Quiet mode. Reduces chatter to standard output. |
| 1965 |
|
| 1966 |
=item B<-Q> |
| 1967 |
|
| 1968 |
Silences warning about being unable to fork. |
| 1969 |
|
| 1970 |
=item B<-r> |
| 1971 |
|
| 1972 |
=item B<-s> I<file> |
| 1973 |
|
| 1974 |
Use I<file> as the style file. Note that if you use this option, |
| 1975 |
you need to know whether B<makeindex> or B<xindy> will be called, as |
| 1976 |
they have different style files. |
| 1977 |
|
| 1978 |
=item B<-t> I<file> |
| 1979 |
|
| 1980 |
Use I<file> as the transcript file. |
| 1981 |
|
| 1982 |
Disable implicit page range formation (B<makeindex> only). |
| 1983 |
|
| 1984 |
=item B<-x> I<file> |
| 1985 |
|
| 1986 |
Specify the full path name for B<xindy> to I<file> in the |
| 1987 |
event that B<xindy> isn't on the operating system's path. |
| 1988 |
|
| 1989 |
=item B<--version> |
| 1990 |
|
| 1991 |
Prints version number and exits. |
| 1992 |
|
| 1993 |
=item B<--help> |
| 1994 |
|
| 1995 |
Prints help message and exits. |
| 1996 |
|
| 1997 |
=back |
| 1998 |
|
| 1999 |
=head1 REQUIRES |
| 2000 |
|
| 2001 |
Perl, Getopt::Std, and makeindex or xindy (depending on glossaries |
| 2002 |
package options). |
| 2003 |
|
| 2004 |
=head1 LICENSE |
| 2005 |
|
| 2006 |
This is free software distributed under the LaTeX Project Public |
| 2007 |
License. There is NO WARRANTY. |
| 2008 |
See L<http://www.latex-project.org/lppl.txt> for details. |
| 2009 |
|
| 2010 |
=head1 AUTHOR |
| 2011 |
|
| 2012 |
Nicola L. C. Talbot, |
| 2013 |
L<http://www.dickimaw-books.com/> |
| 2014 |
|
| 2015 |
=head1 RECOMMENDED READING |
| 2016 |
|
| 2017 |
The glossaries manual: |
| 2018 |
|
| 2019 |
texdoc glossaries |
| 2020 |
|
| 2021 |
=cut |