Using Powershell to clean up the animations your LaTeX file

In a previous post, I talked how to animate your Beamer presentations and how to print them as slides and article for the audience. One problem with a presentation with animations is that every element of an animation means one more slide. If you want to give the presentation to the audience so they can write on their slides using their ipad or touch screen notebook, they will complain that only one of the animated slides is complete.

The easiest way to remedy this, replace all overlays, \pause, etc. from your LaTeX file and print it like this. One could do this easily in Emacs and write a macro for this. This time I chose another way to do this using Powershell, the awesome windows scripting language.

First, I define a function that will show me a file picker. Then I will use this file picker to get the LaTeX-file that should be cleaned up. From the file chosen, I save the path in a variable $FolderPath and get the name of the file. This information is used to save the file as the original name with “_NA” (for no animation).

Then I read the content and replace all occurences of \pause, <+-.> <digit-> and \only by a space using regular expressions. After this I save the file in the original place using the _NA-addition. The only thing I had problems with was the encoding (Powershell saved it in the wrong format), so I had to add “–Encoding Default” as option.

That’s all. Of course, this could be done with any scripting language.

Scripts for automating commits and updates with Subversion

Version control is good, but there are two possible pitfalls for me:
  1. In the morning, it can happen that I start working without updating my project. If this is a project I worked on, on  another computer the day before, as soon as I want to commit the new changes, I will have to merge all the changes in one file. Not a big issue, but unnessary work.
  2. Before I leave the office, I unfortunately often forget to commit.
 
I wrote a commit batch file that runs every two hours,  but the problem was that I manually had to define in which directories the batch file should look and, if there was nothing to commit, I still had to click the commit window away (if you have about 30 open projects, that isn’t much fun).
I decided to improve my batch file: It should automatically generate a list of all the root directories of projects under version control and then check if there is something to commit. If there is nothing to commit, the batch file should just continue without showing me the commit window.
 
One hour of surfing and my rudimentary powershell knowledge resulted in two small scripts that check for projects should be committed and should be updated. In order to run these scripts, you need a Windows computer and the command line utilities for Subversion (they are usually installed if you use TortoiseSVN). I think that a script like this can also be written in other scripting languages and for other operating systems.
If you want to run it on your computer, you will have to adjust the abolute paths in the scripts to your settings.
 
 
The commit script (svncommit.ps1):
 
 
Remarks:
  • Line 1: Changing to the root directory of my data drive with all my projects
  • Line 2: Here we look for .svn folders (subversion puts them in the root directory of a project. Powershell looks in all folders if there is a subfolder with this name (it continues if it encounters system directories) and saves the path of these directories in the file svn.txt.
  • Line 5-14: In the for loop, I loop through every project root directory, check the subversion status, write the result once again to a file (status.txt) and check  if it is not empty: if it is not empty, it does a commit.
  • I save the files svn.txt and status.txt in a directory that is not under version control, so it is not around when I check for changes in the project directory.
  • This script runs every two hours on my computers.
 
The update script (svnupdate.ps1) is also short and simple
 
 
 
It hast the same first two lines as the commit script. With the subversion update option /closeonend:2, only projects that are not up-to-date will be updated.