From e7361d77e6e37bf1f5a3137e237ab03d6dbb316f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 31 Jan 2008 15:19:36 +0000 Subject: [PATCH] =?utf8?q?Forcieren,=20dass=20bei=20LaTeX-Vorlagen=20das?= =?utf8?q?=20Paket=20"textcomp"=20eingebunden=20wird,=20das=20f=C3=BCr=20d?= =?utf8?q?as=20Euro-Zeichen=20ben=C3=B6tigt=20wird.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Template.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/SL/Template.pm b/SL/Template.pm index e6d7e1060..a268ae6c9 100644 --- a/SL/Template.pm +++ b/SL/Template.pm @@ -415,6 +415,31 @@ sub _parse_config_lines { } } +sub _force_mandatory_packages { + my $self = shift; + my $lines = shift; + + my (%used_packages, $document_start_line); + + foreach my $i (0 .. scalar @{ $lines } - 1) { + if ($lines->[$i] =~ m/\\usepackage[^{]*{(.*?)}/) { + $used_packages{$1} = 1; + + } elsif ($lines->[$i] =~ m/\\begin{document}/) { + $document_start_line = $i; + last; + + } + } + + $document_start_line = scalar @{ $lines } - 1 if (!defined $document_start_line); + + if (!$used_packages{textcomp}) { + splice @{ $lines }, $document_start_line, 0, "\\usepackage{textcomp}\n"; + $document_start_line++; + } +} + sub parse { my $self = $_[0]; local *OUT = $_[1]; @@ -428,6 +453,7 @@ sub parse { close(IN); $self->_parse_config_lines(\@lines); + $self->_force_mandatory_packages(\@lines); my $contents = join("", @lines); -- 2.20.1