Replacement for LaTeXiT on Linux
Like several others, I have been searching for a suitable replacement for the great program LaTeXiT, which only runs on Mac OS X. Alternatives I found were:
  1. The package texgd provides a command that outputs a given formula as a PNG file; not quite what I wanted.
  2. The Ekee equation editor has all the functionality I need; unfortunately, this great software is quite unstable on my system and it is no longer maintained.
  3. This little bash script (web-link defunct) does a good job; I used it as a basis for mine, which implements additional features.
  4. The program KLatexFormula is another LaTeXiT clone, but it's not very mature yet.
  5. The same applies to latexyt.
My Solution
The script latexit on the bottom of this page can be evoked in 4 different ways (options 1 and 2 originate from the script mentioned in point 3 above):

  1. by giving a formula to typeset, e.g.

    ./ 1+1=2

  2. by giving the name of a file that contains the formula, e.g.

    ./ my_equation.txt

    where the contents of my_equation.txt are


    Note that the formula-file is removed, as its contents will be stored in the PDF (see below).

  3. by giving the name of a PDF file with a previously typeset formula (using the latexit script), e.g.

    ./ my_equation.pdf

    (You will be prompted with an editor where you can make changes to the formula.)

  4. without any arguments, i.e.


    (You will be prompted with an editor where you can enter a formula.)

In any of these cases the output is a PDF file, which contains the typeset formula with the essential LaTeX commands attached to it. Similar to LaTeXiT, formulas can thereby be re-edited at a later point without having to enter the formula again; it is automatically extracted from the PDF and displayed in your favourite editor. (Note: The pdftk package must be installed.)

If you prefer a bit of GUI functionality, you can create a GNOME Desktop Launcher to call the script. Clicking it evokes the script without arguments (option 4). Alternatively, you can drag and drop formula files (option 2) or formula PDFs (option 3) onto the launcher icon. (The output PDF is placed in the same directory as the original one.)

The output of the script is minimal and you will only be confronted with longer messages if something goes wrong. In that case, (temporary) files are not removed, so you can examine the problem. Otherwise, all you find at the end of a successful run is the PDF.
Please, let me know if...
  1. you know further alternatives to LaTeXiT on Linux,
  2. have problems in using or suggestions on improvements to my script, or
  3. simply enjoy using it ;-)

    My name is Chris and you can reach me by removing all underscores from
The Script
# last modified: Feb 2012
#    + now using editor according to "$EDITOR" (if defined) [thanks to Christopher M.]
#    + added more explanatory comments

# if no default editor is defined, choose vi
if [ -z "$EDITOR" ]; then

# set default file-names, which may be overwritten

# if no arguments given, open empty file in editor
if [ $# -eq 0 ]; then

   $EDITOR "$formula_file"


   # test whether given argument is a file
   if [ -f "$may_be_a_file" ]; then

      cd "$(dirname "$is_a_file")"
      if [ "${is_a_file: -4}" == ".pdf" ]; then
         # file is a PDF; extract attached fomular (if any)
         echo "Extracting formula from PDF..."
         tmp_dir=$(mktemp -d)
         pdftk "$pdf_input_file" unpack_files output "$tmp_dir"
         if [ -f "$tmp_dir/formula.txt" ]; then
            mv "$tmp_dir/formula.txt" "$formula_file"
            rm -r "$tmp_dir"
$EDITOR "$formula_file"
            echo "Error: PDF has no formula attached to it."
            exit -1
         # file is not a PDF; assume it contains the formula

   else # if argument is not a file, assume it's a fomular

      echo "$*" > "$formula_file"

# rename output-file, if exists; will be deleted later, if no errors occur
(test -f "$outfile") && mv "$outfile" latexit.$$.pdf.old

# create minimal LaTeX wrapper for the formular
echo "\documentclass{article} \usepackage[landscape]{geometry} \begin{document} \pagestyle{empty} \[" > latexit.$$.tex
cat "$formula_file" >> latexit.$$.tex
echo "\]\end{document}" >> latexit.$$.tex

# run pdflatex
echo "Typesetting formula..."
pdflatex latexit.$$.tex > latexit.$$.err
pdfcrop latexit.$$.pdf "$outfile" >> latexit.$$.err

# check if output-PDF has been generated
if [ -f "$outfile" ]; then
   echo "Attaching formula to PDF..."
   tmp_dir=$(mktemp -d)
   mv "$formula_file" "$tmp_dir/formula.txt"
   mv "$outfile" latexit.$$.pdf
   pdftk latexit.$$.pdf attach_files "$tmp_dir/formula.txt" output "$outfile"
   # clean up
   rm -f latexit.$$.???
   rm -f latexit.$$.???.???
   rm -r "$tmp_dir"
else # display error messages
   echo "==================== ERROR ===================="
   cat latexit.$$.err
   cat latexit.$$.log
   echo "==============================================="
   read -p "[press enter]"