Skip to content

Instantly share code, notes, and snippets.

@aminophen
Created February 4, 2020 13:28
Show Gist options
  • Save aminophen/c536e298f11a8ae3e9b9cd81dc74316b to your computer and use it in GitHub Desktop.
Save aminophen/c536e298f11a8ae3e9b9cd81dc74316b to your computer and use it in GitHub Desktop.
pTeX: ある fontdef トークンが欧文フォントか和文横組フォントか和文縦組フォントか
\catcode`\@=11
\ifx\@firstoftwo\@undefined
\def\@firstoftwo#1#2{#1}
\fi
\ifx\@secondoftwo\@undefined
\def\@secondoftwo#1#2{#2}
\fi
\def\ptexutil@ifjfont#1{\putl@parse@fontdef{#1}%
\if j\putl@fonttype \expandafter\@firstoftwo
\else \expandafter\@secondoftwo \fi}
\def\ptexutil@iftfont#1{\putl@parse@fontdef{#1}%
\if t\putl@fonttype \expandafter\@firstoftwo
\else \expandafter\@secondoftwo \fi}
\def\ptexutil@ifafont#1{\putl@parse@fontdef{#1}%
\if a\putl@fonttype \expandafter\@firstoftwo
\else \expandafter\@secondoftwo \fi}
{\escapechar-1 \xdef\putl@select@font{\string\select\space\string\font\space}}
\def\putl@parse@fontdef#1{%
\def\reserved@a{#1}%
\edef\putl@parse@tmp{\meaning#1 \putl@select@font}%
\expandafter\putl@parse@@fontdef\putl@parse@tmp\@nil}
\expandafter\def\expandafter\putl@parse@@fontdef
\expandafter#\expandafter1\putl@select@font#2\@nil{%
\ifx\relax#1\relax \putl@dist@font \else \putl@err@notfontdef \fi}
\def\putl@dist@font{{\reserved@a
\expandafter\expandafter\expandafter\ifx
\expandafter\the\expandafter\jfont\reserved@a
\global\def\putl@fonttype{j}\else
\expandafter\expandafter\expandafter\ifx
\expandafter\the\expandafter\tfont\reserved@a
\global\def\putl@fonttype{t}\else
\expandafter\expandafter\expandafter\ifx
\expandafter\the\expandafter\font\reserved@a
\global\def\putl@fonttype{a}\else
\global\def\putl@fonttype{n}\fi
\fi\fi
}}
\def\putl@err@notfontdef{%
\errhelp{This command cannot be used for non-font.}%
\errmessage{\expandafter\string\reserved@a\space is not a font}}
\newlinechar`^^J
\font\TEST=min10
\ptexutil@ifjfont\TEST{\TTTT}{\FFFF}
\ptexutil@iftfont\TEST{\TTTT}{\FFFF}
\font\X=tmin10
\ptexutil@iftfont\X{\TTTT}{\FFFF}
\ptexutil@iftfont\nullfont{\TTTT}{\FFFF}
\ptexutil@ifafont\nullfont{\TTTT}{\FFFF}
\def\TEST{\endgroup}
\ptexutil@ifjfont\TEST{\TTTT}{\FFFF}
\ptexutil@ifjfont\putl@select@font{\TTTT}{\FFFF}
\ptexutil@ifafont\relax{\TTTT}{\FFFF}
\catcode`\@=12
\end
@aminophen
Copy link
Author

texjporg/tex-jp-build#97 を実装する前に,マクロで強引にやろうとしたやつ。

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