line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Amuse::Beamer; |
2
|
42
|
|
|
42
|
|
312
|
use strict; |
|
42
|
|
|
|
|
94
|
|
|
42
|
|
|
|
|
1272
|
|
3
|
42
|
|
|
42
|
|
247
|
use warnings; |
|
42
|
|
|
|
|
101
|
|
|
42
|
|
|
|
|
1090
|
|
4
|
42
|
|
|
42
|
|
213
|
use utf8; |
|
42
|
|
|
|
|
100
|
|
|
42
|
|
|
|
|
253
|
|
5
|
|
|
|
|
|
|
# use Data::Dumper; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Text::Amuse::Beamer - Beamer output for Text::Amuse |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Parse the L LaTeX result and convert it to a |
14
|
|
|
|
|
|
|
beamer documentclass body, wrapping the text into frames. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
The module is used internally by L, so everything here is |
19
|
|
|
|
|
|
|
pretty much internal only (and underdocumented). |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 CONSTRUCTORS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over 4 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item new(latex => \@latex_chunks) |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=back |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item latex |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Accessor to the latex arrayref passed at the constructor. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item process |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Return the beamer body as a string. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
1
|
|
|
1
|
1
|
6
|
my ($class, %args) = @_; |
45
|
1
|
50
|
|
|
|
4
|
die "Missing latex" unless $args{latex}; |
46
|
1
|
|
|
|
|
3
|
my $self = { latex => [ @{$args{latex}} ] }; |
|
1
|
|
|
|
|
29
|
|
47
|
1
|
|
|
|
|
7
|
bless $self, $class; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub latex { |
51
|
1
|
|
|
1
|
1
|
13
|
return shift->{latex}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub process { |
55
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
56
|
1
|
|
|
|
|
6
|
my $latex = $self->latex; |
57
|
1
|
|
|
|
|
3
|
my @out; |
58
|
|
|
|
|
|
|
# these chunks correspond to the various elements found, so if |
59
|
|
|
|
|
|
|
# it's an heading, it's guaranteed to be this way. |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
2
|
my ($in_frame, $in_text, @current, $current_title); |
62
|
|
|
|
|
|
|
# print Dumper($latex); |
63
|
1
|
|
|
|
|
4
|
foreach my $piece (@$latex) { |
64
|
121
|
|
|
|
|
189
|
$piece =~ s/\\footnoteB?\{/\\footnote[frame]{/g; |
65
|
121
|
100
|
|
|
|
311
|
if ($piece =~ /\A\s*\\( |
|
|
100
|
|
|
|
|
|
66
|
|
|
|
|
|
|
part| |
67
|
|
|
|
|
|
|
chapter| |
68
|
|
|
|
|
|
|
section| |
69
|
|
|
|
|
|
|
subsection| |
70
|
|
|
|
|
|
|
subsubsection) |
71
|
|
|
|
|
|
|
(\[\{(.+)\}\])? |
72
|
|
|
|
|
|
|
(\{(.+)\}\s*\z) |
73
|
|
|
|
|
|
|
/x) { |
74
|
15
|
|
|
|
|
30
|
my $type = $1; |
75
|
15
|
|
66
|
|
|
53
|
$in_frame = $3 || $5; |
76
|
15
|
100
|
|
|
|
30
|
if (@current) { |
77
|
8
|
|
50
|
|
|
54
|
push @out, { title => $current_title || '', |
78
|
|
|
|
|
|
|
body => [@current] }; |
79
|
8
|
|
|
|
|
18
|
@current = (); |
80
|
|
|
|
|
|
|
} |
81
|
15
|
|
|
|
|
46
|
push @out, "\\" . $type . '{' . $in_frame . '}' . "\n\n"; |
82
|
15
|
|
|
|
|
30
|
$current_title = $in_frame; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
elsif (defined $in_frame) { |
85
|
105
|
|
|
|
|
166
|
push @current, $piece; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
# flush; |
89
|
1
|
50
|
33
|
|
|
10
|
if ($in_frame && @current) { |
90
|
0
|
|
|
|
|
0
|
push @out, { title => $current_title, |
91
|
|
|
|
|
|
|
body => [@current] }; |
92
|
|
|
|
|
|
|
} |
93
|
1
|
|
|
|
|
7
|
return $self->_render(\@out); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _render { |
97
|
1
|
|
|
1
|
|
4
|
my ($self, $list) = @_; |
98
|
1
|
|
|
|
|
2
|
my @out; |
99
|
|
|
|
|
|
|
ELEMENT: |
100
|
1
|
|
|
|
|
3
|
foreach my $el (@$list) { |
101
|
23
|
100
|
|
|
|
39
|
if (ref($el)) { |
102
|
8
|
|
|
|
|
11
|
my $body = join('', @{$el->{body}}); |
|
8
|
|
|
|
|
33
|
|
103
|
8
|
100
|
|
|
|
31
|
if ($body =~ m/^%\s+no\s*slides?\s*$/im) { |
104
|
|
|
|
|
|
|
# and remove the previous element with the chapter |
105
|
2
|
50
|
|
|
|
8
|
pop @out if @out; |
106
|
2
|
|
|
|
|
6
|
next ELEMENT; |
107
|
|
|
|
|
|
|
} |
108
|
6
|
|
|
|
|
23
|
push @out, "\n\\begin{frame}[fragile]{$el->{title}}\n", $body, |
109
|
|
|
|
|
|
|
"\\end{frame}\n\n"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
15
|
|
|
|
|
27
|
push @out, $el; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
1
|
50
|
|
|
|
5
|
if (@out) { |
116
|
1
|
|
|
|
|
34
|
return join('', @out); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else { |
119
|
0
|
|
|
|
|
|
return ''; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=back |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |