Skip to content

Instantly share code, notes, and snippets.

@aminophen
Forked from zr-tex8r/pxtatescale.sty
Last active January 22, 2017 19:23
Show Gist options
  • Save aminophen/c77543f68633df1757712fd6e2c0085b to your computer and use it in GitHub Desktop.
Save aminophen/c77543f68633df1757712fd6e2c0085b to your computer and use it in GitHub Desktop.
Support for correct scaling in pTeX vertical writing
% pxtatescale.sty
\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{pxtatescale}[2017/01/23 v0.5]
\def\pxqtg@pkgname{pxtatescale}
\@ifpackageloaded{graphics}{}{%else
\PackageError\pxqtg@pkgname{Package 'graphics' not loaded}\@ehc}
\begingroup
% the patch is necessary only when dvipdfmx.def is used
\def\pxqtg@tempa{dvipdfmx.def}
\ifx\Gin@driver\pxqtg@tempa %%% if-level 1
% dvipdfmx.def 2017/01/22 v4.13 natively supports pTeX vertical writing
\def\pxqtg@Gscale@start{%
\special{pdf:btrans}%
\special{pdf:literal
\iftdir \Gscale@y\space 0 0 \Gscale@x\space
\else \Gscale@x\space 0 0 \Gscale@y\space
\fi 0 0 cm}}
\ifx\Gscale@start\pxqtg@Gscale@start %%% if-level 2
\PackageInfo\pxqtg@pkgname{Patch unnecessary, exiting}%
\else %%% if-level 2
% prepare
\def\pxqtg@patch@status{1}%
\def\pxqtg@try@patch#1#2#3{%
\edef\pxqtg@tempcsname{\string#1}%
\def\pxqtg@temp{#2}\ifx#1\pxqtg@temp
\gdef#1{#3}%
\def\pxqtg@patch@status{0}%
\fi}
% first trial (new definition)
\pxqtg@try@patch\Gscale@start
{\special{pdf:btrans}%
\special{pdf:literal \Gscale@x\space 0 0 \Gscale@y\space 0 0 cm}}
{\special{pdf:btrans}%
\special{pdf:literal
\iftdir \Gscale@y\space 0 0 \Gscale@x\space
\else \Gscale@x\space 0 0 \Gscale@y\space
\fi 0 0 cm}}
\ifnum\pxqtg@patch@status=\z@\else
% second trial (old definition)
\pxqtg@try@patch\Gscale@start
{\special{pdf:btrans xscale \Gscale@x\space yscale \Gscale@y}}%
{\special{pdf:btrans
\iftdir xscale \Gscale@y\space yscale \Gscale@x
\else xscale \Gscale@x\space yscale \Gscale@y
\fi}}
\fi
% check patch status
\ifnum\pxqtg@patch@status=\z@
\PackageInfo\pxqtg@pkgname{Patch applied to \pxqtg@tempcsname}%
\else
\PackageWarningNoLine\pxqtg@pkgname{Patch cannot be applied to \pxqtg@tempcsname}%
\fi
%
\fi %%% if-level 2 end
\fi %%% if-level 1 end
\endgroup
%#!platex + dvipdfmx
% This file contains Japanese characters.
\documentclass[a5paper,10pt]{jsbook}
% 'plext' provides an extension for minipage environment
% to force 'tate' (= vertical) direction
\usepackage{plext}
\usepackage[dvipdfmx]{graphicx}
% patch unnecessary since dvipdfmx.def 2017/01/22 v4.13
\usepackage{pxtatescale}
\begin{document}
Test for scalebox.
% 'yoko' (= horizontal) direction
\noindent\null
□\scalebox{1}[-1]{あ}□1,-1
\\
□\scalebox{-1}[1]{あ}□-1,1
\vspace{1cm}
% 'tate' (= vertical) direction
\begin{minipage}<t>{4.5cm}
\noindent\null
□\scalebox{1}[-1]{あ}□1,-1
\\
□\scalebox{-1}[1]{あ}□-1,1
\end{minipage}
\end{document}
%#!platex + dvipdfmx
\documentclass[a5paper,papersize]{jsarticle}
% 'plext' provides an extension for minipage environment
% to force 'tate' (= vertical) direction
\usepackage{plext}
\usepackage[dvipdfmx]{graphicx}
% patch unnecessary since dvipdfmx.def 2017/01/22 v4.13
\usepackage{pxtatescale}
\begin{document}
\begin{center}\begin{minipage}<t>{10cm}
\fbox{\scalebox{2}[1]{scale}}
\par
\fbox{\reflectbox{reflect}}
\par
\fbox{\resizebox{1in}{2\height}{resize}}
\par\medskip
% rotation is ok
\fbox{\rotatebox[origin=c]{30}{rotate}}
\end{minipage}\end{center}
\end{document}
%#!platex + dvips + ps2pdf
\documentclass[a5paper,papersize]{jsarticle}
% 'plext' provides an extension for minipage environment
% to force 'tate' (= vertical) direction
\usepackage{plext}
\usepackage[dvips]{graphicx}
% patch is unnecessary for dvips, because the dvips program
% itself can interpret pTeX vertical writing
\usepackage{pxtatescale}
\begin{document}
\begin{center}\begin{minipage}<t>{10cm}
\fbox{\scalebox{2}[1]{scale}}
\par
\fbox{\reflectbox{reflect}}
\par
\fbox{\resizebox{1in}{2\height}{resize}}
\par\medskip
% rotation is ok
\fbox{\rotatebox[origin=c]{30}{rotate}}
\end{minipage}\end{center}
\end{document}
@aminophen
Copy link
Author

dvipdfmx.def 2017/01/22 v4.13 supports pTeX vertical writing, so pxtatescale.sty will become unnecessary. I added to pxtatescale package an ad-hoc test for the new version. If we check by version number:

diff --git a/pxtatescale.sty b/pxtatescale.sty
index 838d3b5..bdd96e5 100644
--- a/pxtatescale.sty
+++ b/pxtatescale.sty
@@ -9,13 +9,10 @@
 \def\pxqtg@tempa{dvipdfmx.def}
 \ifx\Gin@driver\pxqtg@tempa          %%% if-level 1
 % dvipdfmx.def 2017/01/22 v4.13 natively supports pTeX vertical writing
-\def\pxqtg@Gscale@start{%
-  \special{pdf:btrans}%
-  \special{pdf:literal
-  \iftdir \Gscale@y\space 0 0 \Gscale@x\space
-  \else   \Gscale@x\space 0 0 \Gscale@y\space
-  \fi 0 0 cm}}
-\ifx\Gscale@start\pxqtg@Gscale@start %%% if-level 2
+\def\ProvidesFile#1[#2 #3]{%
+  \edef\pxqtg@dpmxver{\@parse@version#2//00\@nil}\endinput}
+\input{dvipdfmx.def}
+\ifnum\pxqtg@dpmxver>20170121\relax  %%% if-level 2
   \PackageInfo\pxqtg@pkgname{Patch unnecessary, exiting}%
 \else                                %%% if-level 2
 % prepare

I don't know which way is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment