-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtricktex
executable file
·261 lines (248 loc) · 7.73 KB
/
tricktex
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#! /usr/bin/perl -w
#
# Copyright (C) 2007-2015 Christoph Junghans
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#version 0.42 added --keep option
#version 0.43 added --pic option
#version 0.44 added --pdf option
#version 0.45 added -gv option
#version 0.46 change style to test as standard
#version 0.47 change --pic output to .ps
#version 0.48 added -w option
#version 0.49 better short opts
#version 0.50 added -watch to gv
#version 0.51 removed Base name
#version 0.52 added --rotate
#version 0.53, 18.04.08 -- added --tight and change default behavious
#version 0.54, 25.04.08 -- better version
#version 0.55, 13.10.08 -- added GPL header
#version 0.5.6, 19.05.11 -- removed --pdf option
#version 0.5.7, 08.05.13 -- fixed a bug in -o extension detection
#version 0.5.8, 19.08.13 -- added --output(=-o), fail if output is in pics
#version 0.5.9, 20.09.13 -- make -t, --view work again
#version 0.6.0, 13.03.15 -- moved issue tracker to github
use strict;
$_=$0;
s#^.*/##;
my $progname=$_;
my $usage="Usage: $progname [OPTIONS] tex code";
my $output="myfile";
my $ending="eps";
my @packages;
my $equ=undef;
my $keep=undef;
my $pic=undef;
my $pdf=undef;
my $tight=undef;
my $nrpic=0;
my $viewer=undef;
my $textwidth=1.0;
my $angle=0;
while ((defined ($ARGV[0])) and ($ARGV[0] =~ /^\-/))
{
if (($ARGV[0] !~ /^--/) and (length($ARGV[0])>2)){
$_=shift(@ARGV);
if ( $_ =~ /^-[opw]/ ) {
unshift(@ARGV,substr($_,0,2),substr($_,2));
}
else{
unshift(@ARGV,substr($_,0,2),"-".substr($_,2));
}
}
if (($ARGV[0] eq "-h") or ($ARGV[0] eq "--help"))
{
print <<END;
$usage
Make a eps or ps file out of a tex code
Options:
-v, --version Prints version
-h, --help Show this help message
-p NAME Add package
-o, --output FILE Give the output filename. The default is '$output.$ending'
--equ Run in equation mode
--keep Do not delete the tex file
--pic Run in Picture mode
-t, --tight tight bounding (uses bbbox_add.pl)
-w, --width NUMBER Change textwidth of the pictures (implies --pic)
The default is $textwidth (*\\textwidth)
-r, --rotate rotate pics by 90 degree
--view VIEWER Run VIEWER at the end
Examples:
$progname --equ -o test.eps \'\\omega\' Create an omega symbol in test.eps
$progname --equ -o test \\\\omega Create an omega symbol in '$output.$ending'
$progname --equ -p color '\\textcolor{blue}{\\theta}\' Create a blue theta symbol in '$output.$ending'
$progname hallo Create a "hallo" in '$output.$ending'
$progname --pic *.eps Combine all eps picture into '$output.$ending'
Report bugs and comments at https://github.com/junghans/gnuplotutils/issues or junghans\@votca.org
END
exit;
}
elsif (($ARGV[0] eq "-o") or ($ARGV[0] eq "--width")){
shift(@ARGV);
$output=shift(@ARGV);
}
elsif ($ARGV[0] eq "-p")
{
shift(@ARGV);
push(@packages,shift(@ARGV));
}
elsif ($ARGV[0] eq "--equ")
{
shift(@ARGV);
$equ='yes';
}
elsif ($ARGV[0] eq "--keep")
{
shift(@ARGV);
$keep='yes';
}
elsif ($ARGV[0] eq "--pic")
{
shift(@ARGV);
$pic='yes';
}
elsif (($ARGV[0] eq "-w") or ($ARGV[0] eq "--width"))
{
shift(@ARGV);
$pic='yes';
$textwidth=shift(@ARGV);
}
elsif (($ARGV[0] eq "-r") or ($ARGV[0] eq "--rotate"))
{
shift(@ARGV);
$pic='yes';
$angle=90;
}
elsif (($ARGV[0] eq "--tight") or ($ARGV[0] eq "-t"))
{
shift(@ARGV);
$tight='yes';
}
elsif ($ARGV[0] eq "--view")
{
shift(@ARGV);
$viewer=shift(@ARGV);
}
elsif (($ARGV[0] eq "-v") or ($ARGV[0] eq "--version"))
{
my $version=`$^X -ne 'print "\$1\n" if /^#version (.*?) --/' $0 | $^X -ne 'print if eof'`;
chomp($version);
print "$progname $version\n\n";
system("$^X -ne 'print \$1 if /^# (Copyright.*)/;' $0");
print "\nThis is free software: you are free to change and redistribute it.\n";
print "License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl2.html>\n";
print "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
print "Written by C. Junghans <junghans\@votca.org>\n";
exit;
}
elsif ($ARGV[0] eq "--vcs")
{
my $message=`$^X -ne 'print "\$1\n" if /^#version .*? -- (.*)\$/' $0 | $^X -ne 'print if eof'`;
chomp($message);
print "$progname: $message\n";
exit;
}
else
{
print "Unknow option '".$ARGV[0]."' ignored !\n";
shift(@ARGV);
}
}
die "${usage}Error: no tex code given\nHelp with --help\n" unless $#ARGV>-1;
die "What do you want equ or pic mode?\nCheat the text mode with \$something\$ !\n" if ($pic and $equ);
if ( $output =~ /^.*\.(.*?)$/){
$ending=$1;
die "Can not handle this ending ($ending)!\n" unless (($ending eq "eps")or($ending eq "ps")or($ending eq "pdf"));
}else{
print "No ending given use .eps\n";
$ending="eps";
$output="$output.eps";
}
my $ending2="$ending";
$ending2="eps" if ( $ending eq "pdf");
my $trunc;
if ( $output =~ /^(.*)\.$ending$/){
$trunc=$1;
}else{
die "Could not get trunc from $output\n";
}
open(FILE,"> $trunc.tex") or
die "Error at opening file\n";
print FILE '\documentclass[10pt,a4paper,onecolumn]{article}'."\n";
print FILE '\usepackage{amsmath}'."\n" if ($equ);
print FILE '\usepackage{graphicx}'."\n" if ($pic);
foreach (@packages){
print FILE '\usepackage{'.$_."}\n";
}
print FILE '\begin{document}'."\n";
print FILE '\pagestyle{empty}'."\n";
print FILE '\noindent'."\n";
print FILE '\['."\n" if($equ);
if ($pic){
foreach (@ARGV){
if ( $_ !~ /\.(eps|ps)$/ ){
print "Given picture ($_) should end with eps or ps -> ignored !\n";
next;
}
if ( ! -r $_ ){
print "Given picture is not readable -> ignored!\n";
next;
}
if ( $_ =~ /(\.\/)?$trunc\.$ending2$/) {
print "Given picture ($_) is equal to output file or one of his itermediates -> ignored!\n";
next;
}
print FILE '\includegraphics[angle='.$angle.',width='.$textwidth.'\textwidth]{'.$_."}\n";
$nrpic++;
}
}else{
foreach (@ARGV){
print FILE $_." ";
}
print FILE "\n";
}
print FILE '\]'."\n" if ($equ);
print FILE '\end{document}'."\n";
close(FILE);
if ( ($pic) and ($nrpic==0))
{
unlink("$trunc.tex") unless $keep;
die "Picture mode and no valid picture found -> exit!\n";
}
$_=system("latex -halt-on-error $trunc.tex");
unlink("$trunc.tex") unless $keep;
unlink("$trunc.aux");
unlink("$trunc.log");
die "Error at running latex\n" if $_;
#no tight box for multiple pics
if(($tight)and($nrpic<2)){
die "Error at running dvips\n" if system("dvips -E $trunc.dvi -o $trunc.$ending2");
} else {
die "Error at running dvips\n" if system("dvips $trunc.dvi -o $trunc.$ending2");
}
unlink("$trunc.dvi");
if ($ending eq "pdf"){
die "Error at running ps2pdf\n" if system("ps2pdf $trunc.$ending2");
unlink("$trunc.$ending2");
}elsif(($tight)and ($nrpic<2)){
#no tight box for multiple pics
die "Error at runing bbbox_add.pl\n" if system("bbox_add.pl $trunc.$ending2");
}
if ($viewer){
die "Error at runing $viewer\n" if system("$viewer $output &");
}