sub
new {
my
(
$class
,
%args
) =
@_
;
die
"Missing latex"
unless
$args
{latex};
my
$self
= {
latex
=> [ @{
$args
{latex}} ] };
bless
$self
,
$class
;
}
sub
latex {
return
shift
->{latex};
}
sub
process {
my
$self
=
shift
;
my
$latex
=
$self
->latex;
my
@out
;
my
(
$in_frame
,
$in_text
,
@current
,
$current_title
);
foreach
my
$piece
(
@$latex
) {
if
(
$piece
=~ /\A\s*\\(
part|
chapter|
section|
subsection|
subsubsection)
({(.+)}\s*\z)/x) {
$in_frame
= $3;
if
(
@current
) {
push
@out
, {
title
=>
$current_title
||
''
,
body
=> [
@current
] };
@current
= ();
}
push
@out
,
$piece
;
$current_title
=
$in_frame
;
}
elsif
(
defined
$in_frame
) {
push
@current
,
$piece
;
}
}
if
(
$in_frame
&&
@current
) {
push
@out
, {
title
=>
$current_title
,
body
=> [
@current
] };
}
return
$self
->_render(\
@out
);
}
sub
_render {
my
(
$self
,
$list
) =
@_
;
my
@out
;
ELEMENT:
foreach
my
$el
(
@$list
) {
if
(
ref
(
$el
)) {
my
$body
=
join
(
''
, @{
$el
->{body}});
if
(
$body
=~ m/\\begin\{comment\}\s*;\s+noslide\s*\\end\{comment\}/) {
pop
@out
if
@out
;
next
ELEMENT;
}
push
@out
,
"\n\\begin{frame}[fragile]{$el->{title}}\n"
,
$body
,
"\\end{frame}\n\n"
;
}
else
{
push
@out
,
$el
;
}
}
if
(
@out
) {
return
join
(
''
,
@out
);
}
else
{
return
''
;
}
}
1;