%---------------------------------------------------------------------------
% Time-stamp: <2024-04-06 17:54:16 sutner> 
%
% :File:	ks-texmacs.sty
% :Purpose:	basic macros for discrete math
%
%        
%---------------------------------------------------------------------------

%---------------------------------------------------------------------------
% identification

\def\fileversion{0.3}
\def\filedate{2021/01/23}
\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{ks-texmacs}%
[\filedate\space  v\fileversion]


%---------------------------------------------------------------------------
% options declarations


%---------------------------------------------------------------------------
% options execution


%---------------------------------------------------------------------------
% package loading

\RequirePackage{amsfonts}
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage{mathtools}
\RequirePackage{ifthen}
\RequirePackage{latexsym}
\RequirePackage{stmaryrd}
\RequirePackage{lmodern}
\RequirePackage{xspace}
\RequirePackage{etoolbox}
\RequirePackage{isomath}

% \RequirePackage{datetime}

%---------------------------------------------------------------------------
% main code

%---------------------------------------------------------------------------
% experimental
%---------------------------------------------------------------------------

% this blows up when moved to language section WTF???
\newcommand{\trans}{\@ifstar{\tr@nslong}{\tr@ns}}
\newcommand{\tr@ns}[3]{{#1}\stackrel{{#2}}{\rightarrow}{#3}}
\newcommand{\tr@nslong}[3]{{#1}\stackrel{{#2}}{\longrightarrow}{#3}}


% \def\trademark{\mathrm{TM}}


%---------------------------------------------------------------------------
% stuff
%---------------------------------------------------------------------------

\def\shortrep{\gdef\thesection{\arabic{section}}}    

\def\nowt{\leavevmode\hbox{}}

\providecommand{\dotbox}[1]{\makebox[{#1}][s]{\dotfill}}

\def\singlespacing%
{\let\CS=\@currsize\def\baselinestretch{1}\small\CS}
\def\singlespacingplus%
{\let\CS=\@currsize\def\baselinestretch{1.25}\small\CS}
\def\singlespacingplusplus%
{\let\CS=\@currsize\def\baselinestretch{1.35}\small\CS}
\def\doublespacing%
{\let\CS=\@currsize\def\baselinestretch{1.75}\small\CS}

%---------------------------------------------------------------------------

% \makeatletter
\DeclareRobustCommand\onedot{\futurelet\@let@token\@onedot}
\def\@onedot{\ifx\@let@token.\else.\null\fi\xspace}

\def\re{{r.e}\onedot}  
\def\eg{{e.g}\onedot}  \def\Eg{{E.g}\onedot}
\def\ie{{i.e}\onedot}  \def\Ie{{I.e}\onedot}
%\def\cf{{c.f}\onedot}  
\def\etc{{etc}\onedot}  
%\def\vs{{vs}\onedot}
\def\wrt{w.r.t\onedot} 
\def\etal{{et al}\onedot}
% \makeatother

%---------------------------------------------------------------------------
% print file name instead of date
% dreadful hack
%
% datetime does not work with beamer
% \renewcommand{\dateseparator}{/}
% \yyyymmdddate

\newcommand{\datefile}[1]{%
\ifthenelse{\equal{#1}{}}{\date{\huge{\color{red}\texttt{\jobname\ \ \ %
\number\year/\number\month/\number\day\ \currenttime}}}}{\date{#1}}}


% tag line
% \def\tagline#1{\vspace*{-30mm}\rightline{{\tt #1.tex: \today}} \vspace{20mm}}

% \ivstrut{#1}{#2}
% \ihstrut{#1}
% An invisible vertical/horizontal strut.
% \ivstrut: #1 = height above baseline, #2 = depth below baseline. 
% \ihstrut: #1 = length of strut
% all measures in points. 

\def\ivstrut#1#2{\ifvmode\hrule\else\vrule\fi height #1pt depth #2pt width 0pt}
\def\ihstrut#1{\ifvmode\hrule\else\vrule\fi height 0pt depth 0pt width #1pt}


%---------------------------------------------------------------------------
% boxes and rules
%---------------------------------------------------------------------------


\def\aLine{\bigskip\hrule\bigskip}
\def\bLine{\smallskip\hrule\smallskip}
\def\fatLine{\bigskip\hrule height2pt \bigskip}


%---------------------------------------------------------------------------
%  Math
%---------------------------------------------------------------------------
%
%  miscellaneous
%

\font\ninerm=cmr9
\def\Cee{{\ninerm\textsc{C}}\xspace}
\def\Cpp{{\ninerm\textsc{C}\raisebox{.15ex}{\kern-.05em{+ \kern -.45em+}}}\xspace}
\def\Fpp{{\ninerm\textsc{F}\raisebox{.15ex}{\kern-.05em{+ \kern -.45em+}}}\xspace}
\def\UNIX{{\ninerm\textsc{UNIX}\xspace}}

\def\sbull{\mathrel{\raisebox{1pt}{{$\scriptstyle\bullet$}}}}

\def\eps{\varepsilon}
\def\BL{\Bigl(\,}
\def\BR{\,\Bigr)}
\def\O{\mathit{O}}                % big O
\def\sO{\widetilde{\mathit{O}}}   % soft O
\def\lO{\mathit{o}}               % little o


%---------------------------------------------------------------------------
% cal, roman, bold, operators in math mode 

\def\Mathcal#1{\expandafter\def\csname c#1\endcsname{\mathcal{#1}}}
\def\Mathfrak#1{\expandafter\def\csname f#1\endcsname{\mathfrak{#1}}}
\def\Mathbold#1{\expandafter\def\csname b#1\endcsname{\mathbf{#1}}}
\def\MathBold#1{\expandafter\def\csname #1\endcsname{\mathbf{#1}}}
\def\Mathbb#1{\expandafter\def\csname #1\endcsname{\mathbb{#1}}}
\def\Mathvec#1{\expandafter\def\csname v#1\endcsname{\vec{#1}}}

% \DeclareMathOperator  uses roman? 
\def\Mathop#1{\expandafter\def\csname#1\endcsname{\mathop{\mathsf{#1}}}}
\def\Mathrm#1{\expandafter\def\csname#1\endcsname{{\mathrm{#1}}}}
\def\Mathsf#1{\expandafter\def\csname#1\endcsname{{\mathsf{#1}}}}
\def\Mathsc#1{\expandafter\def\csname#1\endcsname{{\textsc{#1}}\xspace}}


\Mathcal{A}
\Mathcal{B}
\Mathcal{C}
\Mathcal{H}
\Mathcal{S}
\Mathcal{T}

\def\L{\mathcal{L}}             % change ?

\Mathfrak{P}

\MathBold{0}
\MathBold{1}
\MathBold{2}

\Mathbb{N}
\Mathbb{B}
\Mathbb{R}
\Mathbb{Q}
\Mathbb{C}
\Mathbb{Z}
\Mathbb{S}
\Mathbb{F}
\Mathbb{K}


\Mathop{dom}
\Mathop{cod}
\Mathop{grf}
\Mathop{spt}
\Mathop{rng}
\Mathop{img}
\Mathop{rnk}
\Mathop{ker}

\Mathsf{prep}
\Mathsf{app}
\Mathsf{join}
\Mathsf{rev}
\Mathsf{nil}


%---------------------------------------------------------------------------
%  complexity classes
%---------------------------------------------------------------------------  

\Mathbb{P}
\Mathbb{NP}
\Mathsc{PH}
\Mathsc{NC}
\Mathsc{AC}
\Mathsc{NL}
\Mathsc{EXP}
\Mathsc{NEXP}
\Mathsc{PSPACE}
\Mathsc{NPSPACE}
% \def\DLOG{\textsc{L}\xspace}
% \def\NLOG{\textsc{NL}\xspace}
\def\DLOG{\mathbb{L}\xspace}
\def\NLOG{\mathbb{NL}\xspace}

\Mathsc{SAT}

\Mathrm{TIME}
\Mathrm{NTIME}
\Mathrm{SPACE}
\Mathrm{NSPACE}

\def\NoP{\#\P}
\def\coNP{\text{co-}\NP}

\Mathsf{VC}
\Mathsf{SAT}
\Mathsf{Taut}
\Mathsf{Clique}
\Mathsf{IS}


%---------------------------------------------------------------------------
% sets, tuples, ... 
%---------------------------------------------------------------------------

\Mathsf{true}
\Mathsf{false}

% paired delimiters

\DeclarePairedDelimiter\setof{\{}{\}}
% \def\setof#1{\left\{ {#1} \right\}}
% \def\setfix#1#2{\{\, {#1} \mid {#2}\,\}}
% \def\setoffix#1{\{ {#1} \}}

\DeclarePairedDelimiter\card{|}{|}
\DeclarePairedDelimiter\norm{\|}{\|}
% \def\card#1{\left|{#1}\right|} 
% \def\norm#1{\left\|{#1}\right\|} 


\DeclarePairedDelimiter\Norm{\llbracket}{\rrbracket}
% only catches first bracket
% \DeclarePairedDelimiter\Norm{[\mkern-2mu[}{]\mkern-2mu]}
% should have * option
% \def\Norm#1{[\mkern-2mu[{#1}]\mkern-2mu]}
% \def\Norm{\@ifstar{\n@orms}{\n@orm}}
% \def\n@orms#1{\left[\mkern-5mu\left[{#1}\right]\mkern-5mu\right]}
% \def\n@orm#1{[\mkern-3mu[{#1}]\mkern-3mu]}



\DeclarePairedDelimiter\ceiling{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
% \def\floor#1{\lfloor{#1}\rfloor} 
% \def\ceiling#1{\lceil{#1}\rceil} 


% set comprehension style

\def\Set#1#2{\left\{\, {#1} \,\middle|\, {#2}\,\right\}}
\def\set#1#2{\{\, {#1} \mid {#2}\,\}}
\def\nset{\@ifstar\nset@zero\nset@pln}
\def\nset@pln#1{[\,{#1}\,]}
\def\nset@zero#1{\underline{#1}}



\def\mmin#1#2{\min \bigl(\, {#1} \mid {#2} \,\bigr) }
\def\mmax#1#2{\max \bigl(\, {#1} \mid {#2} \,\bigr) }

% probability 

\def\Prob#1{\ifx#1.\mathsf{Pr}\else\mathsf{Pr}[\,{#1}\,]\fi}
\def\Probc#1#2{\mathsf{Pr}[\,{#1}\mid{#2}\,]}
\def\Probs#1#2{\mathsf{Pr}_{#1}[\,{#2}\,]}
% cool clash
\def\Exp#1{\mathsf{E}[{#1}]}
\def\Var#1{\mathsf{Var}[{#1}]}


% \def\chf#1{\chi_{\ivstrut{8}{0}{#1}}}


% tuples, lists

% adjust firstindex to 0 or 1 as appropriate
\def\first@index{1}
\providecommand{\firstindex}[1]{\def\first@index{#1}}
\providecommand{\Tuple}[2][n]{{#2}_{\first@index},\ldots,{#2}_{#1}\futurelet\next\mathcorr}

% use of \futurelet:
% 
% next := next token
% put next
% expand \mathcorr
% 
\def\mathcorr{\ifx\next.\mkern -.3mu\else\ifx\next,\mkern -.3mu\else\,\fi\fi}
\def\tuple#1#2#3{#1_{#2},\ldots,#1_{#3}\mkern-.1mu\futurelet\next\mathcorr}
\def\range#1#2#3{#1 = #2,\ldots,#3\mkern -.05mu\futurelet\next\mathcorr}

\def\func#1#2#3{{#1}:{#2}\to{#3}\futurelet\next\mathcorr}
\def\pfunc#1#2#3{{#1}:{#2}\nrightarrow{#3}\futurelet\next\mathcorr}
\def\bfunc#1#2#3{{#1}:{#2}\longleftrightarrow{#3}\futurelet\next\mathcorr}
\def\lfunc#1#2#3{{#1}:{#2}\longrightarrow{#3}\futurelet\next\mathcorr}

\def\pair#1#2{ \langle #1,#2 \rangle\futurelet\next\mathcorr}
\def\triple#1#2#3{ \langle #1,#2,#3 \rangle\futurelet\next\mathcorr}
%  \def\struct#1{ \left\langle \, {#1} \,\right\rangle\futurelet\next\mathcorr}
\DeclarePairedDelimiter\struct{\langle}{\rangle}

%---------------------------------------------------------------------------
%  decision problems
%---------------------------------------------------------------------------  

\newcounter{labelno}

\def\problem[#1]#2#3#4{%
\def\problemlabel##1{%
\ifcase##1 \or{Problem:\hfil}\or{Instance:\hfil}\or%%
\ifx#1d{Question:\hfil}\else{Solution:\hfil}\fi\fi}
\begin{list}
  {\problemlabel\thelabelno}{\usecounter{labelno}
  \rightmargin 0mm \leftmargin 18mm \labelsep 0mm \labelwidth 20mm 
  \topsep 3mm \itemsep 0mm \listparindent 0mm}
    \item {\textbf{#2}}
    \item {#3}
    \item {#4}
\end{list}
}

%---------------------------------------------------------------------------
%  text proofs  
%---------------------------------------------------------------------------

\def\proof{\textsl{Proof.}\/\quad}
\def\proofsketch{\textsl{Sketch of proof.}\/\quad}

%%\def\qed{$\Box$ \par \vspace{2ex}}
\def\qed{{\unskip\nobreak\hfil\penalty50
\hskip1em\hbox{}\nobreak\hfill{\lower .5pt \hbox{$\Box$}} 
\parfillskip=0pt \finalhyphendemerits=0 \par} 
\vspace{2ex}}


%---------------------------------------------------------------------------
% experimental
%---------------------------------------------------------------------------

\def\pow{\@ifstar\powfrak\powpow}
\def\powpow{\mathsf{pow}}
\def\powfrak{\mathfrak{P}}


\def\Range{\@ifnextchar*{\r@ange}{\r@@ange}}
\def\r@ange*{\r@angezero}
\def\r@angezero#1{({#1})}
\def\r@@ange#1{[{#1}]}

\providecommand{\fullfunction}[5]{\ensuremath{
   \begin {array}{crcl}
       {#1} \;\colon  & {#2} & \longrightarrow & {#3} \\
                      & {#4} & \longmapsto     & {#5}
   \end{array}
}}


% ISO for vectors
\renewcommand{\vec}{\vectorsym}

%---------------------------------------------------------------------------
% computability

\def\qY{q_{\mathrm{Y}}} 
\def\qN{q_{\mathrm{N}}}

\def\Sign{\mathsf{sign}}
\def\Signbar{\overline{\mathsf{sign}}}
\def\Char{\@ifstar\char@up\char@down}
\def\char@up#1{\mathsf{char}({#1})}
\def\char@down#1{\mathsf{char}_{#1}}
\def\sChar{\@ifstar\schar@up\schar@down}
\def\schar@up#1{\mathsf{schar}({#1})}
\def\schar@down#1{\mathsf{schar}_{#1}}
\def\Charbar#1{\overline{\mathsf{char}}_{#1}}


%  see book-macs.tex
\makeatletter
\DeclareRobustCommand\onedot{\futurelet\@let@token\@onedot}
\def\@onedot{\ifx\@let@token.\else.\null\fi\xspace}

\def\re{{r.e}\onedot}
\def\ce{{c.e}\onedot}
\def\core{{co-r.e}\onedot}
\def\pr{{p.r}\onedot}
\makeatother

% \def\re{\relax\ifmmode \mathrm{r.e.} \else r\@.e\@.\xspace\fi}
% \def\core{\relax\ifmmode \mathrm{co-r.e.} \else co-r\@.e\@.\xspace\fi}
% \def\ce{c\@.e\@.\xspace}
% \def\pr{p\@.r\@.\xspace}



% reducibilities
\def\redm{\leq_{m}}
\def\equivm{\equiv_{m}}
\def\redo{\leq_{1}}
\def\equivo{\equiv_{1}}
\def\redT{\leq_{T}}
\def\redTs{<_{T}}
\def\redlm{\leq_{l}}
\def\equivT{\equiv_{T}}
\def\redpm{\leq_{m}^{p}}
\def\equivpm{\equiv_{m}^{p}}
\def\redpT{\leq_{T}^{p}}
\def\equivpT{\equiv_{T}^{p}}


% classes

\def\timec#1#2{T_{#1}\!\left({#2}\right)}
\def\timecavg#1#2{T_{#1}^{\mathrm{avg}}\left({#2}\right)}
\def\spacec#1#2{S_{#1}\!\left({#2}\right)}
\def\spacecavg#1#2{S_{#1}^{\mathrm{avg}}\left({#2}\right)}


\Mathsf{TOT}
\Mathsf{REC}

\def\kolmo#1{K({#1})}
\def\kolmor#1#2{K({#1}\,|\,{#2})}
\def\kolmop#1{C({#1})}
\def\kolmopr#1#2{C({#1}\,|\,{#2})}


%---------------------------------------------------------------------------
% relations 

\def\rrho{\mathrel{\rho}}
\def\rsigma{\mathrel{\sigma}}
\def\rtau{\mathrel{\tau}}
\def\rpi{\mathrel{\pi}}

\def\TRC{\mathsf{TRC}}
\def\TC{\mathsf{TC}}
\def\RC{\mathsf{RC}}


% rewrite
\def\Red{\rightarrow}
\def\Reds{\stackrel{*}\rightarrow}
\def\Redp{\stackrel{+}\rightarrow}
\def\equ{\leftrightarrow}
\def\equs{\stackrel{*}\leftrightarrow}
\def\equp{\stackrel{+}\leftrightarrow}

\def\Rels{\mathsf{Rel}}

%---------------------------------------------------------------------------
% number theory

\def\divs{\mathrel{|}}
\def\div{\mathrel{\mathrm{div}}}
\def\rem{\mathrel{\mathrm{rem}}}

% \def\div{\mskip-\medmuskip\mkern5mu\mathbin{\rm div}%%
% \penalty900 \mkern5mu\mskip-\medmuskip}

\def\ZZ#1{\Z_{#1}}
\def\ZZS#1{\Star{\Z}_{#1}}

\def\Jacobi#1#2{\left(\frac{#1}{#2}\right)}
\def\Legendre#1#2{\mathsf{LS}\left({#1},{#2}\right)}

\Mathsf{GF}

%---------------------------------------------------------------------------
% algebra

% groups
\providecommand{\Cayley}[2][r]{\Gamma_{#1}({#2})}
% \newcommand{\Action}[3][r]{\ifx#1r{{#2}\,{#3}}\else{{#3}\,{#2}}\fi} 

\providecommand{\Actiond}[2]{{#1}\cdot{#2}}
\providecommand{\Action}[2]{{#1}\,{#2}}


% % incidence algebra 

% \providecommand{\interval}[2]{[\,{#1},{#2}\,]}
% \providecommand{\Intervals}[1]{\mathsf{int}({#1})}

% % ranking

% \Mathsf{urk}
% \Mathsf{Inj}

%---------------------------------------------------------------------------
% falling factorial

\providecommand{\ffac}[2]{{#1}^{\underline{#2}}}


%---------------------------------------------------------------------------
%  language theory macros
%---------------------------------------------------------------------------

% \let\pref=\sqsubseteq
% \let\suff=\sqsupseteq


\providecommand{\Star}[1]{{#1}^{\star}}
\providecommand{\Plus}[1]{{#1}^{+}}
\providecommand{\Starr}[2]{{#1}_{#2}^{\star}}
% cool clash
\providecommand{\Infinity}[1]{{#1}^{\infty}}
\providecommand{\ToOmega}[1]{{#1}^{\omega}}
\providecommand{\ToZeta}[1]{{#1}^{\Z}}


% this requires stmaryrd
\providecommand{\lquotient}[2]{{#1}^{-1} \, {#2}}
\providecommand{\behavior}[1]{\llbracket{#1}\rrbracket}
\providecommand{\behaviorA}[2][\cA]{\llbracket{#2}\rrbracket_{#1}}
\providecommand{\cobehavior}[1]{\llbracket{#1}\rrbracket^{\mathsf{co}}}
\providecommand{\cobehaviorA}[2][\cA]{\llbracket{#2}\rrbracket^{\mathsf{co}}_{#1}}
% \providecommand{\behavior}[1]{[\kern-2pt[{#1}]\kern-2.pt]}
% \providecommand{\behaviorA}[2][\cA]{[\kern-2pt[{#2}]\kern-2.pt]_{#1}}

\providecommand{\growth}[2][L]{\gamma_{#1}({#2})}


\def\LS{\L(\Sigma)}
\def\SS{\Star{\Sigma}}
\def\SP{\Plus{\Sigma}}
\def\Se{\Sigma \cup \setof{\eps}}
\def\SI{\Infinity{\Sigma}}
\def\SSS{\Sigma^\infty}

\def\Reg{\mathrm{Reg}}
\def\Rat{\mathrm{Rat}}

\endinput
%---------------------------------------------------------------------------
% eof

