LaTeXML

 view release on metacpan or  search on metacpan

lib/LaTeXML/Package/psfrag.sty.ltxml  view on Meta::CPAN

# -*- mode: Perl -*-
# /=====================================================================\ #
# |  psfrag                                                             | #
# | Implementation for LaTeXML                                          | #
# |=====================================================================| #
# | Part of LaTeXML:                                                    | #
# |  Public domain software, produced as part of work done by the       | #
# |  United States Government & not subject to copyright in the US.     | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov>                        #_#     | #
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Package::Pool;
use strict;
use warnings;
use LaTeXML::Package;
use LaTeXML::Util::Image;

#======================================================================
# Would be lovely to overlay SVG, MathML, Images etc
# but kinda impractical to hope to align things the same way as LaTeX would.
# So, we just punt all of it to LaTeX to create a composite image

# Store fragments for later use
AssignValue(saved_psfragments => Tokens());
AssignValue(psfrag_scan_all   => LookupValue('2.09_COMPATIBILITY'));
AssignValue(psfrag_scan       => 0);
DeclareOption('209mode', sub { AssignValue(psfrag_scan_all => 1); });
DeclareOption('2emode',  sub { AssignValue(psfrag_scan_all => 0); });
DeclareOption('scanall', sub { AssignValue(psfrag_scan_all => 1); });

ProcessOptions();

sub save_psfrag {
  my (@stuff) = @_;
  return unless @stuff;
  # NOT global!!!  And defer expansion of the leading CS
  AssignValue(saved_psfragments =>
      Tokens(LookupValue('saved_psfragments')->unlist, T_CS('\noexpand'), @stuff));
  return; }

sub unsave_psfrag {
  return Tokens(Digest(LookupValue('saved_psfragments'))->revert); }

# NOT a constructor since probably args should not be digested yet(?)
DefPrimitive('\psfrag OptionalMatch:* Semiverbatim [][][][]{}', sub {
    my ($stomach, $star, $a, $b, $c, $d, $e, $f) = @_;
    # Guard against empty $$ argument.
    my @argt = $f->unlist;
    if ((scalar(@argt) == 2) && ($argt[0][1] == CC_MATH) && ($argt[1][1] == CC_MATH)) {
      $f = Tokens(); }
    save_psfrag(Invocation(T_CS('\lx@delayed@psfrag'), $star, $a, $b, $c, $d, $e, $f));
    return; });
DefConstructor('\lx@delayed@psfrag OptionalMatch:* Semiverbatim [][][][]{}', '',
  alias => '\psfrag');

DefConstructor('\psfragscanon', '',
  afterDigest => sub {
    save_psfrag(T_CS('\psfragscanon'));
    AssignValue(psfrag_scan => 1); });
DefConstructor('\psfragscanoff', '',
  afterDigest => sub {
    save_psfrag(T_CS('\psfragscanoff'));
    AssignValue(psfrag_scan => 0); });

# AVOID using ltx:picture instead of ltx:graphic
# unless there actually are some psfrags defined, OR embedded fragments was explicitly enabled.
# (faster, probably more reliable image conversion)
sub psfrag_requirepicture {
  my (@candidates) = @_;
  my $have_ps = 0;
  if (scalar(@candidates) == 1) {
    my $type = image_type(pathname_absolute($candidates[0], LookupValue('SOURCEDIRECTORY')));
    $have_ps = ($type eq 'ps') || ($type eq 'eps'); }
  my $have_frags = scalar(LookupValue('saved_psfragments')->unlist);
  my $scan_on    = LookupValue('psfrag_scan') || LookupValue('psfrag_scan_all');
  return $have_ps && ($have_frags || $scan_on); }

# For graphics version of \includegraphics
DefConstructor('\lx@psfrag@includegraphics OptionalMatch:* [][] Semiverbatim',



( run in 1.275 second using v1.01-cache-2.11-cpan-f56aa216473 )