%# -*- coding: utf-8 -*-
\ifx\epTeXinputencoding\undefined\else % defined in e-pTeX (> TL2016)
  \epTeXinputencoding utf8    % ensure utf-8 encoding for platex
\fi

\documentclass[a4paper]{jsarticle}
\usepackage[nohyperref]{doc}% doc v3
\usepackage{pxatbegshi}
\GetFileInfo{pxatbegshi.sty}
\title{Package \textsf{pxatbegshi} \fileversion}
\author{Hironobu Yamashita}
\date{\filedate}
\begin{document}

\maketitle

Package \textsf{atbegshi} (written by Heiko Oberdiek) provides
a command \verb+\AtBeginShipout{...}+, however it cannot be used
with Japanese classes for vertical writing (tarticle.cls, etc).
\begin{verbatim}
  ! Incompatible direction list can't be unboxed.
  \AtBeginShipoutAddToBox ...box \AtBeginShipoutBox 
                                                    \kern 0pt}\AtBegShi@restor...
\end{verbatim}
The package \textsf{pxatbegshi} provides a patch for \textsf{atbegshi}
to work with both horizontal and vertical writing.

With \pLaTeXe~2020-10-01 or later, this package does
nothing because the \pLaTeXe\ itself handles the situation.
Therefore, you will not need this package at all.

This package is part of \textsf{platex-tools} bundle:
\begin{verbatim}
  https://github.com/aminophen/platex-tools
\end{verbatim}

\bigskip

Heiko Oberdiek氏による\textsf{atbegshi}パッケージは
\verb+\AtBeginShipout{...}+というコマンドを提供しますが、これを
p\LaTeX の縦組クラス（tarticle.clsなど）で使うとエラーが出てしまいます
\footnote{単に縦組クラスで\textsf{atbegshi}パッケージを読み込んだだけ
では、エラーは出ないようです。}。
この\textsf{pxatbegshi}パッケージは、縦組クラスでも
\textsf{atbegshi}パッケージの機能を使えるようにするためのものです。
もちろん、横組クラスで\textsf{pxatbegshi}パッケージを使用しても
ほぼ問題は起きません。ただし、制約事項として
\begin{quote}
「\verb+\AtBeginShipout+の中身が外部垂直モードで実行されること」を
想定した使用は\emph{サポートしない}
\end{quote}
と明言します（例：\verb+aminophen/platex-tools#15+）。

\LaTeXe~2020-10-01以降では、\textsf{atbegshi}と同等の機能がカーネルに
実装されていて、その対処は\pLaTeXe{}カーネルでなされます。
この場合、\textsf{pxatbegshi}パッケージは何もしません。

\newpage
\section{使いかた}

使いかたは、\textsf{atbegshi}パッケージの代わりに、あるいは
\textsf{atbegshi}パッケージに追加して、\textsf{pxatbegshi}パッケージを
読みこむだけです。使用例：
\begin{verbatim}
  \documentclass[a4paper]{tarticle}
  \usepackage[dvipdfmx]{graphicx}
  \usepackage{pxatbegshi}
  \AtBeginShipout{%
    \AtBeginShipoutUpperLeft{%
      \parbox[t][\paperheight][b]{\paperwidth}{%
        \includegraphics[width=210truemm]{background.eps}}}}
  \begin{document}
  背景に透かしを入れます。
  \end{document}
\end{verbatim}

\section{謝辞}

本パッケージの実装は、北川さん(Hironori Kitagawa)による
「\verb+\AtBegShi@Output+の処理を強引に横組でやらせるコード」
をベースにしています\footnote{2018/09/21 v0.4では
Takayuki Yato (ZR) さんによる\textsf{bxpapersize}パッケージを参考に
していましたが、\textsf{multicol}パッケージで問題が起きるようなので
v0.3以前と同様に北川さんのコードベースに戻しました。}。

\section*{References}

\begin{itemize}
\item utbookでatbegshiパッケージを使いたい\\
  \texttt{https://oku.edu.mie-u.ac.jp/tex/mod/forum/discuss.php?d=2134}
\item \relax[tex-jp-build] [ptex] ページ・数式の組方向
      （※北川さんのコードの初出）\\
  \texttt{https://github.com/texjporg/tex-jp-build/issues/21}
\item CTAN: Package \textsf{bxpapersize}\\
  \texttt{https://ctan.org/pkg/bxpapersize}
\end{itemize}

\end{document}
