%D \module
%D   [       file=cont-log,
%D        version=1995.10.10,
%D          title=\CONTEXT\ Miscellaneous Macros,
%D       subtitle=\TEX\ Logos,
%D         author=J. Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt TeX Logos}

%D The system that is used to typeset this text is called \TEX, typeset with an
%D lowered~E. From te beginning of \TEX, authors of macro packages adapted this
%D raising and lowering style. In this module we define some of those logos.

%D We define the uppercase logo commands as (unfrozen) instances because they can be
%D redefined in the synonyms modules. We use old school definitions. Watch out: when
%D a math font is used the \AMS\ logos can come out ugly but they are ugly anyway.

%D We will at some point move the non-\CONTEXT\ logos to the abbreviations file
%D because it makes no sense to have e.g. the \LATEX\ logo defined here.

\unprotect

% \protected\frozen\instance\def\TeX
%   {\dontleavehmode
%    \begingroup
%    T%
%    \setbox\scratchbox\hbox{M}%
%    \kern-.1667\wd\scratchbox
%    \lower.5\exheight\hbox{E}%
%    \kern-.125\wd\scratchbox
%    X%
%    \endgroup}

\protected\frozen\instance\def\TeX
  {\dontleavehmode
   \begingroup
   \scratchdimen\scaledfontcharwd\font`M%
   T%
   \kern-.1667\scratchdimen
  %\lower.3183\scaledfontcharht\font`T\hbox{E}% .318316 but no exact match possible anyway
   \lower.5\exheight\hbox{E}% but on the average this looks better
   \kern-.125\scratchdimen
   X%
   \endgroup}

\protected\frozen\instance\def\TeXsuffix{\wordboundary\TeX}
\protected\frozen\instance\def\TeXprefix{\TeX\wordboundary}

\def\syst_logos_context
  {Con%
   \wordboundary
   \setbox\scratchboxone\hbox{T\kern\zeropoint e}%
   \setbox\scratchboxtwo\hbox{Te}%
   \discretionary{-}{}{\kern{\wd\scratchboxtwo-\wd\scratchboxone}}%
   \TeX t}

\protected\frozen\instance\def\ConTeXt
  {\dontleavehmode
   \begingroup
   \ifcase\getcharactercasingcategory % todo: also other logos
     \syst_logos_context
   \or % 1 uppercase
     \syst_logos_context
   \or % 2 lowercase
     \resetcharactercasing
     con\-text%
   \else
     Con\-text%
   \fi
   \endgroup}

\protected\frozen\instance\def\PPCHTeX{ppch\TeX}

\protected\frozen\instance\def\LaTeX % requested by erik frambach
  {\dontleavehmode
   \begingroup
   \setbox\scratchbox\hbox{L}%
   \scratchdimen\ht\scratchbox
   \setbox\scratchbox\hbox{\doresetattribute{case}\txx A}%
   L\kern-.55\wd\scratchbox
   \raise\scratchdimen\hbox{\lower\ht\scratchbox\copy\scratchbox}%
   \kern-.2\wd\scratchbox\TeX
   \endgroup}

\protected\frozen\instance\def\TaBlE
  {T%
   \kern-.27\emwidth\lower.5\exheight\hbox{A}%
   \kern-.18\emwidth B%
   \kern-.1\emwidth\lower.5\exheight\hbox{L}%
   \kern-.075\emwidth E}

\protected\frozen\instance\def\PiCTeX
  {P%
   \kern-.12\emwidth\lower.5\exheight\hbox{I}%
   \kern-.075\emwidth C%
   \kern-.11\emwidth\TeX}

\def\syst_logos_ams_script#1%
  {\normalstartimath
   \cal\ifdim\bodyfontsize>1.1\emwidth\scriptstyle\fi#1%
   \normalstopimath}

\protected\frozen\instance\def\AmSTeX
  {\dontleavehmode
   \syst_logos_ams_script A%
   \kern-.5\emwidth\lower.5\exheight\hbox{\syst_logos_ams_script M}% was .1667 for old math
   \kern-.125\emwidth\syst_logos_ams_script S%
   -\TeX}

\protected\frozen\instance\def\LamSTeX
  {L%
   \kern-.4\emwidth\raise.4\exheight\hbox{\syst_logos_ams_script A}% was .4 .3 for old math
   \kern-.5\emwidth\lower.3\exheight\hbox{\syst_logos_ams_script M}% was .25 for old math
   \kern-.125\emwidth{\syst_logos_ams_script S}%
   -\TeX}

%D Alternative \CONTEXT\ logo, first Idris S.~Hamid's version:
%D
%D \def\Context
%D   {{\sc C\kern -.0667emo\kern -.0667emn\kern -.0549emt\kern
%D    -.1667em\lower.5ex\hbox {e}\kern -.125emx\kern -.0549emt}}
%D
%D I changed this into one that adapts itself:

\protected\frozen\instance\def\Context % wrong usage of \getscaledglyph
  {\dontleavehmode
   \begingroup
   C%
   \kern -.0667\emwidth
   \getscaledglyph{.8}\empty{%
     O\kern-.0667\emwidth
     N%
     \discretionary{-}{}{\kern-.0549\emwidth}%
     T%
     \doifelseitalic{\kern-.1\emwidth}{\kern-.1667\emwidth}%
     \lower.5\exheight\hbox{E}%
     \doifelseitalic\empty{\kern-.11em}%
     X%
     \kern-.055\emwidth
     T%
   }%
   \endgroup}

%D The \METAFONT\ and \METAPOST\ logos adapt themselves to the current fontsize, an
%D ugly but usefull hack.

\mutable\let\logofont\nullfont

% \loadmapfile[original-base.map] % stil needed? not if we assume afm

\permanent\protected\def\setMFPfont% more sensitive for low level changes
  {\font\logofont=logo%
     \ifx\fontalternative\s!bf\s!bf\orelse
     \ifx\fontalternative\s!it\s!sl\orelse
     \ifx\fontalternative\s!sl\s!sl\orelse
     \ifx\fontalternative\s!bi\s!bf\orelse
     \ifx\fontalternative\s!bs\s!bf\fi
     10 at \currentfontscale\bodyfontsize % there is no afm in the minimals yet
   \logofont}

\def\syst_logos_meta_hyphen % there is no hyphenchar in this font
  {\discretionary{\vrule\s!height.33\emwidth\s!depth-.27\emwidth\s!width.33\emwidth}{}{}}

\protected\frozen\instance\def\MetaFontLogo
  {\dontleavehmode
   \begingroup
   \setMFPfont META\syst_logos_meta_hyphen FONT%
   \endgroup}

\protected\def\MetaPostLogo
  {\dontleavehmode
   \begingroup
   \setMFPfont META\syst_logos_meta_hyphen POST%
   \endgroup}

% \protected\def\MetaFunLogo
%   {\dontleavehmode
%    \begingroup
%    \setMFPfont META\syst_logos_meta_hyphen FUN%
%    \endgroup}

% As decided on the ConText Meeting 2013 the logo has been simplified:

\protected\instance\def\MetaFont{MetaFont}
\protected\instance\def\MetaPost{MetaPost}
\protected\instance\def\MetaFun {MetaFun}

%D \macros
%D  {TEX, METAFONT, METAPOST, METAFUN,
%D   PICTEX, TABLE,
%D   CONTEXT, PPCHTEX,
%D   AMSTEX, LATEX, LAMSTEX}
%D
%D We define the funny written ones as well as the less error prone upper case names
%D (in \CONTEXT\ we tend to write all user defined commands, like abbreviations, in
%D uppercase.)

\protected\instance\def\METAFONT{\MetaFont}
\protected\instance\def\METAPOST{\MetaPost}
\protected\instance\def\PPCHTEX {\PPCHTeX}
\protected\instance\def\CONTEXT {\ConTeXt}
\protected\instance\def\METAFUN {\MetaFun}

\protected\instance\def\TEX     {\TeX}
\protected\instance\def\LATEX   {\LaTeX}
\protected\instance\def\PICTEX  {\PiCTeX}
\protected\instance\def\TABLE   {\TaBlE}
\protected\instance\def\AMSTEX  {\AmSTeX}
\protected\instance\def\LAMSTEX {\LamSTeX}
\protected\instance\def\INRSTEX {inrs\TeX}

\protected\instance\def\PRAGMA  {Pragma ADE}
\protected\instance\def\LUA     {\Lua} % below

%D And this is how they show up: \TeX, \MetaFont, \MetaPost, \PiCTeX, \TaBlE, \ConTeXt,
%D \PPCHTeX, \AmSTeX, \LaTeX, \LamSTeX.

%D Some placeholders:

%protected\frozen\instance\def\eTeX      {\mathematics{\varepsilon}-\TeX}
\protected\frozen\instance\def\pdfTeX    {pdf\wordboundary\TeX}
\protected\frozen\instance\def\luaTeX    {lua\wordboundary\TeX}
\protected\frozen\instance\def\Lua       {Lua}
\protected\frozen\instance\def\luajitTeX {lua\wordboundary jit\wordboundary\TeX}
\protected\frozen\instance\def\luametaTeX{lua\wordboundary meta\wordboundary\TeX}
\protected\frozen\instance\def\XeTeX     {X\lower.5\exheight\hbox{\kern-.15\emwidth\mirror{E}}\kern-.1667\emwidth\TeX}

%protected\frozen\instance\def\eTeX      {{\tf \nocap $\varepsilon$}-\TeX} % compact mode hack for epsilon
%protected\frozen\instance\def\pdfeTeX   {pdfe-\wordboundary\TeX}

% The epsilon in the etex logo is kind of weird and also not that pretty. Taking it
% from a math font is risky and we also don't want math in tagged stuff so let's go
% for a bit more simple and modern variant. More logos qualify for such a treatment.

% \def\Test#1{{Test \eTeX\ Some \pdfeTeX\ Logos} (#1)}
%
% \startTEXpage[offset=1ts,strut=no] \showglyphs
%   \startlines[before=,after=]
%                 \Test{no caps}
%     {\smallcaps \Test{real smallcaps}}
%     \fsc       {\Test{emulated small caps}}
%     \cap       {\Test{pseudo small caps}}
%   \stoplines
% \stopTEXpage

\protected\frozen\instance\def\eTeX
  {\dontleavehmode
  %{\nocap e}% we keep \smallcaps
   e%
   \begingroup
   \scratchdimen.05\emwidth
   \kern\scratchdimen-\kern-2\scratchdimen
   \endgroup
   \TeX}

\protected\frozen\instance\def\pdfeTeX
  {pdf%
   \begingroup
   \scratchdimen.05\emwidth
   \kern\scratchdimen-\kern\scratchdimen
   e%
   \discretionary
     {\kern\scratchdimen-}{}%
     {\kern\scratchdimen-\kern-2\scratchdimen}%
   \endgroup
   \TeX}

% % Adapted from a patch by Mojca:
%
% \def\syst_logos_xetex_e
%   {\setbox\scratchbox\hbox{E}%
%    \raise\dimexpr\ht\scratchbox+\dp\scratchbox\relax\hbox{\rotate[\c!rotation=180]{\box\scratchbox}}}
%
% \protected\frozen\instance\def\XeTeX
%   {X\lower.5\exheight
%    \hbox
%      {\kern-.15\emwidth
%       \iffontchar\font"018E\relax
%         \char"018E%
%       \else
%         \ifx\fontalternative\s!bf         \mirror{E}\orelse
%         \ifx\fontalternative\s!it\syst_logos_xetex_e\orelse
%         \ifx\fontalternative\s!sl\syst_logos_xetex_e\orelse
%         \ifx\fontalternative\s!bi\syst_logos_xetex_e\orelse
%         \ifx\fontalternative\s!bs\syst_logos_xetex_e\else
%                                           \mirror{E}\fi
%       \fi}%
%    \kern-.1667\emwidth\TeX}

% This is good enough for the few times that we need it:

\def\syst_logos_xe
  {X\lower.5\exheight
   \hbox\bgroup
     \kern-.15\emwidth
     \iffontchar\font"018E\relax
       \char"018E%
     \else
       \mirror{E}%
     \fi
   \egroup}

\protected\frozen\instance\def\XeTeX  {\syst_logos_xe\kern-.1667\emwidth\TeX}
\protected\frozen\instance\def\XeLaTeX{\syst_logos_xe\LaTeX}

\protected\instance\def\ETEX      {\eTeX}
\protected\instance\def\PDFTEX    {\pdfTeX}
\protected\instance\def\PDFETEX   {\pdfeTeX}
\protected\instance\def\LUATEX    {\luaTeX}
\protected\instance\def\LUAJITTEX {\luajitTeX}
\protected\instance\def\LuaTeX    {\luaTeX}
\protected\instance\def\LuaMetaTeX{\luametaTeX}
\protected\instance\def\LUAMETATEX{\luametaTeX}
\protected\instance\def\XETEX     {\XeTeX}

\protected\frozen\instance\def\LuaTeX
  {\dontleavehmode
   \begingroup
     Lua%
     % hope for kerning, try aT
     \setbox0\hbox{aT}%
     \setbox2\hbox{a\kern\zeropoint T}%
     \ifdim\wd0=\wd2 % kerns can go two ways
       % no aT kerning, try oT as a is not symmetrical
       \setbox0\hbox{oT}%
       \setbox2\hbox{o\kern\zeropoint T}%
       \ifdim\wd0=\wd2 % kerns can go two ways
         % no aT and oT kerning, try To
         \setbox0\hbox{To}%
         \setbox2\hbox{T\kern\zeropoint o}%
         % maybe we need to compensate for the angle (sl/it/bs/bi)
       \fi
       \ifdim\wd0=\wd2\else
         \kern{\wd0-\wd2}%
       \fi
     \fi
     \TeX
   \endgroup}

\protected\frozen\instance\def\LuajitTeX
  {\dontleavehmode
   \begingroup
     % at this moment there is no real need for kerning tT
     Luajit\kern\zeropoint\TeX
   \endgroup}

\frozen\instance\let\luaTeX   \LuaTeX
\frozen\instance\let\luajitTeX\LuajitTeX

\protected\instance\def\LUATEX   {\LuaTeX}
\protected\instance\def\LUAJITTEX{\LuajitTeX}

% It's all about sound ... and for obvious reasons we avoided III.

\protected\instance\def\MKII{MkII} % MarkTwo
\protected\instance\def\MKIV{MkIV} % MarkFour   : MKIV
\protected\instance\def\MKVI{MkVI} % MarkSix    : MKIV
\protected\instance\def\MKXL{MkXL} % MarkFourty : LMTX
\protected\instance\def\MKLX{MkLX} % MarkSixty  : LMTX
\protected\instance\def\MKIX{MkIX} %            : MKIV / LMTX
\protected\instance\def\MKXI{MkXI} %            : MKIV / LMTX

\protected\instance\def\MPII{MpII} % MarkTwo
\protected\instance\def\MPIV{MpIV} % MarkFour   : MetaFun
\protected\instance\def\MPVI{MpVI} % MarkSix    : MetaFun
\protected\instance\def\MPXL{MpXL} % MarkFourty : LuaMetaFun
\protected\instance\def\MPLX{MpLX} % MarkSixty  : LuaMetaFun

\protected\instance\def\LMTX{LMTX} % for LuaMetaTeX + Mk[X.|.X] i.e. the distribition / ecosystem

\protected\instance\def\MKMI{MkMI} % Mark One O O One   : reserved for unvailable machine intelligence
\protected\instance\def\MKML{MkML} % Mark One O O Fifty : reserved for unvailable machine learning

\appendtoks
    \enforced\instance\def\ConTeXt   {ConTeXt}%
    \enforced\instance\def\MetaPost  {MetaPost}%
    \enforced\instance\def\MetaFont  {MetaFont}%
    \enforced\instance\def\MetaFun   {MetaFun}%
    \enforced\instance\def\TeX       {TeX}%
    \enforced\instance\let\TeXsuffix \TeX
    \enforced\instance\let\TeXprefix \TeX
    \enforced\instance\def\LuaTeX    {LuaTeX}%
    \enforced\instance\def\LuajitTeX {LuajitTeX}%
    \enforced\instance\def\LuaMetaTeX{LuaMetaTeX}%
\to \everysimplifycommands

\protect \endinput
