% 2025.07.10
%
% This is a rotation mechanism for Plain TeX.
% It functions correctly only in the DVI -> PS -> PDF chain.
% Place "rotatebox.tex" in a TeX root and execute the "Refresh file name database" task in MiKTeX Console.

\catcode`@=11

\def\zap@space#1 #2{%
  #1%
  \ifx#2\@empty\else\expandafter\zap@space\fi
  #2}
\def\@car#1#2\@nil{#1}
\def\@cdr#1#2\@nil{#2}
\def\@empty{}
\long\def\@gobble#1{}
\long\def\@firstofone#1{#1}

%trig.sty
\chardef\nin@ty=90
\chardef\@clxxx=180
\chardef\@lxxi=71
\mathchardef\@mmmmlxviii=4068
\chardef\@coeffz=72
\chardef\@coefb=42
\mathchardef\@coefc=840
\mathchardef\@coefd=5040
{\catcode`t=12\catcode`p=12\gdef\noPT#1pt{#1}}
\def\TG@rem@pt#1{\expandafter\noPT\the#1\space}
\def\TG@term#1{%
 \dimen@\@tempb\dimen@
 \advance\dimen@ #1\p@}
\def\TG@series{%
 \dimen@\@lxxi\dimen@
 \divide \dimen@ \@mmmmlxviii
 \edef\@tempa{\TG@rem@pt\dimen@}%
 \dimen@\@tempa\dimen@
 \edef\@tempb{\TG@rem@pt\dimen@}%
 \divide\dimen@\@coeffz
 \advance\dimen@\m@ne\p@
 \TG@term\@coefb
 \TG@term{-\@coefc}%
 \TG@term\@coefd
 \dimen@\@tempa\dimen@
 \divide\dimen@ \@coefd}
\def\CalculateSin#1{{%
  \expandafter\ifx\csname sin(\number#1)\endcsname\relax
    \dimen@=#1\p@\TG@@sin
    \expandafter\xdef\csname sin(\number#1)\endcsname
                                    {\TG@rem@pt\dimen@}%
  \fi}}
\def\CalculateCos#1{{%
  \expandafter\ifx\csname cos(\number#1)\endcsname\relax
    \dimen@=\nin@ty\p@
    \advance\dimen@-#1\p@
    \TG@@sin
    \expandafter\xdef\csname cos(\number#1)\endcsname
                                     {\TG@rem@pt\dimen@}%
  \fi}}
\def\TG@reduce#1#2{%
\dimen@#1#2\nin@ty\p@
  \advance\dimen@#2-\@clxxx\p@
  \dimen@-\dimen@
  \TG@@sin}
\def\TG@@sin{%
  \ifdim\TG@reduce>+%
  \else\ifdim\TG@reduce<-%
  \else\TG@series\fi\fi}%
\def\UseSin#1{\csname sin(\number#1)\endcsname}
\def\UseCos#1{\csname cos(\number#1)\endcsname}
\def\z@num{0 }
\def\@tempa{1 }
\def\@tempb{-1 }
\expandafter\let\csname sin(0)\endcsname\z@num
\expandafter\let\csname cos(0)\endcsname\@tempa
\expandafter\let\csname sin(90)\endcsname\@tempa
\expandafter\let\csname cos(90)\endcsname\z@num
\expandafter\let\csname sin(-90)\endcsname\@tempb
\expandafter\let\csname cos(-90)\endcsname\z@num

\newdimen\Grot@height
\newdimen\Grot@left
\newdimen\Grot@right
\newdimen\Grot@depth
\newdimen\Grot@l
\newdimen\Grot@r
\newdimen\Grot@h
\newdimen\Grot@d
\newdimen\Grot@x
\newdimen\Grot@y

\long\def\rotatebox#1#2{%
  \leavevmode
  \Grot@setangle{#1}%
  \setbox\z@\hbox{{#2}}%
  \Grot@x\z@
  \Grot@y\z@
  \Grot@box}
\def\Grot@setangle#1{\edef\Grot@angle{#1}}
\def\Grot@Px#1#2#3{%
        #1\Grot@cos#2%
        \advance#1-\Grot@sin#3}
\def\Grot@Py#1#2#3{%
        #1\Grot@sin#2%
        \advance#1\Grot@cos#3}
\def\Grot@box{%
  \begingroup
  \CalculateSin\Grot@angle
  \CalculateCos\Grot@angle
  \edef\Grot@sin{\UseSin\Grot@angle}%
  \edef\Grot@cos{\UseCos\Grot@angle}%
  \Grot@r\wd\z@  \advance\Grot@r-\Grot@x
  \Grot@l\z@     \advance\Grot@l-\Grot@x
  \Grot@h\ht\z@  \advance\Grot@h-\Grot@y
  \Grot@d-\dp\z@ \advance\Grot@d-\Grot@y
  \ifdim\Grot@sin\p@>\z@
    \ifdim\Grot@cos\p@>\z@
      \Grot@Py\Grot@height \Grot@r\Grot@h%B
      \Grot@Px\Grot@right  \Grot@r\Grot@d%E
      \Grot@Px\Grot@left   \Grot@l\Grot@h%C
      \Grot@Py\Grot@depth  \Grot@l\Grot@d%D
    \else
      \Grot@Py\Grot@height \Grot@r\Grot@d%E
      \Grot@Px\Grot@right  \Grot@l\Grot@d%D
      \Grot@Px\Grot@left   \Grot@r\Grot@h%B
      \Grot@Py\Grot@depth  \Grot@l\Grot@h%C
    \fi
  \else
    \ifdim\Grot@cos\p@<\z@
      \Grot@Py\Grot@height \Grot@l\Grot@d%D
      \Grot@Px\Grot@right  \Grot@l\Grot@h%C
      \Grot@Px\Grot@left   \Grot@r\Grot@d%E
      \Grot@Py\Grot@depth  \Grot@r\Grot@h%B
    \else
      \Grot@Py\Grot@height \Grot@l\Grot@h%C
      \Grot@Px\Grot@right  \Grot@r\Grot@h%B
      \Grot@Px\Grot@left   \Grot@l\Grot@d%D
      \Grot@Py\Grot@depth  \Grot@r\Grot@d%E
    \fi
  \fi
  \advance\Grot@height\Grot@y
  \advance\Grot@depth\Grot@y
  \Grot@Px\dimen@  \Grot@x\Grot@y
  \Grot@Py\dimen@ii \Grot@x\Grot@y
  \dimen@-\dimen@     \advance\dimen@-\Grot@left
  \dimen@ii-\dimen@ii \advance\dimen@ii\Grot@y
  \setbox\z@\hbox{%
    \kern\dimen@
    \raise\dimen@ii\hbox{\Grot@start\box\z@\Grot@end}}%
  \ht\z@\Grot@height
  \dp\z@-\Grot@depth
  \advance\Grot@right-\Grot@left\wd\z@\Grot@right
  \leavevmode\box\z@
  \endgroup}

\ifx\pdfoutput\undefined
\else
\ifnum\pdfoutput=1
% pdftex.def
\def\GPT@space{ }
\def\GPT@MatrixIdentity{1 0 0 1}
\def\GPT@Zero{0}
\def\GPT@Minus{-}
\def\GPT@NormalizeNumber#1{%
  \edef#1{#1}%
  \edef#1{\expandafter\zap@space#1 \@empty}%
  \edef#1{\expandafter\GPT@ZapPlus#1+\@nil}%
  \edef#1{\expandafter\GPT@ZapMinusMinus#1--\@nil}%
  \expandafter\GPT@Split#1..\@nil
  \ifx\GPT@frac\@empty
  \else
    \edef\GPT@frac{%
      \expandafter\GPT@Reverse\expandafter{\expandafter}\GPT@frac\@nil
    }%
    \edef\GPT@frac{%
      \expandafter\GPT@ZapLeadingZeros\GPT@frac\@empty
    }%
    \ifx\GPT@frac\@empty
    \else
      \edef\GPT@frac{%
        \expandafter\GPT@Reverse\expandafter{\expandafter}\GPT@frac\@nil
      }%
    \fi
  \fi
  \edef\GPT@sign{\expandafter\@car\GPT@int\@empty\@nil}%
  \ifx\GPT@sign\GPT@Minus
    \edef\GPT@int{\expandafter\@cdr\GPT@int\@nil}%
  \else
    \def\GPT@sign{}%
  \fi
  \edef\GPT@int{%
    \expandafter\GPT@ZapLeadingZeros\GPT@int\@empty
  }%
  \edef\GPT@temp{\GPT@int\GPT@frac}%
  \ifx\GPT@temp\@empty
    \def#1{0}%
  \else
    \edef#1{%
      \GPT@sign
      \GPT@int
      \ifx\GPT@frac\@empty
      \else
        .\GPT@frac
      \fi
    }%
  \fi
}
\def\GPT@ZapPlus#1+#2\@nil{%
  #1%
  \ifx\@empty#2\@empty
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {%
    \GPT@ZapPlus#2\@nil
  }%
}
\def\GPT@ZapMinusMinus#1--#2\@nil{%
  #1%
  \ifx\@empty#2\@empty
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {%
    \GPT@ZapMinusMinus#2\@nil
  }%
}
\def\GPT@Split#1.#2.#3\@nil{%
  \def\GPT@int{#1}%
  \ifx\@empty#2\@empty
    \let\GPT@frac\@empty
  \else
    \def\GPT@frac{#2}%
  \fi
}
\def\GPT@Reverse#1#2#3\@nil{%
  \ifx\@empty#3\@empty
    #2#1%
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {%
    \GPT@Reverse{#2#1}#3\@nil
  }%
}
\def\GPT@ZapLeadingZeros#1{%
  \ifx0#1%
    \expandafter\GPT@ZapLeadingZeros
  \else
    #1%
  \fi
}
\def\Grot@start{%
  \GPT@NormalizeNumber\Grot@sin
  \GPT@NormalizeNumber\Grot@cos
  \edef\GPT@temp{%
    \Grot@cos\GPT@space\Grot@sin\GPT@space
    \if-\Grot@sin
    \else
      \ifx\Grot@sin\GPT@Zero
        \GPT@Zero
      \else
        -\Grot@sin
      \fi
    \fi
    \GPT@space\Grot@cos
  }%
  \ifx\GPT@temp\GPT@MatrixIdentity
    \def\Grot@end{}%
  \else
    \pdfsave
    \pdfsetmatrix{\GPT@temp}%
    \wd\z@\z@
  \fi
}
\def\Grot@end{\pdfrestore}

\else
\fi
  % dvips
  \def\GPT@space{ }
  \def\Grot@start{%
   \special{ps: gsave currentpoint
   currentpoint translate \Grot@angle\GPT@space neg
   rotate neg exch neg exch translate}}
  \def\Grot@end{\special{ps: currentpoint grestore moveto}}
\fi

\catcode`\@=\active
