summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/gentombow/pxpdfpages.sty
blob: ad86ea819bf1edc6660fadacb6b87713230fd207 (plain)
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
%
% pxpdfpages.sty
% written by Hironobu Yamashita (@aminophen)
%
% This package is part of the gentombow bundle.
% https://github.com/aminophen/gentombow
%
% This package is expected to be compatible with
%   * pdfpages.sty
%     (2015/07/19 v0.5a -- 2020/01/28 v0.5q)
%

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pxpdfpages}
  [2020/10/11 v0.4c Patch to pdfpages for tombow]

%% preparations
\def\pxpdpg@pkgname{pxpdfpages}
\def\pxpdpg@warn{\PackageWarningNoLine\pxpdpg@pkgname}
\def\pxpdpg@info{\PackageInfo\pxpdpg@pkgname}
\let\pxpdpg@debug\@gobble
%\def\pxpdpg@debug#1{\typeout{\pxpdpg@pkgname: [DEBUG] #1}}% for debug

%% load it
\RequirePackageWithOptions{pdfpages}% pdfpages requires atbegshi
\ifx\pfmtname\@undefined\else
  \ifx\AtBegShi@Output\@undefined
    % LaTeX2e 2020-10-01: an emulation by ``atbegshi-ltx.sty''
    % => pLaTeX2e 2020-10-01 natively supports it
  \else
    % older: the real ``atbegshi.sty'' is loaded
    \IfFileExists{pxatbegshi.sty}{\RequirePackage{pxatbegshi}}{}
  \fi
\fi

%% do it
%-- similar to bounddvi.sty (checked 2020/10/08 v8.2)
% detection of \iftombow availability is delayed until \AtBeginDocument,
% to support both (u)pLaTeX kernel and ``gentombow.sty''
\AtBeginDocument{\pxpdpg@do}
\def\pxpdpg@do{%
  \ifx\tombowtrue\@undefined
    \pxpdpg@debug{Tombow feature unavailable, no patch applied}%
    \let\pxpdpg@switch\relax % do nothing
  \fi
  \pxpdpg@switch}
%
\def\pxpdpg@switch{\pxpdpg@patch@pdfpages}

%% patch internal for pdfpages to work with tombow
%-- Note: this code should be copied to gentombow.sty!
\def\pxpdpg@patch@pdfpages{%
  \RequirePackage{etoolbox}
  \patchcmd{\AM@output}{%
    \setlength{\@tempdima}{\AM@xmargin}%
    \edef\AM@xmargin{\the\@tempdima}%
    \setlength{\@tempdima}{\AM@ymargin}%
    \edef\AM@ymargin{\the\@tempdima}%
  }{%
    \setlength{\@tempdima}{\AM@xmargin\iftombow+1in\fi}%
    \edef\AM@xmargin{\the\@tempdima}%
    \setlength{\@tempdima}{\AM@ymargin\iftombow-1in\fi}%
    \edef\AM@ymargin{\the\@tempdima}%
  }%
  {\pxpdpg@info{Patch for pdfpages applied}}%
  {\pxpdpg@warn{Patch for pdfpages failed}}%
}

%% all done

\endinput