From 644504117346e1ae8f2bafa9493cccfdba4f656b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 27 Dec 2010 13:17:06 +0100 Subject: [PATCH] =?utf8?q?Ben=C3=B6tigte=20LaTeX-Pakete=20nach=20letztem?= =?utf8?q?=20\usepackage=20oder=20vor=20\begin{document}=20einbinden?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Erst, wenn weder das Eine noch das Andere gefunden wurde, werden die benötigten Zeilen am Ende angefügt. Fix für Bug 1414. --- SL/Template/LaTeX.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/SL/Template/LaTeX.pm b/SL/Template/LaTeX.pm index 6b18ad038..d1c208018 100644 --- a/SL/Template/LaTeX.pm +++ b/SL/Template/LaTeX.pm @@ -292,11 +292,12 @@ sub _force_mandatory_packages { my $self = shift; my $lines = shift; - my (%used_packages, $document_start_line); + my (%used_packages, $document_start_line, $last_usepackage_line); foreach my $i (0 .. scalar @{ $lines } - 1) { if ($lines->[$i] =~ m/\\usepackage[^\{]*{(.*?)}/) { $used_packages{$1} = 1; + $last_usepackage_line = $i; } elsif ($lines->[$i] =~ m/\\begin{document}/) { $document_start_line = $i; @@ -305,11 +306,14 @@ sub _force_mandatory_packages { } } - $document_start_line = scalar @{ $lines } - 1 if (!defined $document_start_line); + my $insertion_point = defined($document_start_line) ? $document_start_line + : defined($last_usepackage_line) ? $last_usepackage_line + : scalar @{ $lines } - 1; - if (!$used_packages{textcomp}) { - splice @{ $lines }, $document_start_line, 0, "\\usepackage{textcomp}\n"; - $document_start_line++; + foreach my $package (qw(textcomp)) { + next if $used_packages{$package}; + splice @{ $lines }, $insertion_point, 0, "\\usepackage{${package}}\n"; + $insertion_point++; } } -- 2.20.1