From 3a6c900cf3fa3ae7f8a40070d43bbba4ec45b585 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 4 Apr 2023 14:00:33 +0000 Subject: TLPaper: work with new context (mkxl and mkiv) git-svn-id: svn://tug.org/texlive/trunk@66757 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/TeXLive/TLPaper.pm | 117 ++++++++++++++++++++++++++-------------- 1 file changed, 77 insertions(+), 40 deletions(-) (limited to 'Master/tlpkg/TeXLive/TLPaper.pm') diff --git a/Master/tlpkg/TeXLive/TLPaper.pm b/Master/tlpkg/TeXLive/TLPaper.pm index 672db8a452e..e31d5c1ea23 100644 --- a/Master/tlpkg/TeXLive/TLPaper.pm +++ b/Master/tlpkg/TeXLive/TLPaper.pm @@ -1,6 +1,6 @@ # $Id$ # TeXLive::TLPaper.pm - query/modify paper sizes for our various programs -# Copyright 2008-2021 Norbert Preining +# Copyright 2008-2023 Norbert Preining # This file is licensed under the GNU General Public License version 2 # or any later version. @@ -83,8 +83,14 @@ our %paper = ( "context" => { sub => \&paper_context, default_component => "tex/context/user", - default_file => "cont-sys.tex", + default_file => "cont-sys.mkxl", pkg => "context", + variant => { + sub => \&paper_context, + default_component => "tex/context/user", + default_file => "cont-sys.mkiv", + pkg => "context", + } }, "psutils" => { sub => \&paper_psutils, @@ -184,6 +190,8 @@ my %pdftex_papersize = ( "letter" => [ '8.5 true in', '11 true in' ], ); +my %context_papersize = ( "A4" => 1, "letter" => 1, ); + my %dvipdfm_papersize = ( "a3" => 1, "a4" => 1, @@ -284,10 +292,11 @@ sub find_paper_file { sub setup_names { my $prog = shift; + my $variant = shift || ""; my $outcomp = $paper_config_path_component{$prog} - || $paper{$prog}{'default_component'}; + || ($variant eq "variant" ? $paper{$prog}{'variant'}{'default_component'} : $paper{$prog}{'default_component'}); my $filecomp = $paper_config_name{$prog} - || $paper{$prog}{'default_file'}; + || ($variant eq "variant" ? $paper{$prog}{'variant'}{'default_file'} : $paper{$prog}{'default_file'}); return ($outcomp, $filecomp); } @@ -672,7 +681,7 @@ sub paper_dvipdfmx { # context format: -# /--- cont-sys.{tex,rme} +# /--- cont-sys.mkxl and cont-sys.mkiv // formerly {tex,rme} # |... # |\setuppapersize[letter][letter] # |... @@ -681,70 +690,98 @@ sub paper_dvipdfmx { sub paper_context { my $outtree = shift; my $newpaper = shift; - my ($outcomp, $filecomp) = setup_names("context"); - my $dftfile = $paper{'context'}{'default_file'}; - my $outfile = "$outtree/$outcomp/$filecomp"; - my $inp = &find_paper_file("context", "tex", $filecomp, "cont-sys.rme", $dftfile); + # context mkxl actually expects "A4" in contrast to all previous versions + # of context - thanks! But since tlmgr expects to work with a4/letter, + # rewrite a4 -> A4 in the actual function. + if ($newpaper && $newpaper eq "a4") { + $newpaper = "A4"; + } + return (__paper_context($outtree, $newpaper, "context") | __paper_context($outtree, $newpaper, "variant")); +} - return($F_ERROR) unless $inp; +sub __paper_context { + my $outtree = shift; + my $newpaper = shift; + my $what = shift; + my $prog = $what; + my $prog_long = $what; + if ($what eq "variant") { + $prog = "context"; + $prog_long = "context (MkIV)"; + } + my ($outcomp, $filecomp) = setup_names($prog, $what); + my $dftfile = ($what eq 'variant' ? $paper{$prog}{'variant'}{'default_file'} : $paper{$prog}{'default_file'}); + my $outfile = "$outtree/$outcomp/$filecomp"; + my $inp = &find_paper_file("context", "tex", $filecomp, $dftfile); - open(FOO, "<$inp") || die "$prg: open($inp) failed: $!"; - my @lines = ; - close(FOO); + # return($F_ERROR) unless $inp; + # We don't return error here, since the default configuration file + # for context might not have been generated by now cont-sys.mkxl + # + my @lines; + my $endinputidx = -1; my @idx; my $idxlast; - my $endinputidx = -1; my $currentpaper; - # read the lines and the last setuppapersize before the endinput wins - for my $idx (0..$#lines) { - my $l = $lines[$idx]; - if ($l =~ m/^[^%]*\\endinput/) { - $endinputidx = $idx; - last; - } - if ($l =~ m/^\s*\\setuppapersize\s*\[([^][]*)\].*$/) { - if (defined($currentpaper) && $currentpaper ne $1) { - tl_warn("TLPaper: inconsistent paper sizes in $inp! Please fix that.\n"); - return $F_ERROR; + if ($inp) { + open(FOO, "<$inp") || die "$prg: open($inp) failed: $!"; + @lines = ; + close(FOO); + + # read the lines and the last setuppapersize before the endinput wins + for my $idx (0..$#lines) { + my $l = $lines[$idx]; + if ($l =~ m/^[^%]*\\endinput/) { + $endinputidx = $idx; + last; + } + if ($l =~ m/^\s*\\setuppapersize\s*\[([^][]*)\].*$/) { + if (defined($currentpaper) && $currentpaper ne $1) { + tl_warn("TLPaper: inconsistent paper sizes in $inp! Please fix that.\n"); + return $F_ERROR; + } + $currentpaper = $1; + $idxlast = $idx; + push @idx, $idx; + next; } - $currentpaper = $1; - $idxlast = $idx; - push @idx, $idx; - next; } + } else { + @lines = [] + # TODO ??? } # if we haven't found a paper line, assume a4 - $currentpaper || ($currentpaper = "a4"); + $currentpaper || ($currentpaper = "A4"); # trying to find the right papersize # if (defined($newpaper)) { if ($newpaper eq "--list") { info("$currentpaper\n"); - for my $p (keys %pdftex_papersize) { + for my $p (keys %context_papersize) { info("$p\n") unless ($p eq $currentpaper); } } elsif ($newpaper eq "--json") { my @ret = (); push @ret, "$currentpaper"; - for my $p (keys %pdftex_papersize) { + for my $p (keys %context_papersize) { push @ret, $p unless ($p eq $currentpaper); } my %foo; - $foo{'program'} = "context"; + $foo{'program'} = $prog; $foo{'file'} = $inp; $foo{'options'} = \@ret; return \%foo; } elsif ($newpaper eq "--returnlist") { my @ret = (); push @ret, "$currentpaper"; - for my $p (keys %pdftex_papersize) { + for my $p (keys %context_papersize) { push @ret, $p unless ($p eq $currentpaper); } return \@ret; } else { my $found = 0; - for my $p (keys %pdftex_papersize) { + for my $p (keys %context_papersize) { if ($p eq $newpaper) { $found = 1; last; @@ -760,20 +797,20 @@ sub paper_context { } } else { my $addlines = "\\setuppapersize[$newpaper][$newpaper]\n"; - if (defined($endinputidx)) { + if ($endinputidx > -1) { $lines[$endinputidx] = $addlines . $lines[$endinputidx]; } else { $lines[$#lines] = $addlines; } } - info("$prg: setting paper size for context to $newpaper: $outfile\n"); + info("$prg: setting paper size for $prog_long to $newpaper: $outfile\n"); mkdirhier(dirname($outfile)); # if we create the outfile we have to call mktexlsr TeXLive::TLUtils::announce_execute_actions("files-changed") unless (-r $outfile); if (!open(TMP, ">$outfile")) { tlwarn("$prg: Cannot write to $outfile: $!\n"); - tlwarn("Not setting paper size for context.\n"); + tlwarn("Not setting paper size for $prog_long.\n"); return($F_ERROR); } for (@lines) { print TMP; } @@ -782,12 +819,12 @@ sub paper_context { # TODO should we return the value of announce_execute action? return($F_OK); } else { - tlwarn("$prg: Not a valid paper size for context: $newpaper\n"); + tlwarn("$prg: Not a valid paper size for $prog_long: $newpaper\n"); return($F_WARNING); } } } else { - info("Current context paper size (from $inp): $currentpaper\n"); + info("Current $prog_long paper size (from $inp): $currentpaper\n"); } return($F_OK); } -- cgit v1.2.3