| 1 | # | ||
| 2 | # $Id$ | ||
| 3 | # | ||
| 4 | # format::latex Brik | ||
| 5 | # | ||
| 6 | package Metabrik::Format::Latex; | ||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use base qw(Metabrik::Shell::Command Metabrik::System::Package Metabrik::Client::Www); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | sub brik_properties { | ||
| 13 | return { | ||
| 14 | revision => '$Revision$', | ||
| 15 | tags => [ qw(unstable) ], | ||
| 16 | author => 'GomoR <GomoR[at]metabrik.org>', | ||
| 17 | license => 'http://opensource.org/licenses/BSD-3-Clause', | ||
| 18 | attributes => { | ||
| 19 | datadir => [ qw(datadir) ], | ||
| 20 | style => [ qw(file) ], | ||
| 21 | capture_mode => [ qw(0|1) ], | ||
| 22 | }, | ||
| 23 | attributes_default => { | ||
| 24 | style => 'llncs.cls', | ||
| 25 | capture_mode => 0, | ||
| 26 | }, | ||
| 27 | commands => { | ||
| 28 | install => [ ], # Inherited | ||
| 29 | update => [ ], | ||
| 30 | make_dvi => [ qw(input style|OPTIONAL) ], | ||
| 31 | make_pdf => [ qw(input style|OPTIONAL) ], | ||
| 32 | }, | ||
| 33 | require_modules => { | ||
| 34 | 'Metabrik::File::Compress' => [ ], | ||
| 35 | 'Metabrik::System::File' => [ ], | ||
| 36 | }, | ||
| 37 | require_binaries => { | ||
| 38 | latex => [ ], | ||
| 39 | pdflatex => [ ], | ||
| 40 | }, | ||
| 41 | need_packages => { | ||
| 42 | ubuntu => [ qw(texlive texlive-latex-extra texlive-lang-french) ], # Sorry, the author is French | ||
| 43 | debian => [ qw(texlive texlive-latex-extra texlive-lang-french) ], # Sorry, the author is French | ||
| 44 | kali => [ qw(texlive texlive-latex-extra texlive-lang-french) ], # Sorry, the author is French | ||
| 45 | }, | ||
| 46 | }; | ||
| 47 | } | ||
| 48 | |||
| 49 | sub update { | ||
| 50 | my $self = shift; | ||
| 51 | |||
| 52 | my $datadir = $self->datadir; | ||
| 53 | |||
| 54 | my @urls = ( | ||
| 55 | 'ftp://ftp.springer.de/pub/tex/latex/llncs/latex2e/llncs.cls', | ||
| 56 | 'https://www.usenix.org/sites/default/files/usenix.sty_.txt', | ||
| 57 | 'https://www.usenix.org/sites/default/files/template.la_.txt', | ||
| 58 | ); | ||
| 59 | |||
| 60 | my $r = $self->mirror(\@urls) or return; | ||
| 61 | |||
| 62 | my @final = (); | ||
| 63 | my $fc = Metabrik::File::Compress->new_from_brik_init($self) or return; | ||
| 64 | my $sf = Metabrik::System::File->new_from_brik_init($self) or return; | ||
| 65 | for (@$r) { | ||
| 66 | if (/usenix.sty_.txt$/) { | ||
| 67 | my $files = $fc->uncompress($_) or next; | ||
| 68 | next if (@$files == 0); | ||
| 69 | $_ = $files->[0]; | ||
| 70 | my $basedir = $sf->basedir($_) or next; | ||
| 71 | $sf->copy($_, $basedir.'/'.'usenix.sty') or next; | ||
| 72 | $_ = $basedir.'/'.'usenix.sty'; | ||
| 73 | } | ||
| 74 | elsif (/template.la_.txt$/) { | ||
| 75 | my $files = $fc->uncompress($_) or next; | ||
| 76 | next if (@$files == 0); | ||
| 77 | $_ = $files->[0]; | ||
| 78 | my $basedir = $sf->basedir($_) or next; | ||
| 79 | $sf->copy($_, $basedir.'/'.'usenix-template.tex') or next; | ||
| 80 | $_ = $basedir.'/'.'usenix-template.tex'; | ||
| 81 | } | ||
| 82 | push @final, $_; | ||
| 83 | } | ||
| 84 | |||
| 85 | return \@final; | ||
| 86 | } | ||
| 87 | |||
| 88 | sub make_dvi { | ||
| 89 | my $self = shift; | ||
| 90 | my ($input, $style) = @_; | ||
| 91 | |||
| 92 | $style ||= $self->style; | ||
| 93 | $self->brik_help_run_undef_arg('make_dvi', $input) or return; | ||
| 94 | $self->brik_help_run_file_not_found('make_dvi', $input) or return; | ||
| 95 | $self->brik_help_run_file_not_found('make_dvi', $style) or return; | ||
| 96 | |||
| 97 | my $cmd = "latex \"$input\""; | ||
| 98 | |||
| 99 | return $self->execute($cmd); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub make_pdf { | ||
| 103 | my $self = shift; | ||
| 104 | my ($input, $style) = @_; | ||
| 105 | |||
| 106 | my $datadir = $self->datadir; | ||
| 107 | |||
| 108 | $style ||= $datadir.'/'.$self->style; | ||
| 109 | $self->brik_help_run_undef_arg('make_pdf', $input) or return; | ||
| 110 | $self->brik_help_run_file_not_found('make_pdf', $input) or return; | ||
| 111 | $self->brik_help_run_file_not_found('make_pdf', $style) or return; | ||
| 112 | |||
| 113 | my $sf = Metabrik::System::File->new_from_brik_init($self) or return; | ||
| 114 | $sf->copy($style, ".") or return; | ||
| 115 | |||
| 116 | my $cmd = "pdflatex \"$input\""; | ||
| 117 | |||
| 118 | return $self->execute($cmd); | ||
| 119 | } | ||
| 120 | |||
| 121 | 1; | ||
| 122 | |||
| 123 | __END__ | ||