diff options
author | Karl Berry <karl@freefriends.org> | 2017-02-08 22:19:00 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-02-08 22:19:00 +0000 |
commit | 6e51339ef42840e5c37785cc48d3b5ad525cead3 (patch) | |
tree | d02fe5cdd1ae504c167470fb7b95ca84a29a9f12 /Master/texmf-dist/tex/latex/bxpapersize | |
parent | 77b2f02d23f8f97c8c131011f8ce1bc82c58a360 (diff) |
bxpapersize (8feb17)
git-svn-id: svn://tug.org/texlive/trunk@43169 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/bxpapersize')
-rw-r--r-- | Master/texmf-dist/tex/latex/bxpapersize/bxpapersize.sty | 249 |
1 files changed, 189 insertions, 60 deletions
diff --git a/Master/texmf-dist/tex/latex/bxpapersize/bxpapersize.sty b/Master/texmf-dist/tex/latex/bxpapersize/bxpapersize.sty index e15bf32cc84..d5cd3b0d4b1 100644 --- a/Master/texmf-dist/tex/latex/bxpapersize/bxpapersize.sty +++ b/Master/texmf-dist/tex/latex/bxpapersize/bxpapersize.sty @@ -2,7 +2,7 @@ %% package declaration \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{bxpapersize}[2016/03/26 v0.2] +\ProvidesPackage{bxpapersize}[2017/02/08 v0.3] %% preparation \def\bxpr@pkgname{bxpapersize} @@ -10,32 +10,40 @@ %--------------------------------------- options -%% 'disabled' +% Note: Only non-key-value global options should be picked. + +%% 'disabled' / 'nodvidriver' \chardef\bxpr@disabled=0 \DeclareOption{disabled}{% \chardef\bxpr@disabled=1 } +\DeclareOption{nodvidriver}{% + \chardef\bxpr@disabled=1 } +%% 'olddvips' +\chardef\bxpr@olddvips=0 +\DeclareOption{olddvips}{% + \chardef\bxpr@olddvips=1 } %% keyval \@onlypreamble\bxpr@kvopt -\let\bxpr@kvopt\@empty +\let\bxpr@kvopt\@empty % key-value option list \DeclareOption*{% \edef\bxpr@kvopt{\bxpr@kvopt,\CurrentOption}} \ProcessOptions* %% If 'disabled' is given, quit now. \ifnum\bxpr@disabled>\z@ + \providecommand*\papersizesetup{\bxpapersizesetup}% \newcommand*\bxpapersizesetup[1]{}% \expandafter\endinput\fi\relax %--------------------------------------- general %% load packages -\RequirePackage{xkeyval} +\RequirePackage{xkeyval}[2008/08/10]% v2.6 \RequirePackage{atbegshi} \RequirePackage{ifpdf,ifxetex,ifluatex,ifvtex} %% variables \newdimen\bxpr@dima -\newif\ifbxpr@active \let\bxpr@width\relax \let\bxpr@height\relax @@ -83,19 +91,30 @@ \let\bxpr@mode\bxpr@mode@@pdfmode \fi +%% \bxpr@csletcs{<CSa>}{<CSb>} +\def\bxpr@csletcs#1#2{% + \expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname} + %--------------------------------------- parameters %% constants \chardef\bxpr@priority@@low=0 \chardef\bxpr@priority@@middle=1 +\chardef\bxpr@priority@@default=1 \chardef\bxpr@priority@@high=2 +\ifnum\bxpr@olddvips>\z@ + \chardef\bxpr@priority@@low=2 + \chardef\bxpr@priority@@high=0 +\fi \chardef\bxpr@size@@real=0 %'real', use \paperwidth/height -\chardef\bxpr@size@@box=1 %'box', use shipout box size -\chardef\bxpr@size@@boxS=2 %'box*' -\chardef\bxpr@size@@custom=3 % size explicitly given +\chardef\bxpr@size@@realS=1 %'real*' +\chardef\bxpr@size@@box=2 %'box', use shipout box size +\chardef\bxpr@size@@boxS=3 %'box*' +\chardef\bxpr@size@@custom=4 % size explicitly given %% variables -\let\bxpr@priority\bxpr@priority@@middle +\newif\ifbxpr@needs@reset@size +\let\bxpr@priority\bxpr@priority@@default \let\bxpr@size\bxpr@size@@real \def\bxpr@cs@width{\z@}% custom page width \def\bxpr@cs@height{\z@}% custom page height @@ -109,28 +128,98 @@ \PackageError\bxpr@pkgname {Invalid value for '#1': #2}% \@ehc} +\def\bxpr@err@ivkey{% + \begingroup \let\MessageBreak\relax % freeze + \let\bxpr@tmpb\@empty + \@for\bxpr@tmpa:=\XKV@rm\do{% + \edef\bxpr@tmpb{\bxpr@tmpb\MessageBreak\@spaces\bxpr@tmpa}}% + \PackageError\bxpr@pkgname + {Unknown parameter(s)\bxpr@tmpb\MessageBreak + are found in the given list} + \endgroup} %% 'active' -\define@boolkey+{bxpr}{active}% - {\@nameuse{bxpr@active#1}}% +\define@boolkey+[bxpr]{prm}{active}[true]{}% {\bxpr@ivval{active}{#1}} -\bxpr@activetrue +\bxpr@prm@activetrue %% 'priority' -\define@choicekey*+{bxpr}{priority}[\bxpr@tmpa\bxpr@tmpb]% - {low,middle,high}% - {\bxpr@set@priority}% +\define@choicekey*+[bxpr]{prm}{priority}% + {low,middle,default,high}% + {\bxpr@set@priority{#1}}% {\bxpr@ivval{priority}{#1}} -\def\bxpr@set@priority{% - \chardef\bxpr@priority\bxpr@tmpb\relax} +\def\bxpr@set@priority#1{% + \bxpr@csletcs{bxpr@priority}{bxpr@priority@@#1}} \AtBeginDocument{% - \def\bxpr@set@priority{\bxpr@err@nlprm{priority}}} + \def\bxpr@set@priority#1{% invalidate + \bxpr@err@nlprm{priority}}} + +%% 'truedimen' +\define@boolkey+[bxpr]{prm}{truedimen}[true]% + {\bxpr@needs@reset@sizetrue}% + {\bxpr@ivval{truedimen}{#1}} + +%% 'landscape' +\define@boolkey+[bxpr]{prm}{landscape}[true]% + {\bxpr@needs@reset@sizetrue}% + {\bxpr@ivval{landscape}{#1}} %% 'size' -\define@choicekey*+{bxpr}{size}[\bxpr@tmpa\bxpr@tmpb]% - {real,box,box*}% - {\chardef\bxpr@size\bxpr@tmpb\relax}% +\define@choicekey*+[bxpr]{prm}{size}[\bxpr@tmpa\bxpr@tmpb]% + {real,real*,box,box*, + % preset paper sizes + a0paper,a1paper,a2paper,a3paper,a4paper,a5paper,a6paper,% + b0paper,b1paper,b2paper,b3paper,b4paper,b5paper,b6paper,% + c0paper,c1paper,c2paper,c3paper,c4paper,c5paper,c6paper,% + b0j,b1j,b2j,b3j,b4j,b5j,b6j,% + ansiapaper,ansibpaper,ansicpaper,ansidpaper,ansiepaper,% + letterpaper,legalpaper,executivepaper,screen}% + {\def\bxpr@val@size{#1}\bxpr@needs@reset@sizefalse + \ifcase\bxpr@tmpb\relax + \let\bxpr@size\bxpr@size@@real + \or \let\bxpr@size\bxpr@size@@realS + \or \let\bxpr@size\bxpr@size@@box + \or \let\bxpr@size\bxpr@size@@boxS + \or \bxpr@set@size@a(841,1189){mm}% a0paper + \or \bxpr@set@size@a(594,841){mm}% a1paper + \or \bxpr@set@size@a(420,594){mm}% a2paper + \or \bxpr@set@size@a(297,420){mm}% a3paper + \or \bxpr@set@size@a(210,297){mm}% a4paper + \or \bxpr@set@size@a(148,210){mm}% a5paper + \or \bxpr@set@size@a(105,148){mm}% a6paper + \or \bxpr@set@size@a(1000,1414){mm}% b0paper + \or \bxpr@set@size@a(707,1000){mm}% b1paper + \or \bxpr@set@size@a(500,707){mm}% b2paper + \or \bxpr@set@size@a(353,500){mm}% b3paper + \or \bxpr@set@size@a(250,353){mm}% b4paper + \or \bxpr@set@size@a(176,250){mm}% b5paper + \or \bxpr@set@size@a(125,176){mm}% b6paper + \or \bxpr@set@size@a(917,1297){mm}% c0paper + \or \bxpr@set@size@a(648,917){mm}% c1paper + \or \bxpr@set@size@a(458,648){mm}% c2paper + \or \bxpr@set@size@a(324,458){mm}% c3paper + \or \bxpr@set@size@a(229,324){mm}% c4paper + \or \bxpr@set@size@a(162,229){mm}% c5paper + \or \bxpr@set@size@a(114,162){mm}% c6paper + \or \bxpr@set@size@a(1030,1456){mm}% b0j + \or \bxpr@set@size@a(728,1030){mm}% b1j + \or \bxpr@set@size@a(515,728){mm}% b2j + \or \bxpr@set@size@a(364,515){mm}% b3j + \or \bxpr@set@size@a(257,364){mm}% b4j + \or \bxpr@set@size@a(182,257){mm}% b5j + \or \bxpr@set@size@a(128,182){mm}% b6j + \or \bxpr@set@size@a(8.5,11){in}% ansiapaper + \or \bxpr@set@size@a(11,17){in}% ansibpaper + \or \bxpr@set@size@a(17,22){in}% ansicpaper + \or \bxpr@set@size@a(22,34){in}% ansidpaper + \or \bxpr@set@size@a(34,44){in}% ansiepaper + \or \bxpr@set@size@a(8.5,11){in}% letterpaper + \or \bxpr@set@size@a(8.5,14){in}% legalpaper + \or \bxpr@set@size@a(7.25,10.5){in}% executivepaper + \or \bxpr@set@size@a(225,180){mm}% screen + \fi}% {% custom page size ('size={<width>,<height>}') + \def\bxpr@val@size{#1}\bxpr@needs@reset@sizefalse \def\bxpr@tmpa##1,##2,##3\@nil{% \begingroup\setbox\z@\hbox{% \@tempdima##1\relax \@tempdimb##2\relax @@ -140,17 +229,36 @@ \endgroup\bxpr@g@next}% \bxpr@tmpa#1,,\@nil \let\bxpr@size\bxpr@size@@custom} - -%% apply package options -\edef\bxpr@tmpa{% - \noexpand\setkeys{bxpr}{\bxpr@kvopt}% -}\bxpr@tmpa +\def\bxpr@set@size@a(#1,#2)#3{% + \edef\bxpr@tmpa##1##2{% + \ifbxpr@prm@landscape##2\else##1\fi + \ifbxpr@prm@truedimen true\fi #3\relax}% + \bxpr@dima=\bxpr@tmpa{#1}{#2}\edef\bxpr@cs@width{\the\bxpr@dima}% + \bxpr@dima=\bxpr@tmpa{#2}{#1}\edef\bxpr@cs@height{\the\bxpr@dima}% + \let\bxpr@size\bxpr@size@@custom} %--------------------------------------- user interface %%<*> \bxpapersizesetup{<key>=<value>,...} \newcommand*\bxpapersizesetup[1]{% - \setkeys{bxpr}{#1}} + \setkeys*[bxpr]{prm}{#1}% + \ifx\XKV@rm\@empty\else + \bxpr@err@ivkey + \fi + \ifbxpr@needs@reset@size + \edef\bxpr@tmpa{% + \noexpand\setkeys[bxpr]{prm}{size=\bxpr@val@size}% + }\bxpr@tmpa + \fi} +%%<*> \papersizesetup{<key>=<value>,...} +% Synonym for \bxpapersizesetup, declared only if not yet defined. +\providecommand*\papersizesetup{% + \bxpapersizesetup} + +%% apply package options +\edef\bxpr@tmpa{% + \noexpand\bxpapersizesetup{\bxpr@kvopt}% +}\bxpr@tmpa %--------------------------------------- page hook @@ -165,19 +273,20 @@ \the\toks@} \endgroup -%% \bxpr@begindoc@second@hook +%% \bxpr@begindoc@last@hook % Placed after the begin-docuemnt hook. -\def\bxpr@begindoc@second@hook{% - \let\bxpr@begindoc@second@hook\@undefined} +\def\bxpr@begindoc@last@hook{% + \let\bxpr@begindoc@last@hook\@undefined} \g@addto@macro\document{% - \bxpr@begindoc@second@hook} + \bxpr@begindoc@last@hook} %% add hook for every page \g@addto@macro\bxpr@begindoc@first@hook{% \bxDebug{bxpapersize settings:^^J% mode=\the\bxpr@mode^^J% - prioity=\the\bxpr@priority^^J% - size=\the\bxpr@size}% + priority=\the\bxpr@priority^^J% + size=\the\bxpr@size(\bxpr@cs@width,\bxpr@cs@height)% + \ifnum\bxpr@tombow>\z@ [tombow]\fi}% \bxpr@geometry@hack \ifcase\bxpr@mode % dvi \ifcase\bxpr@priority % low @@ -190,7 +299,7 @@ \bxpr@page@process \AtBeginShipoutNext{\bxpr@every@page@hook}}% \AtBeginShipoutFirst{\bxpr@special@chunk} - \or % middle + \or % default \def\bxpr@every@page@hook{% \bxpr@page@process \bxpr@modify@output@box\relax\bxpr@special@chunk}% @@ -210,7 +319,14 @@ \AtBeginShipout{\bxpr@every@page@hook}% \fi} -%% \bxpr@modify@output@box +%% \bxpr@tombow +\chardef\bxpr@tombow=0 +\expandafter\ifx\csname iftombow\expandafter\endcsname + \csname iftrue\endcsname + \chardef\bxpr@tombow=1 +\fi + +%% \bxpr@modify@output@box{<pre>}{<post>} \def\bxpr@modify@output@box#1#2{% \setbox\AtBeginShipoutBox\vbox{% #1\box\AtBeginShipoutBox#2}} @@ -233,7 +349,7 @@ \edef\bxpr@tmpa{% \paperwidth=\the\paperwidth \paperheight=\the\paperheight}% - \expandafter\g@addto@macro\expandafter\bxpr@begindoc@second@hook + \expandafter\g@addto@macro\expandafter\bxpr@begindoc@last@hook \expandafter{\bxpr@tmpa}% }{}} @@ -245,8 +361,13 @@ %% \bxpr@set@page@size{<width>}{<height>} \ifcase\bxpr@mode %dvi \def\bxpr@set@page@size#1#2{% - \bxpr@dima=#1\relax \edef\bxpr@tmpb{\the\bxpr@dima}% - \bxpr@dima=#2\relax \edef\bxpr@tmpb{\bxpr@tmpb,\the\bxpr@dima}% + \begingroup + \bxpr@let@real@mag@to\bxpr@tmpa + \paperwidth=#1\relax \paperwidth=\bxpr@tmpa\paperwidth + \paperheight=#2\relax \paperheight=\bxpr@tmpa\paperheight + \xdef\bxpr@g@next{% + \def\noexpand\bxpr@tmpb{\the\paperwidth,\the\paperheight}}% + \endgroup \bxpr@g@next \bxDebug{papersize=\bxpr@tmpb}% \edef\bxpr@special@chunk{\special{papersize=\bxpr@tmpb}}}% \else %pdf @@ -255,23 +376,28 @@ \bxDebug{papersize=\the\bxpr@pagewidth,\the\bxpr@pageheight}}% \fi +%% \bxpr@let@real@mag@to\CS +\def\bxpr@let@real@mag@to#1{% + \begingroup + \@tempcnta=\mag \advance\@tempcnta100000 + \def\bxpr@tmpa1##1##2##3##4##5\relax{% + \@tempdima=##1##2.##3##4##5\p@}% + \expandafter\bxpr@tmpa\the\@tempcnta\relax + \xdef\bxpr@g@next{% + \def\noexpand#1{\strip@pt\@tempdima}}% + \endgroup \bxpr@g@next} + %% \bxpr@page@process \def\bxpr@page@process{% - \ifbxpr@active + \ifbxpr@prm@active \bxpr@page@process@a \fi} \def\bxpr@page@process@a{% \ifcase\bxpr@size % real - \ifcase\bxpr@mode % dvi - \ifnum\mag=\@m - \bxpr@set@page@size{\paperwidth}{\paperheight}% - \else - \bxpr@apply@mag - \bxpr@set@page@size{\bxpr@width}{\bxpr@height}% - \fi - \or % pdf - \bxpr@set@page@size{\paperwidth}{\paperheight}% - \fi + \bxpr@use@real@size + \bxpr@set@page@size{\bxpr@width}{\bxpr@height}% + \or % real* + \bxpr@set@page@size{\paperwidth}{\paperheight}% \or % box \bxpr@use@box@size \setbox\AtBeginShipoutBox\vbox{% @@ -285,20 +411,23 @@ \bxpr@set@page@size{\bxpr@cs@width}{\bxpr@cs@height}% \fi} -%% \bxpr@apply@mag -\def\bxpr@apply@mag{% +%% \bxpr@use@real@size +\def\bxpr@use@real@size{% + \bxpr@use@real@size@a{width}% + \bxpr@use@real@size@a{height}} +\def\bxpr@use@real@size@a#1{% \begingroup - \ifnum\mag=\@m\else - \@tempcnta=\mag \advance\@tempcnta100000 - \def\bxpr@next1##1##2##3##4##5\relax{% - \def\bxpr@tmpa{##1##2.##3##4##5}}% - \expandafter\bxpr@next\the\@tempcnta\relax - \paperwidth=\bxpr@tmpa\paperwidth - \paperheight=\bxpr@tmpa\paperheight + \bxpr@csletcs{bxpr@tmpa}{paper#1}% + \ifnum\bxpr@tombow>\z@ + \advance\bxpr@tmpa2truein\relax \fi + \bxpr@csletcs{bxpr@tmpb}{stock#1}% + \ifx\bxpr@tmpb\relax\else \ifdim\bxpr@tmpb>\z@ + \bxpr@tmpa\bxpr@tmpb + \fi\fi \xdef\bxpr@g@next{% - \def\noexpand\bxpr@width{\the\paperwidth}% - \def\noexpand\bxpr@height{\the\paperheight}}% + \def\expandafter\noexpand\csname bxpr@#1\endcsname{% + \the\bxpr@tmpa}} \endgroup \bxpr@g@next} %% \bxpr@use@box@size |