"twocolumn" => "\\papercolumns 2",
);
- # if the language file is available then added it to the options table
+ my %Languages_Table = ();
+ # if the language file is available then added it to the languages table
if(-e "$main::lyxdir/languages") {
open (LANGUAGES, "<$main::lyxdir/languages");
while(<LANGUAGES>) {
next if(/^\#/); #ignore comments
my @lang_field = split(/\s+/);
- $Option_Trans_Table{$lang_field[1]} = "\\language $lang_field[1]";
+ $Languages_Table{$lang_field[1]} = $lang_field[1];
}
close(LANGUAGES);
}
#}
# Write first line of the lyx file
- $LyX_Preamble .= "\#LyX 1.2 created this file. For more info see http://www.lyx.org/\n";
+ $LyX_Preamble .= "\# The reLyX bundled with LyX 1.3 created this file.\n" .
+ "# For more info see http://www.lyx.org/\n";
# Print \lyxformat.
$LyX_Preamble .= "\\lyxformat $Format\n";
}
}
$extra_options =~ s/^,+|,+(?=,)|,+$//g; # extra commas
+ # Analyze further the extra options for languages, the last language
+ # is the document language, so the order matters.
+ my $language ="";
+ foreach $op (split(/\s*,\s*/,$extra_options)) {
+ if (exists $Languages_Table{$op}) {
+ $language = $op;
+ $extra_options =~ s/\b$op\b//;
+ print "Document language $op\n" if $debug_on;
+ }
+ }
+ if ($language) {
+ $LyX_Preamble .= "\\language $language\n";
+ }
+ $extra_options =~ s/^,+|,+(?=,)|,+$//g; # extra commas
}
# Convert any remaining options to an \options command
if ($extra_options) {
# (unless there is no preamble)
# Everything until the end of filehandle PREAMBLE is preamble matter
my $Latex_Preamble = $_; # there COULD be a preamble command on same line
- my $write_preamble = (! /^\s*$/ && ! /^\s*%/);
while (<PREAMBLE>) {
$Latex_Preamble .= $_;
- # write an official preamble if we find anything that's not comment
- $write_preamble ||= (! /^\s*$/ && ! /^\s*%/);
}
- # Process $Latex_Preamble, and try to extarct as much as possible to
+ # Process $Latex_Preamble, and try to extract as much as possible to
# $Lyx_Preamble (jamatos 2001/07/21)
# Deal with counters, for now just "tocdepth" and "secnumdepth"
if($Latex_Preamble =~ s/\\usepackage\[(.*)\]\{inputenc\}\s*//) {
$LyX_Preamble .= "\\inputencoding $1\n";
}
+ $Latex_Preamble =~ s/\\usepackage\[.*\]\{fontenc\}\s*//;
- ## Deal with several \usepackage{} cases
+ ## Deal with \usepackage{} cases, no optional argument
my %Usepackage_Table = (
"amsmath" => "\\use_amsmath 1",
"amssymb" => "",
"a4" => "\\paperpackage a4wide",
"graphics" => "\\graphics default",
- "rotating" => ""
+ "rotating" => "",
+ "makeidx" => ""
);
+ ## Babel with arguments specifing language
+ if($Latex_Preamble =~ s/\\usepackage\[(.*)\]\{babel\}\s*//) {
+ my @languages = split(',',$1);
+ my $lang = pop @languages;
+ $LyX_Preamble .= "\\language $lang\n";
+ }
+
my $up;
foreach $up (keys %Usepackage_Table) {
- $Latex_Preamble =~ s/\\usepackage\{$up\}\s*// && do {
+ $Latex_Preamble =~ s/^\s*\\usepackage\{$up\}\s*// && do {
$LyX_Preamble .= "$Usepackage_Table{$up}";
$LyX_Preamble .= "\n" unless ($Usepackage_Table{$up} eq "");
}
}
+ # Natbib is a little more complex than that.
+ if ($Latex_Preamble =~ s/\\usepackage(.*)\{natbib\}\s*//) {
+ $LyX_Preamble .= "\\use_natbib 1\n\\use_numerical_citations ";
+ $LyX_Preamble .= ($1 =~ /numbers/) ? "1\n" : "0\n";
+ } else {
+ $LyX_Preamble .= "\\use_natbib 0\n\\use_numerical_citations 0\n";
+ }
+
## Handle geometry options
## The custom paper missing from the options list since it involves two parameters
my %Geometry_Options =(
my $op;
foreach $op (keys %Geometry_Options) {
$geom_options =~ s/$op// && do {
- $LyX_Preamble .= $Geometry_Options{$op}();
+ $LyX_Preamble .= &{$Geometry_Options{$op}}();
print "Geometry option $op\n" if $debug_on;
}
}
$Latex_Preamble =~ s/\\makeatletter\s*//;
$Latex_Preamble =~ s/\\makeatother\s*//;
- if ($write_preamble) {
- $Latex_Preamble =~ s/^\s*//;
- print "LaTeX preamble, consists of:\n$Latex_Preamble" if $debug_on;
+ $Latex_Preamble =~ s/^\s*//;
+ print "LaTeX preamble, consists of:\n$Latex_Preamble" if $debug_on;
+ if($Latex_Preamble) {
$Latex_Preamble = "\\begin_preamble\n$Latex_Preamble\\end_preamble\n";
- print "End of LaTeX preamble\n" if $debug_on;
- } else {
- $Latex_Preamble = ""; #just comments, whitespace. Ignore them
- }
+ } #just comments, whitespace. Ignore them
+ print "End of LaTeX preamble\n" if $debug_on;
#warn "Done creating LyX Preamble\n";
return ($class, $LyX_Preamble, $Latex_Preamble);