%D \module
%D   [      file=s-math-parameters.mkiv, % was s-mat-12.mkiv
%D        version=2012.06.06, % whatever, probably a bit earlier
%D          title=\CONTEXT\ Style File,
%D       subtitle=Show Math Character Repertoire,
%D         author=Hans 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.

\enabletrackers[pages.timing]

\enableexperiments[fonts.compact]

\usemodule[s][math-characters]

% context --global --bodyfont=lucidaot --result=math-repertoire-lucidaot s-math-repertoire.mkiv
% context --global --bodyfont=cambria  --result=math-repertoire-cambria  s-math-repertoire.mkiv
% context --global --bodyfont=xits     --result=math-repertoire-xits     s-math-repertoire.mkiv
% context --global --bodyfont=modern   --result=math-repertoire-modern   s-math-repertoire.mkiv
% context --global --bodyfont=pagella  --result=math-repertoire-pagella  s-math-repertoire.mkiv
% context --global --bodyfont=termes   --result=math-repertoire-termes   s-math-repertoire.mkiv
% context --global --bodyfont=bonum    --result=math-repertoire-bonum    s-math-repertoire.mkiv

\startmodule[math-repertoire]

% layout

\definecolor[backgroundcolor] [r=.6,g=.6]
\definecolor[backgroundcolorx][r=.6]
\definecolor[backgroundcolory][g=.6]
\definecolor[baselinecolor]   [a=1,t=.5,s=.6]
\definecolor[charactercolor]  [b=.6]
\definecolor[italiccolor]     [r=.6]
\definecolor[anchorcolor]     [s=1]
\definecolor[pagecolor]       [s=.1]
\definecolor[nonecolor]       [s=.5]
\definecolor[textcolor]       [s=.9]

% \setuppapersize[HD]
%
% \setuplayout
%   [page]

\setuppapersize
  [HD+]

\setuplayout
  [backspace=0pt,
   topspace=0pt,
   bottomspace=120pt, %1200-1080
   bottom=24pt,
   bottomdistance=5mm,
   header=0pt,
   footer=0pt,
   width=middle,
   height=middle]

\definelayer
  [page]

\setuplayer
  [page]
  [width=\textwidth,
   height=\textheight]

\setupbackgrounds
  [page]
  [background=color,
   backgroundcolor=pagecolor]

\setupbackgrounds
  [text][text]
  [bottomframe=on,
   framecolor=textcolor,
   rulethickness=0.025ex]

\setupmakeup
  [standard]
  [pagestate=start]

\setupinteraction
  [state=start,
   menu=on]

\defineinteractionmenu
  [ALPHABETS]
  [bottom]

\defineinteractionmenu
  [alphabets]
  [bottom]

\defineinteractionmenu
  [symbols]
  [bottom]

\setupinteractionmenu
  [bottom]
  [before=\vfill,
   after=\vfill,
   left=\hfill,
   right=\hfill,
   style=\tt\bf,
   distance=0pt,
   color=textcolor,
   contrastcolor=nonecolor]

\def\showmathcharacterssetrange#1#2#3%
  {\writestatus{range}{#1: \unihex{#2} - \unihex{#3}}%
   \ifcase#2\relax
     \definereference[#1][notpresent]%
   \else\ifcase#3\relax
     \definereference[#1][notpresent]%
   \else
     \normalexpanded{\definereference[#1][\unihex{#2}]}%
   \fi\fi}

\startinteractionmenu[bottom]
    \startgot [firstpage]       first    \stopgot \quad
    \startgot [deltapage(-100)] -100     \stopgot \quad
    \startgot [deltapage(-10)]  -10      \stopgot \quad
    \startgot [previouspage]    previous \stopgot \quad
    \startgot [nextpage]        next     \stopgot \quad
    \startgot [deltapage(+10)]  +10      \stopgot \quad
    \startgot [deltapage(+100)] +100     \stopgot \quad
    \startgot [lastpage]        last     \stopgot
\stopinteractionmenu

\startinteractionmenu[ALPHABETS]
    \startgot [U+00041] NORMAL            \stopgot \quad
    \startgot [U+1D400] BOLD              \stopgot \quad
    \startgot [U+1D434] ITALIC            \stopgot \quad
    \startgot [U+1D468] BOLDITALIC        \stopgot \quad
    \startgot [U+1D49C] SCRIPT            \stopgot \quad
    \startgot [U+1D4D0] BOLDSCRIPT        \stopgot \quad
    \startgot [U+1D504] FRAKTUR           \stopgot \quad
    \startgot [U+1D538] DOUBLESTRUCK      \stopgot \quad
    \startgot [U+1D56C] BOLDFRAKTUR       \stopgot \quad
    \startgot [U+1D5A0] SS NORMAL         \stopgot \quad
    \startgot [U+1D5D4] SS BOLD           \stopgot \quad
    \startgot [U+1D608] SS ITALIC         \stopgot \quad
    \startgot [U+1D63C] SS BOLDITALIC     \stopgot \quad
    \startgot [U+1D670] MONOSPACE         \stopgot \quad
    \startgot [U+00391] GRK NORMAL        \stopgot \quad
    \startgot [U+1D6A8] GRK BOLD          \stopgot \quad
    \startgot [U+1D6E2] GRK ITALIC        \stopgot \quad
    \startgot [U+1D71C] GRK BOLDITALIC    \stopgot \quad
    \startgot [U+1D756] GRK SS BOLD       \stopgot \quad
    \startgot [U+1D790] GRK SS BOLDITALIC \stopgot
\stopinteractionmenu

\startinteractionmenu[alphabets]
    \startgot [U+00061] normal            \stopgot \quad
    \startgot [U+1D41A] bold              \stopgot \quad
    \startgot [U+1D44E] italic            \stopgot \quad
    \startgot [U+1D482] bolditalic        \stopgot \quad
    \startgot [U+1D4B6] script            \stopgot \quad
    \startgot [U+1D4EA] boldscript        \stopgot \quad
    \startgot [U+1D51E] fraktur           \stopgot \quad
    \startgot [U+1D552] doublestruck      \stopgot \quad
    \startgot [U+1D586] boldfraktur       \stopgot \quad
    \startgot [U+1D5BA] ss normal         \stopgot \quad
    \startgot [U+1D5EE] ss bold           \stopgot \quad
    \startgot [U+1D622] ss italic         \stopgot \quad
    \startgot [U+1D656] ss bolditalic     \stopgot \quad
    \startgot [U+1D68A] monospace         \stopgot \quad
    \startgot [U+003B1] grk normal        \stopgot \quad
    \startgot [U+1D6C2] grk bold          \stopgot \quad
    \startgot [U+1D6FC] grk italic        \stopgot \quad
    \startgot [U+1D736] grk bolditalic    \stopgot \quad
    \startgot [U+1D770] grk ss bold       \stopgot \quad
    \startgot [U+1D7AA] grk ss bolditalic \stopgot
\stopinteractionmenu

% \startinteractionmenu[symbols]
%     \startgot [U+00030] dig normal       \stopgot \quad
%     \startgot [U+1D7CE] dig bold         \stopgot \quad
%     \startgot [U+1D7D8] dig doublestruck \stopgot \quad
%     \startgot [U+1D7E2] dig ss normal    \stopgot \quad
%     \startgot [U+1D7EC] dig ss bold      \stopgot \quad
%     \startgot [U+1D7F6] dig monospace    \stopgot \quad
%     \startgot [U+02200] operators        \stopgot \quad
%     \startgot [U+02701] symbols a        \stopgot \quad
%     \startgot [U+02901] symbols b        \stopgot \quad
%     \startgot [U+02A00] supplemental     \stopgot \quad
%     \startgot [U+027F0] arrows a         \stopgot \quad
%     \startgot [U+02900] arrows b         \stopgot \quad
%     \startgot [U+1F800] arrows c         \stopgot
% \stopinteractionmenu

\startinteractionmenu[symbols]
    \startgot [U+00030] dig normal       \stopgot \quad
    \startgot [U+1D7CE] dig bold         \stopgot \quad
    \startgot [U+1D7D8] dig doublestruck \stopgot \quad
    \startgot [U+1D7E2] dig ss normal    \stopgot \quad
    \startgot [U+1D7EC] dig ss bold      \stopgot \quad
    \startgot [U+1D7F6] dig monospace    \stopgot \quad
    \startgot [U+02200] operators        \stopgot \quad
    \startgot [miscellaneousmathematicalsymbolsa] symbols a    \stopgot \quad
    \startgot [miscellaneousmathematicalsymbolsb] symbols b    \stopgot \quad
    \startgot [supplementalmathematicaloperators] supplemental \stopgot \quad
    \startgot [supplementalarrowsa]               arrows a     \stopgot \quad
    \startgot [supplementalarrowsb]               arrows b     \stopgot \quad
    \startgot [supplementalarrowsc]               arrows c     \stopgot \quad
    \removeunwantedspaces
\stopinteractionmenu

\defineframed
  [somedata]
  [background=color,
   backgroundcolor=textcolor,
  %framecolor=charactercolor,
  %rulethickness=1pt,
   frame=off,
   offset=1ex]

% helpers

\unexpanded\def\showmathcharacterstxt#1%
  {{\tttf#1}}

\unexpanded\def\showmathcharacterschr#1#2%
  {\iffontchar\font#2\relax
     \scale
       [sx=#1,sy=#1]
       {\dontleavehmode\hbox\bgroup
        \setbox\scratchbox\hbox\bgroup
          \charactercolor
          \char#2\relax
        \egroup
        \scratchwidth \wd\scratchbox
        \scratchheight\ht\scratchbox
        \scratchdepth \dp\scratchbox
        \scratchitalic\ifdefined\glyphscale\glyphxscaled\fontcharic\font#2\relax\else\zeropoint\fi
        \setbox\scratchbox\hbox\bgroup
          \ifdim\scratchitalic=\zeropoint\else
            \hskip\scratchwidth
            \ifdim\scratchitalic<\zeropoint
              \hskip\scratchitalic
              \scratchitalic-\scratchitalic
            \fi
            \italiccolor
            \vrule
              width  \scratchitalic
              height \scratchheight
              depth  \scratchdepth
            \relax
            \hskip-\dimexpr\scratchwidth+\scratchitalic\relax
          \fi
          \unhbox\scratchbox
        \egroup
        \scratchtotal\dimexpr\scratchwidth+\scratchitalic\relax
        \wd\scratchbox\scratchtotal
        %
        \ifdim\scratchtotal>\zeropoint
          \backgroundline[backgroundcolor]{\box\scratchbox}%
        \else\ifdim\scratchtotal<\zeropoint
          % really negative width?
          \scratchtotal-\scratchtotal
          \setbox\scratchbox\hbox to \scratchtotal{\hss\charactercolor\char#2}%
          \backgroundline[backgroundcolorx]{\box\scratchbox}%
        \else
          \setbox\scratchbox\hbox to \emwidth{\hss\charactercolor\char#2}%
          \scratchtotal\wd\scratchbox
          \backgroundline[backgroundcolory]{\box\scratchbox}%
        \fi\fi
        \hskip-\scratchtotal
        \baselinecolor\vrule width \scratchtotal height .05\exheight depth .05\exheight
        %
        \ifdefined\glyphscale
          \scratchdimen\glyphyscaled\fontcharta\font#2\relax
          \ifdim\scratchdimen=\zeropoint\else
             \hskip-\scratchtotal
             \hbox to \scratchwidth yoffset \scratchheight \bgroup
               \hskip\scratchdimen
               \anchorcolor
               \vrule
                 width  .10\exheight
                 height .05\exheight
                 depth  .05\exheight
               \relax
               \hss
             \egroup
             \hskip\scratchitalic
          \fi
        \fi
        \egroup}%
   \fi}

\unexpanded\def\showmathcharactersmth#1#2%
  {\setbox\scratchbox\hbox{\showmathcharacterschr{#1}{#2}}%
   \ht\scratchbox\strutht
   \dp\scratchbox\strutdp
   \box\scratchbox}

\let\showmathcharactersbodyfonts\empty

\unexpanded\def\showmathcharactersbodyfontentry#1#2%
  {\somedata
     [align={none,middle},background=,height=5cm]
     {\begingroup
      \switchtobodyfont[#2,12pt]%
      \definedfont[MathRoman*math-text]%
      \showmathcharactersmth{10}{#1}%
      \endgroup
      \vfilll
      \doifelsemode{crosslink}
        {\goto{\strut\textcolor\showmathcharacterstxt{#2}}[#2::#1]}%
              {\strut\textcolor\showmathcharacterstxt{#2}}}%
   \hskip1ex}

\unexpanded\def\showmathcharacterssetbodyfonts#1%
  {\edef\showmathcharactersbodyfonts{#1}%
%    \def\doshowmathcharacterssetbodyfonts##1{\setupbodyfont[##1,12pt]}% \usebodyfont[##1,12pt]%
   \def\doshowmathcharacterssetbodyfonts##1{\usebodyfont[##1,12pt]}%
   \processcommacommand[\showmathcharactersbodyfonts]\doshowmathcharacterssetbodyfonts}

\unexpanded\def\showmathcharactersbodyfontschars#1%
  {\processcommacommand[\showmathcharactersbodyfonts]{\showmathcharactersbodyfontentry{#1}}}

% main

\unexpanded\def\showmathcharactersstart
  {\starttext
   \startstandardmakeup % we use baselinecolor so that we have a transparency on page 1
     \setupalign[middle]
     \vfil
%      \dontleavehmode \scale[height=.3\textheight]{\strut\color[textcolor]{\fontclass}}
     \dontleavehmode \scale[width=.75\textwidth]{\strut\color[textcolor]{\fontclass}}
     \vfil
     \dontleavehmode \scale[height=.1\textheight]{\strut\color[baselinecolor]{\currentdate}}
     \vfil
     \vfil
   \stopstandardmakeup}

\unexpanded\def\showmathcharactersstop
  {\stoptext}

% entry

\unexpanded\def\showmathcharactersstartentry
  {\startstandardmakeup}

\unexpanded\def\showmathcharactersstopentry
  {\tightlayer[page]
   \stopstandardmakeup}

\unexpanded\def\showmathcharactersreference#1%
  {\setlayer[page]{\pagereference[#1]}}

\unexpanded\def\showmathcharactersentryhexdectit#1#2#3%
  {\setlayer
     [page]
     [preset=middletop,voffset=5mm]
     {\somedata[height=1cm]{\showmathcharacterstxt{#1}}}
   \setlayer
     [page]
     [preset=middle,y=2cm]
     {\showmathcharactersmth{25}{#2}}
   \setlayer
     [page]
     [preset=righttop,offset=5mm]
     {\somedata[height=1cm]{\showmathcharacterstxt{#3}}}
   \doifsomething\showmathcharactersbodyfonts
     {\setlayer
        [page]
        [preset=middlebottom,voffset=5mm]
        {\showmathcharactersbodyfontschars{#2}}}}

% dimensions (we can ask them in tex)

\ifcase\contextlmtxmode

    \unexpanded\def\showmathcharactersentrywdhtdpicta#1#2#3#4#5%
      {\setlayer
         [page]
         [preset=leftbottom,offset=5mm]
         {\somedata[align=normal,width=5cm]
            {\strut width \hfill \the\dimexpr#1\scaledpoint\par
             \strut height\hfill \the\dimexpr#2\scaledpoint\par
             \strut depth \hfill \the\dimexpr#3\scaledpoint\par
             \ifnum#4=\zerocount\else
             \strut italic\hfill \the\dimexpr#4\scaledpoint\par
             \fi
             \ifnum#5=\zerocount\else
             \strut accent\hfill \the\dimexpr#5\scaledpoint
             \fi
            }}}

\else

    \unexpanded\def\showmathcharactersentrywdhtdpicta#1%
      {\setlayer
         [page]
         [preset=leftbottom,offset=5mm]
         {\somedata[align=normal,width=5cm]
            {\scratchwidth \glyphxscaled\fontcharwd\font#1%
             \scratchheight\glyphxscaled\fontcharht\font#1%
             \scratchdepth \glyphxscaled\fontchardp\font#1%
             \scratchitalic\glyphxscaled\fontcharic\font#1%
             \scratchdimen \glyphxscaled\fontcharta\font#1%
             \strut width \hfill \the\scratchwidth \par
             \strut height\hfill \the\scratchheight\par
             \strut depth \hfill \the\scratchdepth \par
             \ifnum\scratchitalic=\zerocount\else
             \strut italic\hfill \the\scratchitalic\par
             \fi
             \ifnum\scratchdimen=\zerocount\else
             \strut accent\hfill \the\scratchdimen
             \fi
            }}}

\fi

\unexpanded\def\showmathcharactersentryresource#1%
  {} % {virtual: #1\par}

% next

\unexpanded\def\showmathcharactersstartnext
  {\setlayer
     [page]
     [preset=middleleft,hoffset=5mm]
     \bgroup\vbox\bgroup}

\unexpanded\def\showmathcharactersstopnext
  {\egroup\egroup}

\unexpanded\def\showmathcharactersnextentry#1#2#3%
  {\ifnum#1>1 \vskip\exheight \fi
   \dontleavehmode\somedata
     [align=normal,width=4cm]
     {\strut\showmathcharacterstxt{#2}\hfill\showmathcharacterschr{2}{#3}}\par}

\unexpanded\def\showmathcharactersnextcycle#1%
  {\ifnum#1>1 \vskip\exheight \fi
   \dontleavehmode\somedata
     [align=normal,width=4cm]
     {\strut\showmathcharacterstxt{cycle}}\par}

% variants

\unexpanded\def\showmathcharactersstartvvariants
  {\setlayer
     [page]
     [preset=lefttop,offset=5mm]
     \bgroup\vbox\bgroup}

\unexpanded\def\showmathcharactersstarthvariants
  {\setlayer
     [page]
     [preset=lefttop,offset=5mm]
     \bgroup\hbox\bgroup}

\unexpanded\def\showmathcharactersvvariantsentry#1#2#3%
  {\ifnum#1>1 \vskip\exheight \fi
   \dontleavehmode\somedata
     [align=middle,width=4cm]
     {\strut\showmathcharacterstxt{#2}\hfilll\showmathcharacterschr{2}{#3}}}

\unexpanded\def\showmathcharactershvariantsentry#1#2#3%
  {\ifnum#1>1 \hskip\exheight \else \dontleavehmode \fi
   \somedata
     [align={none,middle},height=2cm]
     {\strut\showmathcharacterstxt{#2}\vfilll\showmathcharacterschr{2}{#3}}}

\unexpanded\def\showmathcharactersstopvvariants
  {\egroup\egroup}

\unexpanded\def\showmathcharactersstophvariants
  {\egroup\egroup}

\unexpanded\def\showmathcharactersbetweennextandvariants
  {}

% classes

\unexpanded\def\showmathcharactersstartentryclassspec
  {\setlayer
     [page]
     [preset=rightbottom,offset=5mm]
     \bgroup\somedata[align=normal,width=8cm]\bgroup}

\unexpanded\def\showmathcharactersstopentryclassspec
  {\egroup\egroup}

\unexpanded\def\showmathcharactersentryclassname#1#2%
  {\strut{\showmathcharacterstxt#1}\hfill\showmathcharacterstxt{#2}\par}

% symbols

\unexpanded\def\showmathcharactersentrysymbol#1#2%
  {\setlayer
     [page]
     [preset=leftbottom,hoffset=5mm,voffset=50mm]
     {\somedata
        [align=normal,width=5cm]
        {\showmathcharacterstxt{#1}\hfill\showmathcharacterschr{4}{#2}}}}

% alternates

\unexpanded\def\showmathcharactersstartlookupvariants
  {\setlayer
     [page]
     [preset=middleright,hoffset=5mm]
     \bgroup\vbox\bgroup}

\unexpanded\def\showmathcharactersstoplookupvariants
  {\egroup\egroup}

\unexpanded\def\showmathcharacterslookupvariant#1#2#3#4%
  {\ifnum#1>1 \vskip\exheight \fi
   \somedata
     [align=normal,width=7cm]
     {\showmathcharacterstxt{#4:} \showmathcharacterstxt{#2}\hfill\showmathcharacterschr{4}{#3}}}

% main

% this is a one-run style so we can forget about an alternative
% just assume that the previous definitions are global

\unprotect

\unexpanded\def\showmathfontrepertoire
  {\dosingleempty\module_math_repertoire_show}

\def\module_math_repertoire_show[#1]%
  {\showmathfontcharacters[alternative=,option=,check=yes,#1]
   \showmathfontcharacters[alternative=,option=,#1]}

\protect

\stopmodule

\continueifinputfile{s-math-repertoire.mkiv}

% \enabledirectives[math.nogoodies]

% \showmathcharacterssetbodyfonts{lucidaot,cambria,xits,stixtwo,modern,pagella,termes,bonum,schola,dejavu}
\showmathcharacterssetbodyfonts{lucida,cambria,stixtwo,modern,pagella,termes,bonum,schola,ebgaramond,dejavu}% ,modernlatin}
% \showmathcharacterssetbodyfonts{newcomputermodern-book,lucidaot,cambria,stixtwo,modern,pagella,termes,bonum,schola,dejavu}
% \showmathcharacterssetbodyfonts{newcomputermodern-book,stixtwo,modern,pagella,termes,bonum,schola,dejavu}
% \showmathcharacterssetbodyfonts{newcomputermodern-book,lucidaot,cambria,stixtwo,modern,pagella,termes,schola,dejavu}
% \showmathcharacterssetbodyfonts{modernlatin,lucidaot,cambria,stixtwo,modern,pagella,termes,schola,dejavu}

\starttext

    \doifelse {\getdocumentargument{bodyfont}} {} {

      % \setupbodyfont[cambria,                12pt]
      % \setupbodyfont[modern,                 12pt]
      % \setupbodyfont[lmvirtual,              12pt]
      % \setupbodyfont[pxvirtual,              12pt]
      % \setupbodyfont[txvirtual,              12pt]
      % \setupbodyfont[palatino,               10pt]
      % \setupbodyfont[mathtimes,              12pt]
      % \setupbodyfont[stix,                   12pt]
      % \setupbodyfont[xits,                   12pt]
      % \setupbodyfont[lucida,                 12pt]
      % \setupbodyfont[lucidaot,               12pt]
      % \setupbodyfont[pagella,                12pt]
      % \setupbodyfont[bonum,                  12pt]
      % \setupbodyfont[schola,                 12pt]
      % \setupbodyfont[dejavu,                 12pt]
        \setupbodyfont[lucida,                 12pt]
      % \setupbodyfont[newcomputermodern-book, 12pt]

    } {

        \normalexpanded{\setupbodyfont[\getdocumentargument{bodyfont},12pt]}

    }

    \showmathfontrepertoire

\stoptext

