12

This is a turnstile with and without a subscript

\def\stile{{|\kern-.225em-}}

\def\sstile#1{{|\kern-.225em-}_{\rm #1}}

$$\stile \alpha$$

$$\sstile{K} \alpha$$

\bye

It would be nice to have just one command and be able to type either \stile \alpha or \stile[K] \alpha. How is that done?

enter image description here

1
  • You can look into latex.ltx how \newcommand is defined in order to make your Plain version of that
    – user31729
    Commented Mar 4, 2018 at 15:07

4 Answers 4

23

Look ahead for the [:

\def\stile{\futurelet\next\dostile}
\def\dostile{%
  \mathrel{|\mkern-4mu{-}}
  \ifx[\next %]
    \expandafter\dostileopt
  \fi
}
\def\dostileopt[#1]{_{\rm #1}}

$\stile \alpha$

$\stile[K] \alpha$

\bye

enter image description here

17

You could use the plain compatible eplain macros:

enter image description here

\input eplain

\catcode`\@=11

\def\stile{\@getoptionalarg\xstile}

\def\xstile{{|\kern-.225em-}%
    \ifx\@optionalarg\empty\else_{\rm\@optionalarg}\fi}

\catcode`\@=12

$$\stile \alpha$$

$$\stile[K] \alpha$$

\bye
5

With a primitive implementation of \@ifnextchar (taking the one from latex.ltx would be better, I guess):

\catcode`\@=11
\long\def\@firstoftwo#1#2{#1}%
\long\def\@secondoftwo#1#2{#2}%
\long\def\@ifnextchar#1#2#3#4{%
  \ifx#1#4%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {#2}{#3}#4}%
\def\stile{\@ifnextchar[{\stile@i}{\stile@ii}}%
\def\stile@i[#1]{{|\kern-.225em-}_{\rm #1}}%
\def\stile@ii{{|\kern-.225em-}}%
\catcode`\@=12

$$\stile \alpha$$

$$\stile[K] \alpha$$

\bye

A more stable version of \@ifnextchar (similar to the one of latex.ltx but not the same):

\long\def\@ifnextchar#1#2#3{%
  \let\@tmpa=#1%
  \def\@tmpb{#2}%
  \def\@tmpc{#3}%
  \futurelet\@future\@ifnextchar@i}%
\def\@ifnextchar@i{%
  \ifx\@tmpa\@future%
    \expandafter\@tmpb
  \else
    \expandafter\@tmpc
  \fi}%
3
  • The problem with this is that \stile{[}K] works like this, or may be \stile {[A/B] \over C} will give problems.
    – Manuel
    Commented Mar 4, 2018 at 15:29
  • @Manuel as I said, it's a primitive implementation.
    – Skillmon
    Commented Mar 4, 2018 at 15:50
  • A primitive definition of \ifnextchar (that does not skip spaces) could be easily done with \futurelet like egreg. I just wanted to note that, if someone knows what (s)he's doing (s)he can use this version.
    – Manuel
    Commented Mar 4, 2018 at 16:02
1

I realize that you tagged this {plain-tex}, but this really is an instance in which the use of LaTeX, with the turnstile package, would be of considerable help.

You could then simply use, $\sststile{\mathrm{K}}{} \alpha$. This package would also improve the overall typesetting quality of your turnstiles (refer to the below image, from the turnstile article), and provide a myriad of additional options.

Comparison of turnstile subscript typography

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .