<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w
use strict;
use Regexp::Common;
use Win32::PowerPoint;
use warnings FATAL =&gt; qw{ uninitialized };

################################################################
#### This is a parser that converts the simple subset of beamer into a PowerPoint file.
#### Note that inner-nested formatting options are currently only supported for:
#### Italic, bold, text size, color.
################################################################

my $PP= qr/$RE{balanced}{-parens=&gt;'\{ \}'}/ms;  ## how to match nested curly parens

(defined($ARGV[0])) or die "Need beamer .tex file as input.";  ## a default file

## read the entire contents of the file
$_ = slurpfile( $ARGV[0] ); 

## comments not avaliable in ppt conversion
s/[^\\]\%(.*)$//gm; 
s/\\n($PP)//g;
s/\\begin\{N\}/\\begin\{N\}\{/g;
s/\\end\{N\}/\}\\end\{N\}/g;
s/\\begin\{N\}($PP)\\end\{N\}//g;

# invoke (or connect to) PowerPoint
my $ppt = Win32::PowerPoint-&gt;new;
################################################################
#### user settings 
################################################################

#set text sizes and margins
my $titleSize = 36;
my $textSize = 24;
my $topMargin = 100; #location of the topmost textbox
my $textMargin = 25; 
my $defaultColor = [0,0,0]; #[255,255,255] format
my $defaultAlign = 'left'; #left, center, or right
   
# set presentation-wide information
$ppt-&gt;new_presentation(
#background_forecolor =&gt; [255,255,255],
#background_backcolor =&gt; [0,0,0],
#pattern =&gt; 'Shingle',
);

#set bullet point shape, in decimal unicode
my $bulletPoint = 8658;

# and master footer if you prefer (optional)
#1 if yes; 0 if no
$ppt-&gt;set_master_footer(
visible         =&gt; 1, 
text            =&gt; 'My Slides',
slide_number    =&gt; 1,
datetime        =&gt; 1,
datetime_format =&gt; 'MMMMyy',
);

# other variables
my $top;
my $tempOption;
my $option = {bold =&gt; 0, italic =&gt; 0,size =&gt; $textSize, left =&gt; 50, top =&gt;$top, width=&gt;600, color =&gt; [0,0,0], alignment =&gt; 'left', superscript =&gt; 0, subscript =&gt; 0};
my $titleOption = { size =&gt; 36, left =&gt; 50, top =&gt;50, width=&gt;600, alignment =&gt; 'center', bold =&gt; 1};


################################################################
#### Save title page
################################################################
s/\\title\{(.*?)\}//; my $title = $1;
s/\\subtitle\{(.*?)\}//g;  my $subtitle= $1;
s/\\author\{(.*?)\}//g;  my $author= $1;
s/\\institute[\{\[](.*?)[\}\]]//g;  my $institute= $1;
s/\\date\{(.*?)\}//g;  my $date= $1;

################################################################
#### special character definitions
#### TODO: perhaps move this to a separate file?
################################################################
#greek alphabet
s/\\alpha/\x{03B1}/g; s/\\beta/\x{03B2}/g; s/\\gamma/\x{03B3}/g;
s/\\delta/\x{03B4}/g; s/\\epsilon/\x{03B5}/g; s/\\zeta/\x{03B6}/g;
s/\\eta/\x{03B7}/g; s/\\theta/\x{03B8}/g; s/\\iota/\x{03B9}/g;
s/\\kappa/\x{03BA}/g; s/\\lambda/\x{03BB}/g; s/\\mu/\x{03BC}/g;
s/\\nu/\x{03BD}/g; s/\\xi/\x{03BE}/g; s/\\omicron/\x{03BF}/g;
s/\\pi/\x{03C0}/g; s/\\rho/\x{03C1}/g; s/\\sigma/\x{03C3}/g;
s/\\tau/\x{03C4}/g; s/\\upsilon/\x{03C5}/g; s/\\phi/\x{03C6}/g;
s/\\chi/\x{03C7}/g; s/\\psi/\x{03C8}/g; s/\\omega/\x{03C9}/g;

s/\\Alpha/\x{0391}/g; s/\\Beta/\x{0392}/g; s/\\Gamma/\x{0393}/g;
s/\\Delta/\x{0394}/g; s/\\Epsilon/\x{0395}/g; s/\\Zeta/\x{0396}/g;
s/\\Eta/\x{0397}/g; s/\\Theta/\x{0398}/g; s/\\Iota/\x{0399}/g;
s/\\Kappa/\x{039A}/g; s/\\Lambda/\x{039B}/g; s/\\Mu/\x{039C}/g;
s/\\Nu/\x{039D}/g; s/\\Xi/\x{039E}/g; s/\\Omicron/\x{039F}/g;
s/\\Pi/\x{03A0}/g; s/\\Rho/\x{03A1}/g; s/\\Sigma/\x{03A3}/g;
s/\\Tau/\x{03A4}/g; s/\\Upsilon/\x{03A5}/g; s/\\Phi/\x{03A6}/g;
s/\\Chi/\x{03A7}/g; s/\\Psi/\x{03A8}/g; s/\\Omega/\x{03A9}/g;

#currencies
s/\\pound/\x{00A3}/g; s/\\euro/\x{20AC}/g; 
s/\\yen/\x{00A5}/g; s/\\cent/\x{00A2}/g;

#math expressions
s/\\infinity/\x{223E}/g; s/\\infty/\x{223E}/g; s/\\leftrightarrow/\x{21D4}/g;
s/\\leftarrow/\x{21D0}/g;   s/\\rightarrow/\x{21D2}/g;  s/\\int/\x{222B}/g;
s/\\cdot/\x{00B7}/g;  s/\\perp/\x{22A5}/g;  s/\\frac12/\x{00BC}/g; 
s/\\frac14/\x{00BD}/g;  s/\\frac34/\x{00BE}/g;  s/\\cross/\x{2715}/g; 
s/\\florin/\x{0192}/g;  s/\\ne/\x{2260}/g;  s/\\equiv/\x{2261}/g;
s/\\sim/\x{007E}/g;  s/\\lt/\x{003C}/g;  s/\\gt/\x{003E}/g; 
s/\\le/\x{2264}/g;  s/\\ge/\x{2265}/g;  s/\\in/\x{2208}/g;
s/\\emptyset/\x{2205}/g;  s/\\forall/\x{2200}/g;  s/\\pm/\x{00B1}/g;
s/\\times/\x{2715}/g;  s/\\prod/\x{220F}/g;  s/\\sum/\x{2211}/g; 
s/\\sqrt/\x{221A}/g;  s/\\approx/\x{2248}/g; 
s/\\prop/\x{223D}/g;    

#other symbols
s/\\spadesuit/\x{2660}/g; s/\\clubsuit/\x{2663}/g; s/\\heartsuit/\x{2665}/g;
s/\\diamondsuit/\x{2666}/g; s/\\copyright/\x{00A9}/g; s/\\curlyleft/\x{007D}/g;
s/\\curlyright/\x{007B}/g; s/\\vert/\x{01C0}/g;
s/\\qquad/\t/g;
s/\\textcolor\{red\}/\\textred/g;
s/\\textcolor\{blue\}/\\textblue/g;
s/\^/\\\^/g;
s/\_/\\\_/g;
s/\\\$/internalDollarSign/g;
s/\$//g; #kills LaTeX equation parameters
s/internalDollarSign/\$/g;

################################################################
#### write content pages
#### TODO: expand color set? only red, black, blue now.
#### TODO: enable text formatting in tables (18pt black for now.)
################################################################


my $ParagraphsCount = 0;
while(/\\begin[\s]*\{frame\}/){
    s/^.*?\\begin\{frame\}//s; 
    $ppt-&gt;new_slide;
    $top = $topMargin;
    $option-&gt;{size} = $textSize;
    #write title page
    if(s/\\titlepage//)  {
	$ppt-&gt;add_text($title, { size =&gt; 36, left =&gt; 100, top =&gt;150, width=&gt;600, alignment =&gt; 'center', bold =&gt; 1});
	$ppt-&gt;add_text($subtitle, {size =&gt; 32, left =&gt; 250, top =&gt;200, width=&gt;400});
	$ppt-&gt;add_text($author, { size =&gt; 24, left =&gt; 450, top =&gt;280, width=&gt;200, alignment =&gt; 'right'});
	$ppt-&gt;add_text($institute, { size =&gt; 24, left =&gt; 450, top =&gt;300, width=&gt;200, alignment =&gt; 'right'});
	$ppt-&gt;add_text($date, { size =&gt; 24, left =&gt; 450, top =&gt;320, width=&gt;200, alignment =&gt; 'right'});
    }
    my $header = "";
    if(/^[\s]*\{/)
    {s/^[\s]*\{(.*)\}//;
    $header = $1;} 
    $ppt-&gt;add_text('',$titleOption);
    my $tempTextSize = $textSize;
    $textSize = $titleSize;
    print STDERR "[Writing slide: $header]\n";
    parse($header,$titleOption) if($header ne "");
    $textSize = $tempTextSize;
    $ppt-&gt;add_text('', $option);
    $ParagraphsCount = 0;
    while(!/^\s*?\\end[\s]*\{frame\}/s) {
	if (s/^[\n \s]*?\\begin[\s]*\{enumerate\}//) {
	    my $number = 1;
	    $number = $1+1 if (s/\\setcounter[\s]*\{enumi\}\{(.*)\}//);
	    #enumerations
	    while(!s/^[\n \s]*\\end[\s]*\{enumerate\}//) {
		if (s/^[\n \s]*\\begin[\s]*\{itemize\}//) {
		    while (!s/^[\n \s]*\\end[\s]*\{itemize\}//){
			s/^[\n \s]*\\item//;    s/^[\n]*(.*)\n//; 
			my $bullet = $ppt-&gt;slide-&gt;Shapes($ppt-&gt;slide-&gt;Shapes-&gt;Count)-&gt;TextFrame-&gt;TextRange-&gt;Paragraphs($ParagraphsCount+1)-&gt;ParagraphFormat-&gt;Bullet;
			$bullet-&gt;{Visible} = 1;
			$bullet-&gt;{RelativeSize} = 1.25;
			$bullet-&gt;{Character}= $bulletPoint;
			my $indent = $ppt-&gt;slide-&gt;Shapes($ppt-&gt;slide-&gt;Shapes-&gt;Count)-&gt;TextFrame-&gt;TextRange-&gt;Paragraphs($ParagraphsCount+1);
			$indent-&gt;{IndentLevel} = 3;
			parse($1,$option);$ppt-&gt;insert_after("\n",$tempOption);$ParagraphsCount++;
		        }}
		if (s/^[\n \s]*\\end[\s]*\{enumerate\}//) {last;}
	    	if (s/^[\n \s]*\\item/$number. /) {$number ++;}
		if (s/^[\n \s]*(.*)\n//) {parse($1,$option);$ppt-&gt;insert_after("\n",$tempOption);$ParagraphsCount++;}
	    }
	}
	#itemizations
	elsif (s/^[\n \s]*?\\begin[\s]*\{itemize\}//) {
	    while (!s/^[\n \s]*\\end[\s]*\{itemize\}//){
		s/^[\n \s]*\\item//;    s/^[\n]*(.*)\n//;
		
		my $bullet = $ppt-&gt;slide-&gt;Shapes($ppt-&gt;slide-&gt;Shapes-&gt;Count)-&gt;TextFrame-&gt;TextRange-&gt;Paragraphs($ParagraphsCount+1)-&gt;ParagraphFormat-&gt;Bullet;
		$bullet-&gt;{Visible} = 1;
		$bullet-&gt;{RelativeSize} = 1.25;
		$bullet-&gt;{Character}= $bulletPoint;
		my $indent = $ppt-&gt;slide-&gt;Shapes($ppt-&gt;slide-&gt;Shapes-&gt;Count)-&gt;TextFrame-&gt;TextRange-&gt;Paragraphs($ParagraphsCount+1);
		$indent-&gt;{IndentLevel} = 3;
		parse($1,$option);$ppt-&gt;insert_after("\n",$tempOption);$ParagraphsCount++;
		}
	}
	#tables
	elsif (s/^[\n \s]*?\\begin[\s]*\{tabular\}($PP)//)
	{
	    $ppt-&gt;slide-&gt;Shapes-&gt;AddTable(1,1,100,$top);
	    my $table = $ppt-&gt;slide-&gt;Shapes( $ppt-&gt;slide-&gt;Shapes-&gt;Count )-&gt;Table;
	    my $tableAlign = $1;  #reads the alignment instructions
	    my $numRows = 1;
	    my $numCols = 1;
	    my $currRow = 1;
	    my $currCol = 1;
	    my $input = '';
	    while(! s/^[\n \s]*?\\end[\s]*\{tabular\}// &amp;&amp;  s/^[\n \s]*\\tr\{(.*)\}/$1/)    {
	        if ($currRow &gt; $numRows) {$table-&gt;Rows-&gt;Add; $numRows++;}
		$currCol = 1;
	        while (! s/^\s*\}// &amp;&amp; s/^[\n \s]*\\td($PP)//) {
		    if ($currCol &gt; $numCols) {$table-&gt;Columns-&gt;Add; $numCols++;}
		    $input = $1; $input =~ s/\{(.*)\}/$1/;
		    $table-&gt;Cell($currRow, $currCol)-&gt;Shape-&gt;TextFrame-&gt;TextRange-&gt;{Text} = $input;
		    $currCol++;}
		$currRow++;
	    }
	    $top += $textMargin*$numRows;
	}
	#regular parsing
	else {
	    s/^[\n \s]*(.*)//;
	    parse($1, $option);
	    $ppt-&gt;insert_after("\n",$tempOption);$ParagraphsCount++;
	}
	$top += $textMargin;
    }
    
}

 


################################################################
#### Clean up, check for existing file 
################################################################

print STDERR "\nSlides successfully generated. Name the file: \n";
my $fileName;
my $yn;
my $readInput = 0;
while ($readInput == 0)
{
chomp($fileName=&lt;STDIN&gt;);
$fileName .= ".pptx";
if (-e $fileName)
{
print STDOUT "File already exists. Overwrite? Y/N \n";
chomp($yn=&lt;STDIN&gt;);
if ($yn eq "Y")
  {
    $ppt-&gt;save_presentation($fileName);
    $readInput = 1;
  }
else
  {
  print STDERR "Name the file: \n";
  next;     
  }
}
$ppt-&gt;save_presentation($fileName);
$readInput = 1;
}


$ppt-&gt;close_presentation;
# PowerPoint closes automatically


################################################################
#### subroutines
################################################################

#read the whole file
sub slurpfile {
  my $v= "";
  foreach my $fname (@_) {
    print STDERR "[reading $fname]\n";
    local $/=undef; 
    open(FIN, $fname) or die "cannot open '$fname': $!\n";
    $v .= &lt;FIN&gt;;                    # slurp the entire file
    close(FIN);
  }
  return $v;
}

#does some simple parsing of italic/bold/color/size to support nested formatting
#expects substring as $_[0], option as $_[1]
sub parse {
    my $storeOption;
    #save formatting options
    $tempOption-&gt;{bold} = $_[1]-&gt;{bold};
    $tempOption-&gt;{italic} = $_[1]-&gt;{italic};
    $tempOption-&gt;{alignment} = $_[1]-&gt;{alignment};
    $tempOption-&gt;{left} = $_[1]-&gt;{left};
    $tempOption-&gt;{width} = $_[1]-&gt;{width};
    $tempOption-&gt;{color} = $_[1]-&gt;{color};
    $tempOption-&gt;{superscript} = $_[1]-&gt;{superscript};
    $tempOption-&gt;{subscript} = $_[1]-&gt;{subscript};
    $storeOption-&gt;{bold} = $_[1]-&gt;{bold};
    $storeOption-&gt;{italic} = $_[1]-&gt;{italic};
    $storeOption-&gt;{alignment} = $_[1]-&gt;{alignment};
    $storeOption-&gt;{left} = $_[1]-&gt;{left};
    $storeOption-&gt;{width} = $_[1]-&gt;{width};
    $storeOption-&gt;{color} = $_[1]-&gt;{color};
    $storeOption-&gt;{superscript} = $_[1]-&gt;{superscript};
    $storeOption-&gt;{subscript} = $_[1]-&gt;{subscript};
    my $string = $_[0];
    my $tempString = "";
    my $modify = "";
    
    $string =~ s/\\pause/\n/g;
    $string =~ s/\\bigskip/\n/g;
    $string =~ s/\\\\/\n/g;
    $string =~ s/\\\%/\%/g;
    $string =~ s/\\\$/\$/g;
    #break into single arguments
    while($string ne ''){
	  if ($string =~ s/^[\n \s]*?\\tiny//){
	      $tempOption-&gt;{size} = $textSize-12;}
	  elsif ($string =~ s/^[\n \s]*?\\scriptsize//){
	      $tempOption-&gt;{size} = $textSize-9;}
	  elsif ($string =~ s/^[\n \s]*?\\footnotesize//){
	      $tempOption-&gt;{size} = $textSize-6;}
	  elsif ($string =~ s/^[\n \s]*?\\small//){
	      $tempOption-&gt;{size} = $textSize-3;}
	  elsif ($string =~ s/^[\n \s]*?\\normalsize//){
	      $tempOption-&gt;{size} = $textSize;}
	  elsif ($string =~ s/^[\n \s]*?\\large//){
	      $tempOption-&gt;{size} = $textSize+3;}
	  elsif ($string =~ s/^[\n \s]*?\\Large//){
	      $tempOption-&gt;{size} = $textSize+6;}	
	  elsif ($string =~ s/^[\n \s]*?\\LARGE//){
	      $tempOption-&gt;{size} = $textSize+9;}
	  elsif ($string =~ s/^[\n \s]*?\\huge//){
	      $tempOption-&gt;{size} = $textSize+12;}
	  elsif ($string =~ s/^[\n \s]*?\\Huge//){
	      $tempOption-&gt;{size} = $textSize+15;}
	  #$tempOption-&gt;{size} = $option-&gt;{size};

	if ($string =~ s/^\\([a-z \^ \_]*)($PP)//){
	    $modify = $1; $tempString = $2; $tempString =~ s/\{(.*)\}$/$1/; 
	    $tempOption-&gt;{bold} = 1 if($modify eq 'textbf');
	    $tempOption-&gt;{italic} = 1 if ($modify eq 'textit');
	    $tempOption-&gt;{alignment} = 'center' if($modify eq 'textcenter');
	    $tempOption-&gt;{alignment} = 'left' if($modify eq 'textleft');
	    $tempOption-&gt;{alignment} = 'right' if($modify eq 'textright');
	    $tempOption-&gt;{color} = [255,0,0] if($modify eq 'textred');
	    $tempOption-&gt;{color} = [0,0,255] if($modify eq 'textblue');
	    $tempOption-&gt;{subscript} = 1 if($modify eq '_');
	    $tempOption-&gt;{superscript} = 1 if($modify eq '^');
	    parse($tempString,$tempOption);
	    #restore
	    $tempOption-&gt;{bold} = $storeOption-&gt;{bold};
	    $tempOption-&gt;{italic} = $storeOption-&gt;{italic};
	    $tempOption-&gt;{size} = $storeOption-&gt;{size};
	    $tempOption-&gt;{subscript} = $storeOption-&gt;{subscript};
	    $tempOption-&gt;{superscript} = $storeOption-&gt;{superscript};
	    $tempOption-&gt;{left} = $storeOption-&gt;{left};
	    $tempOption-&gt;{width} = $storeOption-&gt;{width};
	    $tempOption-&gt;{color} = $storeOption-&gt;{color};}
	elsif ($string =~ /\\/){
	    $string =~ s/(.*)\\/\\/;
	    $ppt-&gt;insert_after($1,$tempOption);}
	else {
	    if ($string ne '')
	    {$ppt-&gt;insert_after($string,$tempOption); $string = '';}
    }
}
}





</pre></body></html>