summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/support/latexmk/example_rcfiles/asymptote_latexmkrc
blob: 7a7425ff47e32c537cd8e08e7ccc4b921136133e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# This shows how to use Asymptote (http://asymptote.sourceforge.net/,
# or http://www.ctan.org/pkg/asymptote/)
# with latexmk.  Asymptote is a vector graphics language with a
# processing program that generates graphics files that can be used in
# a LaTex file.  
#
# A standard method of using it is with the asymptote LaTeX style file
# (http://mirror.ctan.org/graphics/asymptote/doc/asymptote.sty)
# The graphics drawing code is in the tex file, and applying pdflatex to
# the tex file produces one or more files with a base name the same as
# or related to the main tex file, but with the extension 'asy'.  The
# .asy is processed by the program asy (part of the asymptote
# software) to produce graphics files (which may be eps, tex, or pdf
# files) that are used the next time pdflatex is run on the main tex
# file.    
#
# Latexmk can be arranged to run asymptote (i.e., the program asy)
# when needed, by defining the following custom dependency.  (The code
# is to be put in one of latexmk's rc files, e.g., ~/.latexmkrc.)
#

## OLD simple method (taken from the documentation for V. 2.03 of
## asymptote).  These definitions are simple, but they may not always
## give the desired type of output file, and they do not ensure that
## latexmk has dependency information about files imported from the
## asy file.
#OLD sub asy {return system("asy \"$_[0]\"");}
#OLD add_cus_dep("asy","eps",0,"asy");
#OLD add_cus_dep("asy","pdf",0,"asy");
#OLD add_cus_dep("asy","tex",0,"asy");


# The following definitions arrange to run asy with the correct output
# file type.  They run asy in a verbose mode so that dependency
# information on imported files can be extracted.  To avoid adding a
# lot of extra printout on the screen of unimportant messages, the
# output is sent to a log file.  Since this includes error messages,
# which the user should see, latexmk types out error messages and the
# like. These definitions need latexmk 4.48 or later.

add_cus_dep("asy","eps",0,"asy2eps");
add_cus_dep("asy","pdf",0,"asy2pdf");
add_cus_dep("asy","tex",0,"asy2tex");

sub asy2eps { return asy2x( $_[0], 'eps' ); }
sub asy2pdf { return asy2x( $_[0], 'pdf' ); }
sub asy2tex { return asy2x( $_[0], 'tex' ); }

sub asy2x   {
   my $ret = system("asy -vv -f '$_[1]' '$_[0]' >& '$_[0].log'");
   open( my $FH, "<", "$_[0].log" );
   %imp = ();

   while (<$FH>) {
       if (/^(Including|Loading) .* from (.*)\s*$/) {
          my $import = $2;
	  $imp{$import} = 1;
       }
       elsif ( /^error/ || /^.*\.asy: \d/ ) {
           warn "==Message from asy: $_";
	   $ret = 1;
       }
       elsif ( /^kpsewhich / || /^Processing / || /^Using /
               || /^Welcome / || /^Wrote /|| /^cd /|| /^gs /
	     ) {
       }
       else {
           warn "==Message from asy: $_";
       }
   }
   close $FH;
# For latexmk 4.48
   rdb_set_source( $rule, keys %imp );
   return $ret;
}