Debian Codegraph @

debian/tl-paper

raw
1 #!/usr/bin/perl
2 #
3 # tl-paper
4 #
5 # query and change paper settings using TLPaper
6 # this is independent from tlmgr
7 #
8 # Copyright 2011-2015 Norbert Preining
9 # This file is licensed under the GNU General Public License version 3
10 # or any later version.
11 #
12
13 BEGIN {
14 $^W = 1;
15 chomp ($mydir = `dirname $0`);
16 unshift (@INC, "/usr/share/texlive/tlpkg");
17 }
18
19 $^W = 1;
20 use strict;
21 use Cwd qw/abs_path/;
22 use Pod::Usage;
23 use Getopt::Long qw(:config no_autoabbrev permute);
24 use TeXLive::TLPaper;
25
26 # overwrite the default paper config settings
27 our %paper_config_name = (
28 "xdvi" => "XDvi-paper",
29 "pdftex" => "pdftexconfig.tex",
30 "dvips" => "config-paper.ps",
31 "dvipdfmx" => "dvipdfmx-paper.cfg",
32 "context" => "cont-sys-paper.tex",
33 );
34
35 binmode(STDOUT, ":utf8");
36 binmode(STDERR, ":utf8");
37
38 &main();
39
40 sub main {
41 # the script always runs in sys mode
42 chomp(my $texmfsysconfig = `kpsewhich -var-value=TEXMFSYSCONFIG`);
43 chomp(my $texmfsysvar = `kpsewhich -var-value=TEXMFSYSVAR`);
44 $ENV{"TEXMFCONFIG"} = $texmfsysconfig;
45 $ENV{"TEXMFVAR"} = $texmfsysvar;
46
47 my $action = shift @ARGV;
48 $action = "status" if !defined($action);
49 if ($action =~ m/^status$/i) { # "tl-paper status" shows the current settings
50 TeXLive::TLPaper::paper_all($texmfsysvar,undef);
51
52 } elsif ($action =~ m/^list$/i) { # "tl-paper list prg" lists options for prg
53 my $prg = shift @ARGV;
54 if (!$prg) {
55 # currently, pdftex has the most restricted set of paper sizes
56 $prg = "pdftex";
57 }
58 # the following actually also *reads* the configuration and returns
59 # a list where the first item is the one selected.
60 my $paperref = TeXLive::TLPaper::get_paper_list($prg);
61 my ($current_paper, @other_options) = @{$paperref};
62 for my $i ($current_paper, sort @other_options) {
63 print "$i\n";
64 }
65 # for simply getting the list of supported paper sizes without reading
66 # anything, one can use:
67 # my @paper_options = keys(%{${prg}_papersize});
68
69 } elsif ($action =~ m/^set$/i) { # "tl-paper set <prg|all> <paper>" sets paper
70 my $prg = shift @ARGV;
71 my $newpaper = shift @ARGV;
72
73 if ($prg !~ m/^(xdvi|pdftex|dvips|dvipdfmx|context|all)$/i) {
74 usage();
75 exit 1;
76 }
77 # set TEXMFVAR and TEXMFSYSVAR to TEXMFDIST (which is == TEXMFMAIN)
78 # so that we always find either the system provided config file
79 # as distributed in /usr/share/texlive/texmf-dist, or, if the
80 # admin decided to override that, a copy in TEXMFSYSCONFIG
81 # but *not* the one we have created at some point in history
82 # in TEXMF(SYS)VAR
83 chomp(my $texmfdist = `kpsewhich -var-value=TEXMFDIST`);
84 $ENV{"TEXMFVAR"} = $ENV{"TEXMFSYSVAR"} = $texmfdist;
85 if ($prg =~ m/^all$/i) {
86 if ($newpaper !~ /^(a4|letter)$/) {
87 # we cannot deal with that for now, only a4|letter supported for
88 # all programs
89 print "tl-paper: cannot change setting for all programs to $newpaper\n\n";
90 exit 1;
91 }
92 TeXLive::TLPaper::paper_all($texmfsysvar,$newpaper);
93
94 } else {
95 TeXLive::TLPaper::do_paper($prg,$texmfsysvar,$newpaper);
96 }
97
98 # we probably have changed the paper, so run the execute actions
99 # as announced by TLPaper, that is $::files_changed and
100 # $::regenerate_all_formats.
101 #
102 # but we do not do this here, but rely on the libpaper shell
103 # script to do the rest
104
105 } elsif ($action =~ m/^get$/i) { # "tl-paper get prg" gets paper setting for prg
106 my $prg = shift @ARGV;
107 if ($prg !~ m/^(xdvi|pdftex|dvips|dvipdfmx|context)$/i) {
108 usage();
109 exit 1;
110 }
111 my $paperref = TeXLive::TLPaper::get_paper_list($prg);
112 my ($current_paper, @other_options) = @{$paperref};
113 print "$current_paper\n" if defined($current_paper);
114
115 } else {
116 usage();
117 exit 1;
118 }
119 exit 0;
120 }
121
122 sub usage {
123 print STDERR "
124 tl-paper: inquire and set paper settings for various programs in the TeX World.
125
126 usage:
127 tl-paper list <program> lists available papers, current paper first
128 tl-paper status lists all current settings
129 tl-paper get <program> prints the current paper for <program>
130 tl-paper set <program> <newpaper> sets new paper for <program>
131 tl-paper set all <a4|letter> sets new paper for all programs
132
133 Note: after changing the paper setting for pdftex or context, a rebuild
134 of formats (fmtutil-sys --all) is necessary to make the changes
135 take effect.
136 ";
137 }
138
139
140
141 ### Local Variables:
142 ### perl-indent-level: 2
143 ### tab-width: 2
144 ### indent-tabs-mode: nil
145 ### End:
146 # vim:set tabstop=2 expandtab: #