User Tools

Site Tools


latexslideshow

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
latexslideshow [2018/12/06 19:53]
abeverley
latexslideshow [2018/12/06 20:06] (current)
abeverley
Line 1: Line 1:
 +=====LatexSlideshow=====
 +
 I found myself in a situation recently, where somebody wanted to create a Powerpoint slideshow for a hundred or so photos, all with the same header and footer. I thought it might be a lot easier to produce the file using Latex, and indeed it was. This is what I did. I found myself in a situation recently, where somebody wanted to create a Powerpoint slideshow for a hundred or so photos, all with the same header and footer. I thought it might be a lot easier to produce the file using Latex, and indeed it was. This is what I did.
  
 The steps shown here include resizing and renaming the photos first. The steps shown here include resizing and renaming the photos first.
  
-I am assuming that you have all your images in the directory ​<tt>images</tt>+I am assuming that you have all your images in the directory ​''​%%images%%''​
  
-==Resize photos==+===== Resize photos ​=====
  
-I used the Imagemagick ​<tt>mogrify</​tt> ​command to bulk resize all the images. This command resizes all images to a maximum size of 1280x1024, but does not resize them if they are already smaller than that.+I used the Imagemagick ​''​%%mogrify%%'' ​command to bulk resize all the images. This command resizes all images to a maximum size of 1280x1024, but does not resize them if they are already smaller than that.
  
-  mogrify ​-resize 1280x1024\> images/*+''​%%mogrify -resize 1280x1024\>​ images/​*%%''​
  
-==Rename files sequentially==+===== Rename files sequentially ​=====
  
-The following Perl script renames all the files sequentially. This makes it easier to include them in the Latex script. See [http://​stackoverflow.com/​questions/​3211595/​renaming-files-in-a-folder-to-sequential-numbers this Stackoverflow question] for more details.+The following Perl script renames all the files sequentially. This makes it easier to include them in the Latex script. See [[http://​stackoverflow.com/​questions/​3211595/​renaming-files-in-a-folder-to-sequential-numbers|this Stackoverflow question]] for more details.
  
-  ​#​!/​usr/​bin/​perl +<​code>​ 
-   +#​!/​usr/​bin/​perl
-  use strict; +
-  use warnings; +
-   +
-  use File::Temp qw/​tempfile/;​ +
-   +
-  my $dir = $ARGV[0] +
-      or die "​Please specify directory as first argument";​ +
-   +
-  opendir(my $dh, $dir) or die "​can'​t opendir $dir: $!"; +
-   +
-  # First rename any files that are already numeric +
-  while (my @files = grep { /​^[0-9]+(\..*)?​$/​ } readdir($dh)) +
-  { +
-      for my $old (@files) { +
-          my $ext = $old =~ /​(\.[^.]+)$/​ ? $1 : '';​ +
-          my ($fh, $new) = tempfile(DIR => $dir, SUFFIX => $ext); +
-          close $fh; +
-          rename "​$dir/​$old",​ $new; +
-      } +
-  } +
-   +
-  rewinddir $dh; +
-  my $i; +
-  while (my $file = readdir($dh)) +
-  { +
-      next if $file =~ /​\A\.\.?​\z/;​ +
-      my $ext = $file =~ /​(\.[^.]+)$/​ ? $1 : '';​ +
-      rename "​$dir/​$file",​ sprintf("​%s/​%s%s",​ $dir, ++$i, $ext);  +
-  }+
  
 +use strict;
 +use warnings;
 +
 +use File::Temp qw/​tempfile/;​
 +
 +my $dir = $ARGV[0]
 +    or die "​Please specify directory as first argument";​
 +
 +opendir(my $dh, $dir) or die "​can'​t opendir $dir: $!";
 +
 +# First rename any files that are already numeric
 +while (my @files = grep { /​^[0-9]+(\..*)?​$/​ } readdir($dh))
 +{
 +    for my $old (@files) {
 +        my $ext = $old =~ /​(\.[^.]+)$/​ ? $1 : '';​
 +        my ($fh, $new) = tempfile(DIR => $dir, SUFFIX => $ext);
 +        close $fh;
 +        rename "​$dir/​$old",​ $new;
 +    }
 +}
 +
 +rewinddir $dh;
 +my $i;
 +while (my $file = readdir($dh))
 +{
 +    next if $file =~ /​\A\.\.?​\z/;​
 +    my $ext = $file =~ /​(\.[^.]+)$/​ ? $1 : '';​
 +    rename "​$dir/​$file",​ sprintf("​%s/​%s%s",​ $dir, ++$i, $ext); ​
 +}
 +</​code>​
 Save the above script and run: Save the above script and run:
  
-  ​./rename.pl images+''​%%./rename.pl images%%''​
  
 You should now have all your images as 1.jpg, 2.jpg and so on. You should now have all your images as 1.jpg, 2.jpg and so on.
  
-==Convert to slideshow PDF==+===== Convert to slideshow PDF ===== 
 + 
 +Save the following Latex script as ''​%%slides.tex%%''​. Comments being with a ''​%%%%%''​. 
 + 
 +<​code>​ 
 +\documentclass{beamer} 
 +\usepackage[size=a4]{beamerposter} 
 +\usepackage{pdfpages} 
 + 
 +\usefonttheme{professionalfonts} % using non standard fonts for beamer 
 +\usefonttheme{serif} % default family is serif 
 +\usepackage{fontspec} 
 +\usepackage{pgffor} 
 +\setmainfont{Source Sans Pro Light} 
 + 
 +\usepackage{graphicx} 
 + 
 +\begin{document}
  
-Save the following ​Latex script as <​tt>​slides.tex</​tt>​. Comments being with <tt>%</tt>.+% Uncomment ​the following ​to insert ​title image without header and footer text 
 +   ​\begin{frame} 
 +%    \transduration{1.5} 
 +%    \transglitter 
 +%    \begin{figure} 
 +%        \includegraphics[height=20cm]{another-image-file} 
 +%    \end{figure} 
 +%    \end{frame}
  
-  \documentclass{beamer} +\foreach \n in {1,​...,​11}{ 
-  \usepackage[size=a4]{beamerposter} +    \begin{frame} 
-  \usepackage{pdfpages} +    \transduration{1.5} % Duration between slides 
-   +    \transglitter % Transition effect 
-  \usefonttheme{professionalfonts} % using non standard fonts for beamer +%    \includegraphics{logo}\hspace{2cm} % Optional: add a logo at the top of each slide 
-  \usefonttheme{serif} % default family is serif +    {\LARGE\textbf{Here is a header for each page}}\newline 
-  \usepackage{fontspec} +    \begin{figure} 
-  \usepackage{pgffor} +        \includegraphics[height=14cm]{images/​\n} 
-  \setmainfont{Source Sans Pro Light} +    \end{figure} 
-   +    Here is some small footer text 
-  \usepackage{graphicx} +    \end{frame} 
-   +}
-  \begin{document} +
-   +
-  % Uncomment the following to insert a title image without header and footer text +
-  %    \begin{frame} +
-  %    \transduration{1.5} +
-  %    \transglitter +
-  %    \begin{figure} +
-  %        \includegraphics[height=20cm]{another-image-file} +
-  %    \end{figure} +
-  %    \end{frame} +
-   +
-  ​\foreach \n in {1,​...,​11}{ +
-      \begin{frame} +
-      \transduration{1.5} % Duration between slides +
-      \transglitter % Transition effect +
-  %    \includegraphics{logo}\hspace{2cm} % Optional: add a logo at the top of each slide +
-      {\LARGE\textbf{Here is a header for each page}}\newline +
-      \begin{figure} +
-          \includegraphics[height=14cm]{images/​\n} +
-      \end{figure} +
-      Here is some small footer text +
-      \end{frame} +
-  } +
-   +
-  \end{document}+
  
-Run the script. ​<tt>xelatex</​tt> ​is used so that fonts can be used:+\end{document} 
 +</​code>​ 
 +Run the script. ​''​%%xelatex%%'' ​is used so that fonts can be used:
  
-  xelatex slides.tex+''​%%xelatex slides.tex%%''​
  
-This will produce ​<tt>slides.pdf</tt>. This file can be opened with Adobe Acrobat and shown in full screen to see the slideshow with transitions. As much as I dislike the proprietary Adobe viewer, it does show the slideshow well, which not many other PDF viewers seem to support.+This will produce ​''​%%slides.pdf%%''​. This file can be opened with Adobe Acrobat and shown in full screen to see the slideshow with transitions. As much as I dislike the proprietary Adobe viewer, it does show the slideshow well, which not many other PDF viewers seem to support.
  
latexslideshow.1544125995.txt.gz · Last modified: 2018/12/06 19:53 by abeverley