texjporg / platex

pLaTeX community edition
BSD 3-Clause "New" or "Revised" License
49 stars 8 forks source link

\strut #81

Open aminophen opened 5 years ago

aminophen commented 5 years ago

20 (\strutbox 見直し)の続きで,今度は \strut です。

縦数式ディレクションの \strut では,\tstrutbox ではなく \zstrutbox を使うほうが自然に見える(横書きの 90 度回転ぴったりになる)のですが,いかがでしょうか。以下の例示ソースは,pLaTeX / LuaLaTeX 両方でコンパイルできるようにしてあります。

\documentclass{article}

% minipage dir <t>
\ifx\directlua\undefined
  \usepackage{plext}
\else
  \usepackage{lltjext}
\fi

\usepackage{amsmath}% \cfrac を使うため (\strut used in math mode)
\newcommand{\myunderline}[1]{\underline{\rule[-.5ex]{0pt}{1.5ex}#1}}
\newcommand{\varunderline}[1]{\underline{\strut #1}}
\def\TESTA#1{#1{h}, #1{m}, #1{g}, #1{y}, #1{あ}}
\def\TESTB#1{#1{$\int_0^\infty \frac{1}{x}\,\mathrm{d}x$}}
\def\TEST{%
  漢\TESTA\underline, \TESTB\underline\par
  漢\TESTA\myunderline, \TESTB\myunderline\par
  漢\TESTA\varunderline, \TESTB\varunderline\par
  漢$A_1^2 \strut_1^2 \int_0^\infty \frac{1}{x}\,\mathrm{d}x$
  $\cfrac{1}{\sqrt{2}+\cfrac{1}{\sqrt{2}+\cfrac{1}{\sqrt{2}+\dotsb}}}$}

\usepackage{graphicx}% for \rotatebox{90}{...} to compare overlay

\begin{document}

横
\begin{minipage}<y>{10cm}
\TEST
\end{minipage}
\clearpage
縦
\rotatebox{90}{\begin{minipage}<t>{10cm}
\TEST
\end{minipage}}

\end{document}

pLaTeX の場合だと,具体的なコード案は下記の通りです。

%% 新定義
\makeatletter
%% \strut の改良版
\def\strut{\relax
  \iftdir
    \ifmdir
      %% [縦数式ディレクション]
      %% テキストモードの場合は \zstrutbox でなければならない気がする。
      %% (下線 \underline で使う場合に横組の 90 度回転にならない)
      %% 数式モードの場合は \zstrutbox に変えるとかえってバランスが崩れるが,
      %% これは \copy したボックスにベースライン補正が効かないためであり,
      %% その分 \lower で下げる。
      \ifmmode \lower \tbaselineshift \copy \zstrutbox \else \unhcopy \zstrutbox \fi
    \else
      %% [縦ディレクション]
      %% テキストモードの場合は \tstrutbox で良い。
      %% 数式モードに入ると自動的に [縦数式ディレクション] に入るので分岐不要。
      \unhcopy \tstrutbox
    \fi
  \else
    %% [横ディレクション]
    %% テキストモードの場合は \(y)strutbox で良い。
    %% 数式モードではベースライン補正分だけ \lower で下げる。
    \ifmmode \lower \ybaselineshift \copy \ystrutbox \else \unhcopy \ystrutbox \fi
  \fi}
%% \strutbox は \zstrutbox を使うとまずそうなので 2017-04-08 のまま
%\def\strutbox{%
%  \iftdir \ifmdir \zstrutbox \else \tstrutbox \fi
%  \else \ystrutbox \fi}
\makeatother
aminophen commented 5 years ago

exppl2e.sty に入れました。正式に pLaTeX に入れるかどうかは追って検討します。