line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Amuse::Beamer; |
2
|
41
|
|
|
41
|
|
261
|
use strict; |
|
41
|
|
|
|
|
73
|
|
|
41
|
|
|
|
|
1002
|
|
3
|
41
|
|
|
41
|
|
163
|
use warnings; |
|
41
|
|
|
|
|
64
|
|
|
41
|
|
|
|
|
904
|
|
4
|
41
|
|
|
41
|
|
154
|
use utf8; |
|
41
|
|
|
|
|
68
|
|
|
41
|
|
|
|
|
197
|
|
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
|
4
|
my ($class, %args) = @_; |
45
|
1
|
50
|
|
|
|
4
|
die "Missing latex" unless $args{latex}; |
46
|
1
|
|
|
|
|
4
|
my $self = { latex => [ @{$args{latex}} ] }; |
|
1
|
|
|
|
|
33
|
|
47
|
1
|
|
|
|
|
5
|
bless $self, $class; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub latex { |
51
|
1
|
|
|
1
|
1
|
6
|
return shift->{latex}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub process { |
55
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
56
|
1
|
|
|
|
|
4
|
my $latex = $self->latex; |
57
|
1
|
|
|
|
|
2
|
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
|
|
|
|
|
3
|
my ($in_frame, $in_text, @current, $current_title); |
62
|
|
|
|
|
|
|
# print Dumper($latex); |
63
|
1
|
|
|
|
|
3
|
foreach my $piece (@$latex) { |
64
|
121
|
|
|
|
|
132
|
$piece =~ s/\\footnoteB?\{/\\footnote[frame]{/g; |
65
|
121
|
100
|
|
|
|
213
|
if ($piece =~ /\A\s*\\( |
|
|
100
|
|
|
|
|
|
66
|
|
|
|
|
|
|
part| |
67
|
|
|
|
|
|
|
chapter| |
68
|
|
|
|
|
|
|
section| |
69
|
|
|
|
|
|
|
subsection| |
70
|
|
|
|
|
|
|
subsubsection) |
71
|
|
|
|
|
|
|
(\[\{(.+)\}\])? |
72
|
|
|
|
|
|
|
(\{(.+)\}\s*\z) |
73
|
|
|
|
|
|
|
/x) { |
74
|
15
|
|
|
|
|
21
|
my $type = $1; |
75
|
15
|
|
66
|
|
|
35
|
$in_frame = $3 || $5; |
76
|
15
|
100
|
|
|
|
23
|
if (@current) { |
77
|
8
|
|
50
|
|
|
37
|
push @out, { title => $current_title || '', |
78
|
|
|
|
|
|
|
body => [@current] }; |
79
|
8
|
|
|
|
|
11
|
@current = (); |
80
|
|
|
|
|
|
|
} |
81
|
15
|
|
|
|
|
34
|
push @out, "\\" . $type . '{' . $in_frame . '}' . "\n\n"; |
82
|
15
|
|
|
|
|
22
|
$current_title = $in_frame; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
elsif (defined $in_frame) { |
85
|
105
|
|
|
|
|
119
|
push @current, $piece; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
# flush; |
89
|
1
|
50
|
33
|
|
|
6
|
if ($in_frame && @current) { |
90
|
0
|
|
|
|
|
0
|
push @out, { title => $current_title, |
91
|
|
|
|
|
|
|
body => [@current] }; |
92
|
|
|
|
|
|
|
} |
93
|
1
|
|
|
|
|
4
|
return $self->_render(\@out); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _render { |
97
|
1
|
|
|
1
|
|
2
|
my ($self, $list) = @_; |
98
|
1
|
|
|
|
|
2
|
my @out; |
99
|
|
|
|
|
|
|
ELEMENT: |
100
|
1
|
|
|
|
|
2
|
foreach my $el (@$list) { |
101
|
23
|
100
|
|
|
|
27
|
if (ref($el)) { |
102
|
8
|
|
|
|
|
8
|
my $body = join('', @{$el->{body}}); |
|
8
|
|
|
|
|
23
|
|
103
|
8
|
100
|
|
|
|
21
|
if ($body =~ m/^%\s+no\s*slides?\s*$/im) { |
104
|
|
|
|
|
|
|
# and remove the previous element with the chapter |
105
|
2
|
50
|
|
|
|
6
|
pop @out if @out; |
106
|
2
|
|
|
|
|
4
|
next ELEMENT; |
107
|
|
|
|
|
|
|
} |
108
|
6
|
|
|
|
|
17
|
push @out, "\n\\begin{frame}[fragile]{$el->{title}}\n", $body, |
109
|
|
|
|
|
|
|
"\\end{frame}\n\n"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
15
|
|
|
|
|
20
|
push @out, $el; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
1
|
50
|
|
|
|
3
|
if (@out) { |
116
|
1
|
|
|
|
|
24
|
return join('', @out); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
else { |
119
|
0
|
|
|
|
|
|
return ''; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=back |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |