Edit file File name : tl-paper Content :#!/usr/bin/perl # # tl-paper # # query and change paper settings using TLPaper # this is independent from tlmgr # # Copyright 2011-2015 Norbert Preining # This file is licensed under the GNU General Public License version 3 # or any later version. # BEGIN { $^W = 1; chomp ($mydir = `dirname $0`); unshift (@INC, "/usr/share/texlive/tlpkg"); } $^W = 1; use strict; use Cwd qw/abs_path/; use Pod::Usage; use Getopt::Long qw(:config no_autoabbrev permute); use TeXLive::TLPaper; # overwrite the default paper config settings our %paper_config_name = ( "xdvi" => "XDvi-paper", "pdftex" => "pdftexconfig.tex", "dvips" => "config-paper.ps", "dvipdfmx" => "dvipdfmx-paper.cfg", "context" => "cont-sys-paper.tex", ); binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); &main(); sub main { # the script always runs in sys mode chomp(my $texmfsysconfig = `kpsewhich -var-value=TEXMFSYSCONFIG`); chomp(my $texmfsysvar = `kpsewhich -var-value=TEXMFSYSVAR`); $ENV{"TEXMFCONFIG"} = $texmfsysconfig; $ENV{"TEXMFVAR"} = $texmfsysvar; my $action = shift @ARGV; $action = "status" if !defined($action); if ($action =~ m/^status$/i) { # "tl-paper status" shows the current settings TeXLive::TLPaper::paper_all($texmfsysvar,undef); } elsif ($action =~ m/^list$/i) { # "tl-paper list prg" lists options for prg my $prg = shift @ARGV; if (!$prg) { # currently, pdftex has the most restricted set of paper sizes $prg = "pdftex"; } # the following actually also *reads* the configuration and returns # a list where the first item is the one selected. my $paperref = TeXLive::TLPaper::get_paper_list($prg); my ($current_paper, @other_options) = @{$paperref}; for my $i ($current_paper, sort @other_options) { print "$i\n"; } # for simply getting the list of supported paper sizes without reading # anything, one can use: # my @paper_options = keys(%{${prg}_papersize}); } elsif ($action =~ m/^set$/i) { # "tl-paper set <prg|all> <paper>" sets paper my $prg = shift @ARGV; my $newpaper = shift @ARGV; if ($prg !~ m/^(xdvi|pdftex|dvips|dvipdfmx|context|all)$/i) { usage(); exit 1; } # set TEXMFVAR and TEXMFSYSVAR to TEXMFDIST (which is == TEXMFMAIN) # so that we always find either the system provided config file # as distributed in /usr/share/texlive/texmf-dist, or, if the # admin decided to override that, a copy in TEXMFSYSCONFIG # but *not* the one we have created at some point in history # in TEXMF(SYS)VAR chomp(my $texmfdist = `kpsewhich -var-value=TEXMFDIST`); $ENV{"TEXMFVAR"} = $ENV{"TEXMFSYSVAR"} = $texmfdist; if ($prg =~ m/^all$/i) { if ($newpaper !~ /^(a4|letter)$/) { # we cannot deal with that for now, only a4|letter supported for # all programs print "tl-paper: cannot change setting for all programs to $newpaper\n\n"; exit 1; } TeXLive::TLPaper::paper_all($texmfsysvar,$newpaper); } else { TeXLive::TLPaper::do_paper($prg,$texmfsysvar,$newpaper); } # we probably have changed the paper, so run the execute actions # as announced by TLPaper, that is $::files_changed and # $::regenerate_all_formats. # # but we do not do this here, but rely on the libpaper shell # script to do the rest } elsif ($action =~ m/^get$/i) { # "tl-paper get prg" gets paper setting for prg my $prg = shift @ARGV; if ($prg !~ m/^(xdvi|pdftex|dvips|dvipdfmx|context)$/i) { usage(); exit 1; } my $paperref = TeXLive::TLPaper::get_paper_list($prg); my ($current_paper, @other_options) = @{$paperref}; print "$current_paper\n" if defined($current_paper); } else { usage(); exit 1; } exit 0; } sub usage { print STDERR " tl-paper: inquire and set paper settings for various programs in the TeX World. usage: tl-paper list <program> lists available papers, current paper first tl-paper status lists all current settings tl-paper get <program> prints the current paper for <program> tl-paper set <program> <newpaper> sets new paper for <program> tl-paper set all <a4|letter> sets new paper for all programs Note: after changing the paper setting for pdftex or context, a rebuild of formats (fmtutil-sys --all) is necessary to make the changes take effect. "; } ### Local Variables: ### perl-indent-level: 2 ### tab-width: 2 ### indent-tabs-mode: nil ### End: # vim:set tabstop=2 expandtab: # Save