Index: trunk/gsdl/perllib/plugins/BibTexPlug.pm
===================================================================
--- trunk/gsdl/perllib/plugins/BibTexPlug.pm	(revision 3112)
+++ trunk/gsdl/perllib/plugins/BibTexPlug.pm	(revision 3142)
@@ -105,5 +105,5 @@
 		 'title', 'Title',
 		 'volume', 'Volume',
-		 'year', 'Date',
+		 'year', 'Year', # Can't use "Date" as this implies DDDDMMYY!
 
 		 'keywords', 'Keywords',
@@ -119,17 +119,27 @@
     $verbosity = 0 unless $verbosity;
 
-    my $lines=$$textref;
-
-    # Make sure the text has exactly one entry per line
-
-    $lines  =~ s/^\s*(\@[^,]+,)\s*\n/$1=====/; #splitting key in entry
-    $lines =~ s/([\"\}]\s*,)\s*\n/$1=====/g; #splitting by comma, followed by \n (assuming end of lines are " or })
-    $lines =~ s/(\d+\s*\,)\s*\n/$1=====/g; #for the case, when we have number entry without closing "
-    $lines =~ s/\n\s*\n/%%%%%/g; #this was simply added in order to allow to process newline inside  quoted strings, 
-                                 #that continues for several lines
-    $lines =~ s/\s+/ /g;
-    $lines =~ s/\s*=====\s*/\n/g;
-
-    my @all_lines = split(/\n+/, $lines);
+    # Make sure the text has exactly one entry per line -
+    # append line to previous if it doesn't start with "  <key> = "
+
+    my @input_lines=split('\n', $$textref);
+    my @all_lines;
+    my $entry_line=shift @input_lines;
+    foreach my $input_line (@input_lines) {
+	if ($input_line =~ m/^\s*\w+\s*=\s*/) {
+	    # this is a new key
+	    push(@all_lines, $entry_line);
+	    $entry_line=$input_line;
+	} else {
+	    # this is a continuation of previous line
+	    $entry_line .= $input_line;
+	}
+	
+    }
+    # add final line, removing trailing '}'
+    $entry_line =~ s/\}\s*$//;
+    push(@all_lines, $entry_line);
+    push(@all_lines, "}");
+
+
 
     # Read and process each line in the bib file.
@@ -189,4 +199,7 @@
 	$value = $metadata{$entryname};
 
+	if ($name =~ /^Month/) {
+	    $value=expand_month($value);
+	}
 	# Add the various fields as metadata	
  	my $html_value = &text_into_html($value);
@@ -338,4 +351,24 @@
 
 
+sub expand_month {
+    my $text=shift;
+
+    # bibtex style files expand abbreviations for months.
+    # Entries can contain more than one month (eg ' month = jun # "-" # aug, ')
+    $text =~ s/jan/_textmonth01_/g;
+    $text =~ s/feb/_textmonth02_/g;
+    $text =~ s/mar/_textmonth03_/g;
+    $text =~ s/apr/_textmonth04_/g;
+    $text =~ s/may/_textmonth05_/g;
+    $text =~ s/jun/_textmonth06_/g;
+    $text =~ s/jul/_textmonth07_/g;
+    $text =~ s/aug/_textmonth08_/g;
+    $text =~ s/sep/_textmonth09_/g;
+    $text =~ s/oct/_textmonth10_/g;
+    $text =~ s/nov/_textmonth11_/g;
+    $text =~ s/dec/_textmonth12_/g;
+
+    return $text;
+}
 
 
@@ -416,4 +449,10 @@
 	 '"Y' => chr(0xc3).chr(0xb8),
 	 # tilde
+	 '~A' => chr(0xc3).chr(0x83),
+	 '~N' => chr(0xc3).chr(0x91),
+	 '~O' => chr(0xc3).chr(0x95),
+	 '~a' => chr(0xc3).chr(0xa3),
+	 '~n' => chr(0xc3).chr(0xb1),
+	 '~o' => chr(0xc3).chr(0xb5),
 	 # caron - handled specially
 #	   ',s' => chr(0xc5).chr(0xa1),
@@ -520,19 +559,26 @@
       # only do the change if immediately followed by a space, }, {, or \
       for $latex_code (keys %special_utf8_chars) {
-	  $text =~ s/\\${latex_code}([\\\s\{\}])/$special_utf8_chars{$latex_code}$1/g;
+	  $text =~ s/\\${latex_code}([\\\s{}])/$special_utf8_chars{$latex_code}$1/g;
       }
     }
-
     # remove latex commands
-    $text =~ s@\\\w+{([^}]*)}@$1@g;
-
+    $text =~ s@\\noopsort{[^}]+\}@@g;
+    $text =~ s@\\\w+{([^}]*)}@$1@g; # all other commands
+    
     # remove latex groupings { } (but not \{ or \} )
-    $text =~ s/([^\\])\{/$1/g;
-    $text =~ s/([^\\])\}/$1/g;
-    $text =~ s/^{//; # remove { if first char
-
+    while ($text =~ s/([^\\])[\{\}]/$1/g) {;}
+    $text =~ s/^\{//; # remove { if first char
+    
     # maths mode $...$ - this is not interpreted in any way at the moment...
     $text =~ s@\$(.*)\$@$1@g;
-
+    
+    # latex characters
+    # spaces - nobr space (~), opt break (\-), append ("#" - bibtex only)
+    $text =~ s/([^\\])~+/$1/g; # non-breaking space  "~"
+    # optional break "\-"
+    if ($text =~ m/\#/) { # concat macros (bibtex)
+	# the non-macro bits have quotes around them - we just remove quotes
+	$text =~ s/[\"\#]//g;
+    }
     # quoted { } chars
     $text =~ s@\\{@{@g;
