summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gentombow/pxtextpos.sty
blob: 02cd5202e21b593ffb267f89a4b22fab2b66ac89 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
%
% pxtextpos.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
%   * textpos.sty
%     2005/10/13 v1.6a -- 2019/04/15 v1.9.1
%

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pxtextpos}
    [2020/10/11 v0.4b Patch to textpos for tombow]

%% preparations
\def\pxtxtpos@pkgname{pxtextpos}
\def\pxtxtpos@warn{\PackageWarningNoLine\pxtxtpos@pkgname}
\let\pxtxtpos@debug\@gobble
%\def\pxtxtpos@debug#1{\typeout{\pxtxtpos@pkgname: [DEBUG] #1}}% for debug

%% load it
\RequirePackageWithOptions{textpos}
% textpos requires everyshi, only if both conditions are met:
%  (1) \fmtversion is **older** than 2020/10/01
%  (2) \ifTP@abspos == \iftrue
% [TODO] tate-mode support is incomplete!
\ifx\pfmtname\@undefined\else
  \ifx\@EveryShipout@Output\@undefined
    % LaTeX2e 2020-10-01: an emulation by ``everyshi-ltx.sty''
    % => pLaTeX2e 2020-10-01 natively supports it
  \else
    % older: the real ``everyshi.sty'' is loaded
    \IfFileExists{pxeveryshi.sty}{\RequirePackage{pxeveryshi}}{}
  \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{\pxtxtpos@do}
\def\pxtxtpos@do{%
  \ifx\tombowtrue\@undefined
    \pxtxtpos@debug{Tombow feature unavailable, no patch applied}%
    \let\pxtxtpos@switch\relax % do nothing
  \fi
  \pxtxtpos@switch}
%
\def\pxtxtpos@switch{%
  \let\textblockorigin\pxtxtpos@textblockorigin
  \ifTP@abspos\textblockorigin{0pt}{0pt}\fi %% reset
}

%% known definition
\def\pxtxtpos@textblockorigin#1#2{%
  \ifTP@abspos
    \TP@ox=-1in    \addtolength\TP@ox{#1}
    \TP@oy=-1in    \addtolength\TP@oy{#2}
    \ifTP@chatter\typeout{TextBlockOrigin set to #1 x #2}\fi
  \else
    \PackageError{textpos}
      {The \protect\textblockorigin\space command\MessageBreak
       may only be used if the package was given\MessageBreak
       the`absolute' option when it was invoked}
      {If you want to use the \protect\textblockorigin\space command, then
         \MessageBreak
       invoke the package with the syntax\MessageBreak
       \protect\usepackage[absolute]{textpos}}
  \fi
}
\@onlypreamble\pxtxtpos@textblockorigin

%% check definition
\ifx\textblockorigin\pxtxtpos@textblockorigin\else
  \pxtxtpos@warn{%
    Command \noexpand\textblockorigin is beyond my knowledge.\MessageBreak
    I will apply the patch anyway, but it may break:\MessageBreak
    Please report to the author of `\pxtxtpos@pkgname.sty'}
\fi

%% new definition
\def\pxtxtpos@textblockorigin#1#2{%
  \ifTP@abspos
    \TP@ox=-1in    \addtolength\TP@ox{#1}
    \TP@oy=-1in    \addtolength\TP@oy{#2}
    %%% addition
    \iftombow
      \addtolength\TP@ox{1in}\addtolength\TP@oy{1in}
    \fi
    %%%
    \ifTP@chatter\typeout{TextBlockOrigin set to #1 x #2}\fi
  \else
    \PackageError{textpos}
      {The \protect\textblockorigin\space command\MessageBreak
       may only be used if the package was given\MessageBreak
       the`absolute' option when it was invoked}
      {If you want to use the \protect\textblockorigin\space command, then
         \MessageBreak
       invoke the package with the syntax\MessageBreak
       \protect\usepackage[absolute]{textpos}}
  \fi
}

\endinput
%% EOF