LaTeXML
view release on metacpan or search on metacpan
perl Makefile.PL
make
make test
make install
REQUIREMENTS
A sufficiently Unicode supporting Perl: 5.8, maybe 5.6
XML::LibXML and XML::LibXSLT (See www.CPAN.org)
(which require libxml2 and libxslt: See http://www.xmlsoft.org/)
Parse::RecDescent
Image::Magick
lib/LaTeXML/Post/LaTeXImages.pm view on Meta::CPAN
#**********************************************************************
# Check whether this processor actually has the resources it needs to process.
# I don't know if there's a general API implied here;
# It could, conceivably be use in planning post processing?
# But generally, before signalling an error, you'd want to know that the processor
# is even needed.
# This test is called once we know that, from within
#
# At any rate: To process LaTeX snippets into images, we will need
# * latex (or related) from a TeX installation
# * Image::Magick (or similar) [see LaTeXML::Util::Image]
sub canProcess {
my ($self) = @_;
# Check if we have Image::Magick (or similar)
if (!image_can_image()) {
Error('expected', 'Image::Magick', undef,
"No available image processing module found; Skipping.",
"Please install one of: " . join(',', image_classes()));
return; }
# AND check if we have an approriprate latex!!!
if (($LATEXCMD =~ /^(\S+)/) && !which($1)) { # does the command seem to be available?
Error('expected', $LATEXCMD, undef,
"No latex command ($LATEXCMD) found; Skipping.",
"Please install TeX to generate images from LaTeX");
return; }
return 1; }
lib/LaTeXML/Util/Image.pm view on Meta::CPAN
use base qw(Exporter);
our @EXPORT = (
qw( &image_candidates &image_type &image_size ),
qw( &image_classes &image_can_image &image_object ),
qw( &image_write ),
qw( &image_graphicx_parse &image_graphicx_is_trivial &image_graphicx_trivialize
&image_graphicx_size &image_graphicx_trivial &image_graphicx_complex),
qw( &image_graphicx_sizer),
);
# The initial idea here is to form a minimal interface to image operations
# and to shield LaTeXML from the 'unreliable' Image::Magick;
# Namely, it is hard to rely on as a dependency, since it is often
# difficult to port, or has mismatched versions or whatever.
# We do, at least, need to be able to get image size.....
our $DPI = 100; # [CONSTANT]
our $BACKGROUND = "#FFFFFF"; # [CONSTANT]
# Return cleaned-up path and list of candidate image files
# {We could, but dont, filter out non-image types, since extensions are so inconsistent.
# although we could query image_type which is more thorough)
lib/LaTeXML/Util/Image.pm view on Meta::CPAN
# when ghostscript becomes involved in converting postscript or pdf.
# HOWEVER, there are indications that the time limit (at least)
# is being measured against the whole latexml process, not just image processing.
# Thus they aren't really that useful here.
# They probably are useful in a server context, however, so I'll leave the comments.
# $ENV{MAGICK_DISK_LIMIT} = "2GiB" unless defined $ENV{MAGICK_DISK_LIMIT};
# $ENV{MAGICK_MEMORY_LIMIT} = "512MiB" unless defined $ENV{MAGICK_MEMORY_LIMIT};
# $ENV{MAGICK_MAP_LIMIT} = "1GiB" unless defined $ENV{MAGICK_MAP_LIMIT};
# $ENV{MAGICK_TIME_LIMIT} = "300" unless defined $ENV{MAGICK_TIME_LIMIT};
# Note that Image::Size may, itself, use Image::Magick, if available,
# as a fallback for getting image size & type!!!
# However, it seems not to recognize file types with extension .EPS (uppercase), eg!
sub image_type {
my ($pathname) = @_;
my ($w, $h, $t) = imgsize($pathname);
# even though Image::Size CLAIMS to use Image::Magick as fallback... needs tickling?
if (!(defined $w) && !(defined $h) && image_can_image()) { # try harder!
my $image = image_read($pathname) or return;
($t) = image_getvalue($image, 'format'); }
# Note that Image::Magick (sometimes) returns "descriptive" types
# (but I can't find a list anywhere!)
$t = 'eps' if $t && $t =~ /postscript/i;
return (defined $t ? lc($t) : undef); }
sub image_size {
my ($pathname) = @_;
# Annoyingly, ImageMagick uses the MediaBox instead of CropBox (as does graphics.sty) for pdfs.
# Worse, imgsize delegates to ImageMagick, w/o ability to add options
if (($pathname =~ /\.pdf$/i) && image_can_image()) {
my $image = image_read($pathname) or return;
return image_getvalue($image, 'width', 'height'); }
my ($w, $h, $t) = imgsize($pathname);
return ($w, $h) if $w && $h;
if (image_can_image()) { # try harder!
my $image = image_read($pathname) or return;
return image_getvalue($image, 'width', 'height'); } }
# This will be set once we've found an Image processing library to use [Daemon safe]
our $IMAGECLASS; # cached class if we found one that works. [CONFIGURABLE?]
my @MagickClasses = (qw(Graphics::Magick Image::Magick)); # CONSTANT
sub image_classes {
return @MagickClasses; }
sub image_can_image {
my ($pathname) = @_;
if (!$IMAGECLASS) {
foreach my $class (@MagickClasses) {
my $module = $class . ".pm";
$module =~ s/::/\//g;
lib/LaTeXML/Util/Image.pm view on Meta::CPAN
Error('imageprocessing', 'getvalue', undef, "No image object!"); return; }
my @values = $image->Get(@args);
return @values; }
sub image_setvalue {
my ($image, @args) = @_;
if (!$image) {
Error('imageprocessing', 'setvalue', undef, "No image object!"); return; }
return image_internalop($image, 'Set', @args); }
# Apparently ignorable warnings from Image::Magick
our %ignorable = map { $_ => 1; } (
350, # profile 'icc' not permitted on grayscale PNG
);
sub image_internalop {
my ($image, $operation, @args) = @_;
if (!$image) {
Error('imageprocessing', 'internal', undef, "No image object!"); return; }
my $retval = $image->$operation(@args);
return 1 unless $retval;
t/003_unit_imagemagick.t view on Meta::CPAN
#======================================================================
# Unit test for LaTeXML's optional image conversion capability
#======================================================================
use Test::More;
BEGIN { use_ok('LaTeXML::Util::Image'); }
my $image_converter = image_object();
my $is_image_magick = $image_converter && ((ref $image_converter) eq "Image::Magick");
if (!$is_image_magick) {
diag("Skip: This unit test only examines basic Image::Magick conversion, when installed."); }
else {
# try converting a sample PDF image
my $pdf_image = "t/unit/triangle.pdf";
my $png_target = "t/unit/triangle.png";
my $conversion_ok = 0;
if (image_type($pdf_image) eq "portable document format") {
my ($loaded_image, $w, $h) = image_graphicx_complex($pdf_image, []);
if (ref $loaded_image eq "Image::Magick" and $w > 0 and $h > 0) {
image_write($loaded_image,$png_target);
if (-f $png_target) {
# if we *can* convert, make sure the PNG has some size
ok((-s $png_target) > 0,
"PDF to PNG conversion did not produce an image of non-zero size");
unlink($png_target) if -f $png_target;
$conversion_ok = 1; } } }
if (!$conversion_ok) {
# if we *can't* convert, and Image::Magick is installed, warn about the config issues.
diag("Image::Magick is installed, but a simple PDF to PNG conversion fails.\n"
. "\tConsider changing the policy.xml permissions to enable the feature.\n"
. "\tFor details, see https://github.com/brucemiller/LaTeXML/issues/1216"); } }
done_testing();
( run in 1.859 second using v1.01-cache-2.11-cpan-beeb90c9504 )