summary refs log tree commit diff
path: root/pkgs/misc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2007-03-12 18:06:31 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2007-03-12 18:06:31 +0000
commit1c65a5b3287cc8a3c0c3e6796d0df1370bffdebd (patch)
tree86b09b0d10b93bf363545955e7e9db2289a0e97a /pkgs/misc
parentead48be2296a47a8533b1854792f354cc2c1337a (diff)
downloadnixlib-1c65a5b3287cc8a3c0c3e6796d0df1370bffdebd.tar
nixlib-1c65a5b3287cc8a3c0c3e6796d0df1370bffdebd.tar.gz
nixlib-1c65a5b3287cc8a3c0c3e6796d0df1370bffdebd.tar.bz2
nixlib-1c65a5b3287cc8a3c0c3e6796d0df1370bffdebd.tar.lz
nixlib-1c65a5b3287cc8a3c0c3e6796d0df1370bffdebd.tar.xz
nixlib-1c65a5b3287cc8a3c0c3e6796d0df1370bffdebd.tar.zst
nixlib-1c65a5b3287cc8a3c0c3e6796d0df1370bffdebd.zip
* A function `simpleTeXToPNG' that typesets a piece of LaTeX code
  (e.g., a file containing something like `$x^2 + y^2 = z^2$') and
  converts it to a PNG image with no unnecessary surrounding
  whitespace.  Useful when you want to include TeX stuff in webpages /
  other documents.

  This currently calls /usr/bin/convert, so we should add ImageMagick.

svn path=/nixpkgs/trunk/; revision=8269
Diffstat (limited to 'pkgs/misc')
-rw-r--r--pkgs/misc/tex/nix/default.nix79
1 files changed, 79 insertions, 0 deletions
diff --git a/pkgs/misc/tex/nix/default.nix b/pkgs/misc/tex/nix/default.nix
index f28348058188..54fb512c8906 100644
--- a/pkgs/misc/tex/nix/default.nix
+++ b/pkgs/misc/tex/nix/default.nix
@@ -84,4 +84,83 @@ rec {
     inherit dotGraph nrFrames;
   };
 
+
+  # Wrap a piece of TeX code in a document.  Useful when generating
+  # inline images from TeX code.
+  wrapSimpleTeX =
+    { preamble ? null
+    , body
+    , name ? baseNameOf (toString body)
+    }:
+
+    pkgs.stdenv.mkDerivation {
+      inherit name preamble body;
+      buildCommand = "
+        touch $out
+        echo '\\documentclass{article}' >> $out
+        echo '\\pagestyle{empty}' >> $out
+        if test -n \"$preamble\"; then cat $preamble >> $out; fi
+        echo '\\begin{document}' >> $out
+        cat $body >> $out
+        echo '\\end{document}' >> $out
+      ";
+    };
+
+
+  # Convert a Postscript file to a PNG image, trimming it so that
+  # there is no unnecessary surrounding whitespace.    
+  postscriptToPNG =
+    { postscript
+    }:
+
+    pkgs.stdenv.mkDerivation {
+      name = "png";
+      inherit postscript;
+      
+      buildCommand = "
+        if test -d $postscript; then
+          input=$(ls $postscript/*.ps)
+        else
+          input=$(stripHash $postscript; echo $strippedName)
+          ln -s $postscript $input
+        fi
+
+        # !!! Quick hack: no ImageMagick in Nixpkgs yet!
+        export PATH=/usr/bin:$PATH
+        ensureDir $out
+        convert -units PixelsPerInch \\
+          -density 300 \\
+          -trim \\
+          -matte \\
+          -transparent '#ffffff' \\
+          -type PaletteMatte \\
+          +repage \\
+          $input \\
+          \"$out/$(basename $input .ps).png\"
+      ";
+    };
+
+
+  # Convert a piece of TeX code to a PNG image.
+  simpleTeXToPNG =
+    { preamble ? null
+    , body
+    , name ? baseNameOf (toString body)
+    , packages ? []
+    }:
+
+    postscriptToPNG {
+      postscript = runLaTeX {
+        rootFile = wrapSimpleTeX {
+          inherit body preamble;
+        };
+        inherit packages;
+        generatePDF = false;
+        generatePS = true;
+        searchRelativeTo = dirOf (toString body);
+      };
+    };
+
+
+      
 }