X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate.pm;h=6da93d9b396806a0f6270c0f5054217dc3ddde36;hb=2868feee8fb33457e7562f02778186b5b5c1a2b6;hp=e6d7e10607844a3051417e2049c9556d447df66e;hpb=dc3cd296e62eb09a16fa694d9b3a7158e4cf63bf;p=kivitendo-erp.git diff --git a/SL/Template.pm b/SL/Template.pm index e6d7e1060..6da93d9b3 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) if (ref $self eq 'LaTeXTemplate'); my $contents = join("", @lines);