Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/LaTeXML/Post.pm
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,14 @@ sub getSiteDirectory {
my ($self) = @_;
return $$self{siteDirectory}; }

sub findGraphicsPaths {
my ($self) = @_;
my @paths = ();
foreach my $pi ($self->findnodes('.//processing-instruction("latexml")')) {
if ($pi->textContent =~ /^\s*graphicspath\s*=\s*([\"\'])(.*?)\1\s*$/) {
push(@paths, $2); } }
return @paths; }

# Given an absolute pathname in the document destination directory,
# return the corresponding pathname relative to the site directory (they maybe different!).
sub siteRelativePathname {
Expand Down
8 changes: 2 additions & 6 deletions lib/LaTeXML/Post/Graphics.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sub new {
$$self{trivial_scaling} = $options{trivial_scaling} || 1;
$$self{graphics_types} = $options{graphics_types}
|| [qw(svg png gif jpg jpeg
eps ps postscript ai pdf)];
eps ps postscript ai pdf)];
$$self{type_properties} = $options{type_properties}
|| {
ai => { destination_type => 'png',
Expand Down Expand Up @@ -120,11 +120,7 @@ sub getParameter {
# to a list of search paths.
sub findGraphicsPaths {
my ($self, $doc) = @_;
my @paths = ();
foreach my $pi ($doc->findnodes('.//processing-instruction("latexml")')) {
if ($pi->textContent =~ /^\s*graphicspath\s*=\s*([\"\'])(.*?)\1\s*$/) {
push(@paths, $2); } }
return @paths; }
return $doc->findGraphicsPaths; }

sub getGraphicsSourceTypes {
my ($self) = @_;
Expand Down
27 changes: 20 additions & 7 deletions lib/LaTeXML/Post/LaTeXImages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ our $LATEXCMD = 'latex'; #(or elatex) [ CONFIGURABLE? Encoded in PI?]
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(%options);
$$self{cmd} = $LATEXCMD;
$$self{magnification} = $options{magnification} || 1.33333;
$$self{maxwidth} = $options{maxwidth} || 800;
$$self{DPI} = $options{DPI} || 100;
Expand Down Expand Up @@ -130,9 +131,9 @@ sub canProcess {
"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.",
if (($$self{cmd} =~ /^(\S+)/) && !which($1)) { # does the command seem to be available?
Error('expected', $$self{cmd}, undef,
"No latex command ($$self{cmd}) found; Skipping.",
"Please install TeX to generate images from LaTeX");
return; }
return 1; }
Expand Down Expand Up @@ -200,6 +201,10 @@ sub cleanTeX {

sub generateImages {
my ($self, $doc, @nodes) = @_;
local $LaTeXML::Post::Graphics::SEARCHPATHS
= [map { pathname_canonical($_) } $doc->findGraphicsPaths, $doc->getSearchPaths];
Debug(" [Using graphicspaths: "
. join(', ', @$LaTeXML::Post::Graphics::SEARCHPATHS) . "]") if $LaTeXML::DEBUG{images};

my $jobname = "ltxmlimg";
my $orig_cwd = pathname_cwd();
Expand Down Expand Up @@ -268,15 +273,16 @@ sub generateImages {
print $TEX $add_to_body if $add_to_body;

foreach my $entry (@pending) {
## print TEX "\\fbox{$$entry{tex}}\\clearpage\n"; }
# Heuristic: .pdf mention requires pdflatex to build
# $$self{cmd} = 'pdflatex' if $entry =~ /\.pdf/;
print $TEX "$$entry{tex}\\clearpage\n"; }
print $TEX "\\end{document}\n";
close($TEX);

# === Run LaTeX on the file.
# (keep the command simple so it works in Windows)
pathname_chdir($workdir);
my $ltxcommand = "$LATEXCMD $jobname > $jobname.ltxoutput";
my $ltxcommand = "$$self{cmd} $jobname > $jobname.ltxoutput";
my $ltxerr;
{
local $ENV{TEXINPUTS} = join($sep, '.', @searchpaths,
Expand All @@ -288,9 +294,9 @@ sub generateImages {

# Sometimes latex returns non-zero code, even though it apparently succeeded.
# And sometimes it doesn't produce a dvi, even with 0 return code?
if (($ltxerr != 0) || (!-f "$workdir/$jobname.dvi")) {
if (($ltxerr != 0) || ($$self{cmd} eq 'latex' && !-f "$workdir/$jobname.dvi")) {
$workdir->unlink_on_destroy(0) if $LaTeXML::DEBUG{images}; # Preserve junk
Error('shell', $LATEXCMD, undef,
Error('shell', $$self{cmd}, undef,
"LaTeX command '$ltxcommand' failed",
($ltxerr == 0 ? "No dvi file generated" : "returned code $ltxerr (!= 0): $@"),
($LaTeXML::DEBUG{images}
Expand Down Expand Up @@ -422,6 +428,12 @@ sub pre_preamble {
$result_add_to_body .= "\\title{}\\date{}\n"; }
$result_add_to_body .= "\\makeatother\n";

# Check for graphicspaths
my $graphicspaths = '';
if (@$LaTeXML::Post::Graphics::SEARCHPATHS) {
$graphicspaths = "\\graphicspath{" . join(',', @$LaTeXML::Post::Graphics::SEARCHPATHS) . "}\n";
}

my $result_preamble = <<"EOPreamble";
\\batchmode
\\def\\inlatexml{true}
Expand Down Expand Up @@ -466,6 +478,7 @@ $packages
}%
\\def\\lxBeginImage{\\setbox\\lxImageBox\\hbox\\bgroup\\color\@begingroup\\kern\\lxImageBoxSep}
\\def\\lxEndImage{\\kern\\lxImageBoxSep\\color\@endgroup\\egroup}
$graphicspaths
$preambles
\\makeatother
EOPreamble
Expand Down