Created
June 4, 2026 13:50
-
-
Save h20y6m/0c16a0f07532d444652e4af6fefddc48 to your computer and use it in GitHub Desktop.
pLaTeX: 数式を使わずに縦組みで横組みを90度回転
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \documentclass[dvipdfmx]{tarticle} | |
| \usepackage{xcolor} \everymath{\color{red}} | |
| % | |
| %%% Adjust LaTeX 2026-06-01 | |
| \makeatletter | |
| \def\pltx@if@tate@text@dir{% | |
| \ifnum0\iftdir1\fi\ifmmode\else1\fi=11 % | |
| \expandafter\@firstoftwo | |
| \else | |
| \expandafter\@secondoftwo | |
| \fi} | |
| \protected\def\vcenter@text@auxii{% | |
| \begingroup | |
| \dimen0\dimexpr\ht0+\dp0\relax | |
| \ht0\dimexpr\dimexpr\ifodd\dimen0 1sp + \fi\dimen0\relax/2 | |
| +\vcenter@text@axis | |
| -\pltx@if@tate@text@dir | |
| \tbaselineshift | |
| \ybaselineshift\relax | |
| \dp0\dimexpr\dimen0-\ht0\relax | |
| \box0 % | |
| \endgroup | |
| } | |
| % | |
| \ifdefined\vcenter@text\else | |
| \protected\def\vcenter@text{% | |
| \check@mathfonts | |
| \afterassignment\vcenter@text@auxi | |
| \setbox0\vbox} | |
| \protected\def\vcenter@text@auxi{% | |
| \aftergroup\vcenter@text@auxii | |
| } | |
| \newcommand*\vcenter@text@axis{\fontdimen22 \textfont2 } | |
| \fi | |
| \makeatother | |
| % | |
| %%%%%%%%%%%%%%%%%%%% BEGIN CODE %%%%%%%%%%%%%%%%%%%% | |
| \makeatletter | |
| \ExplSyntaxOn | |
| % 一時的に組方向を変えるためのボックス | |
| \box_new:N \l__plext_direction_box | |
| % | |
| \tl_new:N \l__plext_yoko_box_dim_tl | |
| % 横組みでのboxの寸法 | |
| % #1: box | |
| % #2: ht dim | |
| % #3: dp dim | |
| \cs_new_protected:Npn \__plext_get_yoko_box_ht_dp:NNN #1 #2 #3 | |
| { | |
| \hbox_set:Nw \l__plext_direction_box | |
| \tex_yoko:D | |
| \tl_set:Ne \l__plext_yoko_box_dim_tl | |
| { | |
| \dim_set:Nn #2 { \dim_use:N \box_ht:N #1 } | |
| \dim_set:Nn #3 { \dim_use:N \box_dp:N #1 } | |
| } | |
| \exp_after:wN | |
| \hbox_set_end: | |
| \l__plext_yoko_box_dim_tl | |
| } | |
| \box_new:N \l__plext_ztext_box | |
| \dim_new:N \l__plext_ztext_ht_dim | |
| \dim_new:N \l__plext_ztext_dp_dim | |
| \dim_new:N \l__plext_ztext_htdp_dim | |
| % 前提条件: | |
| % ・#1は横組みボックスであること | |
| % ・現在の組方向が縦組みであること | |
| \cs_new_protected:Npn \__plext_ztext_rotate:N #1 | |
| { | |
| \__plext_get_yoko_box_ht_dp:NNN #1 | |
| \l__plext_ztext_ht_dim | |
| \l__plext_ztext_dp_dim | |
| \box_rotate:Nn #1 { -90 } | |
| % ・\box_rotate:Nnの結果は常にhbox | |
| % ・縦組みから見た寸法をもとに回転するので | |
| % ・高さ=0 | |
| % ・深さ=元の横組みの(高さ+深さ) | |
| % ・幅=元の横組みの幅 | |
| % の状態になっている | |
| \hbox_set:Nn #1 | |
| { | |
| \box_move_up:nn | |
| { | |
| \l__plext_ztext_ht_dim | |
| - \tex_tbaselineshift:D | |
| + \tex_ybaselineshift:D | |
| } | |
| { \box_use:N #1 } | |
| } | |
| } | |
| % 前提条件: | |
| % ・#1は横組みボックスであること | |
| % ・現在の組方向が縦組みであること | |
| \cs_new_protected:Npn \__plext_ztext_rotate_vcenter:N #1 | |
| { | |
| \__plext_get_yoko_box_ht_dp:NNN #1 | |
| \l__plext_ztext_ht_dim | |
| \l__plext_ztext_dp_dim | |
| \box_rotate:Nn #1 { -90 } | |
| \__plext_ztext_adjust_vcenter_ht_dp:NN | |
| \l__plext_ztext_ht_dim | |
| \l__plext_ztext_dp_dim | |
| \hbox_set:Nn #1 | |
| { | |
| \box_move_up:nn | |
| { \l__plext_ztext_ht_dim } | |
| { \box_use:N #1 } | |
| } | |
| } | |
| % #1: ht dim | |
| % #2: dp dim | |
| % ref. \vcenter@text@auxii | |
| \cs_new_protected:Npn \__plext_ztext_adjust_vcenter_ht_dp:NN #1 #2 | |
| { | |
| \dim_set:Nn \l__plext_ztext_htdp_dim | |
| { #1 + #2 } | |
| \dim_set:Nn #1 | |
| { | |
| \int_if_odd:nTF { \l__plext_ztext_htdp_dim } | |
| { \dim_eval:n { \l__plext_ztext_htdp_dim + 1sp } / 2 } | |
| { \l__plext_ztext_htdp_dim / 2 } | |
| + \vcenter@text@axis | |
| - \bool_lazy_and:nnTF | |
| { \platex_if_direction_tate_p: } | |
| { ! \mode_if_math_p: } | |
| { \tex_tbaselineshift:D } | |
| { \tex_ybaselineshift:D } | |
| } | |
| \dim_set:Nn #2 | |
| { \l__plext_ztext_htdp_dim - #1 } | |
| } | |
| % for 2e code | |
| \cs_set_eq:NN \@plext@ztext@rotate@@N | |
| \__plext_ztext_rotate:N | |
| \cs_set_eq:NN \@plext@ztext@rotate@vcenter@@N | |
| \__plext_ztext_rotate_vcenter:N | |
| \ExplSyntaxOff | |
| % | |
| % | |
| \newbox\@plext@ztext@box | |
| % | |
| % | |
| % | |
| % | |
| \protected\def\plext@hbox@ztext{% | |
| \pltx@if@tate@text@dir\plext@hbox@ztext@\hbox} | |
| \protected\def\plext@hbox@ztext@{% | |
| \afterassignment\plext@ztext@auxi | |
| \setbox\@plext@ztext@box\hbox} | |
| % | |
| \protected\def\plext@vbox@ztext{% | |
| \pltx@if@tate@text@dir\plext@vbox@ztext@\vbox} | |
| \protected\def\plext@vbox@ztext@{% | |
| \afterassignment\plext@ztext@auxi | |
| \setbox\@plext@ztext@box\vbox} | |
| % | |
| \protected\def\plext@vtop@ztext{% | |
| \pltx@if@tate@text@dir\plext@vtop@ztext@\vtop} | |
| \protected\def\plext@vtop@ztext@{% | |
| \afterassignment\plext@ztext@auxi | |
| \setbox\@plext@ztext@box\vtop} | |
| % | |
| \protected\def\plext@ztext@auxi{% | |
| \yoko | |
| \aftergroup\plext@ztext@auxii | |
| } | |
| \protected\def\plext@ztext@auxii{% | |
| \begingroup | |
| \@plext@ztext@rotate@@N \@plext@ztext@box | |
| \box\@plext@ztext@box | |
| \endgroup | |
| } | |
| % | |
| % | |
| \protected\def\plext@vcenter@ztext{% | |
| \pltx@if@tate@text@dir\plext@vcenter@ztext@\vcenter@text} | |
| \protected\def\plext@vcenter@ztext@{% | |
| \check@mathfonts | |
| \afterassignment\plext@vcenter@ztext@auxi | |
| \setbox\@plext@ztext@box\vbox} | |
| % | |
| \protected\def\plext@vcenter@ztext@auxi{% | |
| \yoko | |
| \aftergroup\plext@vcenter@ztext@auxii | |
| } | |
| \protected\def\plext@vcenter@ztext@auxii{% | |
| \begingroup | |
| \@plext@ztext@rotate@vcenter@@N \@plext@ztext@box | |
| \box\@plext@ztext@box | |
| \endgroup | |
| } | |
| % | |
| \makeatother | |
| %%%%%%%%%%%%%%%%%%%% END CODE %%%%%%%%%%%%%%%%%%%% | |
| % | |
| \begin{document} | |
| \makeatletter | |
| % | |
| \tbaselineshift=2zw | |
| \ybaselineshift=1zw | |
| % | |
| \par \hrulefill \par | |
| あいうえお\plext@hbox@ztext{かきくけこ}さしすせそ | |
| あいうえお\null$\m@th\hbox{かきくけこ}$\null さしすせそ | |
| \par \hrulefill \par | |
| あいうえお\plext@vbox@ztext{\hsize=2zw かきくけこ}さしすせそ | |
| あいうえお\null$\m@th\vbox{\hsize=2zw かきくけこ}$\null さしすせそ | |
| \par \hrulefill \par | |
| あいうえお\plext@vtop@ztext{\hsize=2zw かきくけこ}さしすせそ | |
| あいうえお\null$\m@th\vtop{\hsize=2zw かきくけこ}$\null さしすせそ | |
| \par \hrulefill \par | |
| あいうえお\plext@vcenter@ztext{\hsize=2zw かきくけこ}さしすせそ | |
| あいうえお\null$\m@th\vcenter{\hsize=2zw かきくけこ}$\null さしすせそ | |
| \par \hrulefill \par | |
| % | |
| \par \hrulefill \par | |
| $あいうえお\plext@hbox@ztext{かきくけこ}さしすせそ$ | |
| $あいうえお\hbox{かきくけこ}さしすせそ$ | |
| \par \hrulefill \par | |
| $あいうえお\plext@vbox@ztext{\hsize=2zw かきくけこ}さしすせそ$ | |
| $あいうえお\vbox{\hsize=2zw かきくけこ}さしすせそ$ | |
| \par \hrulefill \par | |
| $あいうえお\plext@vtop@ztext{\hsize=2zw かきくけこ}さしすせそ$ | |
| $あいうえお\vtop{\hsize=2zw かきくけこ}さしすせそ$ | |
| \par \hrulefill \par | |
| $あいうえお\plext@vcenter@ztext{\hsize=2zw かきくけこ}さしすせそ$ | |
| $あいうえお\vcenter{\hsize=2zw かきくけこ}さしすせそ$ | |
| $あいうえお\vcenter@text{\hsize=2zw かきくけこ}さしすせそ$ | |
| \par \hrulefill \par | |
| % | |
| \makeatother | |
| \end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment