% -*- coding: utf-8 -*-
% ----------------------------------------------------------------------------
% Author:  Jianrui Lyu <tolvjr@163.com>
% License: The LaTeX Project Public License 1.3c
% ----------------------------------------------------------------------------

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{typstfun}[2024-02-20 v2024A Print equivalent Typst function names]

\RequirePackage{functional}
\IgnoreSpacesOn

\propConstFromKeyval\c@typstfun@text@env@prop{
   description = terms
  ,enumerate = enum
  ,figure = figure
  ,itemize = list
  ,minipage = block
  ,table = figure
  ,tabular = table
  ,tabularx = {table,grid}
  ,thebibliography = bibliography
  ,verbatim = raw
}

\propConstFromKeyval\c@typstfun@text@cmd@prop{
   chapter = heading
  ,cite = cite
  ,documentclass = import
  ,emph = emph
  ,fbox = rect
 %,foreach = for
  ,href = link
  ,hspace = h
  ,include = include
  ,includegraphics = image
  ,label = label
  ,lowercase = lower
  ,medspace = medium
  ,newcommand = let
  ,newcounter = let
  ,newenvironment = let
  ,newlength = let
  ,pagebreak = pagebreak
  ,parbox = block
  ,part = heading
  ,qquad = wide
  ,quad = quad
  ,ref = ref
  ,renewcommand = let
  ,renewenvironment = let
  ,section = heading
  ,setcounter = let
  ,setlength = let
  ,subsection = heading
  ,subsubsection = heading
  ,textbf = strong
  ,textit = text
  ,textmd = text
  ,textrm = text
  ,textsc = text
  ,textsf = text
  ,textsl = text
  ,texttt = text
  ,thickspace = thick
  ,thinspace = thin
  ,underline = underline
  ,uppercase = upper
  ,url = link
  ,usepackage = import
  ,verb = raw
  ,vspace = v
}

\propConstFromKeyval\c@typstfun@math@env@prop{
   Bmatirx = mat
  ,Vmatirx = mat
  ,align = equation
  ,array = mat
  ,bmatirx = mat
  ,cases = cases
  ,displaymath = equation
  ,equation = equation
  ,math = math
  ,matrix = mat
  ,pmatirx = mat
  ,vmatirx = mat
}

\propConstFromKeyval\c@typstfun@math@cmd@prop{
   arccos = arccos
  ,arcsin = arcsin
  ,arctan = arctan
  ,arg = arg
  ,bar = macron
  ,binom = binom
  ,boldsymbol = bold
  ,cos = cos
  ,cosh = cosh
  ,cot = cot
  ,coth = coth
  ,csc = csc
  ,dbinom = binom
  ,ddot = {diaer,dot.double}
  ,deg = deg
  ,det = det
  ,dfrac = frac
  ,dim = dim
  ,dot = dot
  ,exp = exp
  ,frac = frac
  ,gcd = gcd
  ,hat = hat
  ,hspace = h
  ,inf = inf
  ,ker = ker
  ,left = lr
  ,lg = lg
  ,lim = lim
  ,liminf = liminf
  ,limsup = limsup
  ,ln = ln
  ,log = log
  ,mathbb = bb
  ,mathcal = cal
  ,max = max
  ,min = min
  ,mod = mod
  ,overbrace = overbrace
  ,overline = overline
  ,qquad = wide
  ,quad = quad
  ,right = lr
  ,sec = sec
  ,sin = sin
  ,sinh = sinh
  ,sqrt = {sqrt,root}
  ,sup = sup
  ,tan = tan
  ,tanh = tanh
  ,tbinom = binom
  ,tfrac = frac
  ,tilde = tilde
  ,underbrace = underbrace
  ,vec = arrow
  ,widehat = hat
}

\propConstFromKeyval\c@typstfun@math@sym@prop{
   Cap = sect.double
  ,Cup = union.double
  ,Delta = Delta
  ,Gamma = Gamma
  ,Join = join
  ,Lambda = Lambda
  ,Longrightarrow = arrow.double.not
  ,Omega = Omega
  ,Phi = Phi
  ,Pi = Pi
  ,Psi = Psi
  ,Rightarrow = arrow.double
  ,Sigma = Sigma
  ,Theta = Theta
  ,aleph = alef
  ,alpha = alpha
 %,amalg = product.co
  ,angle = angle
  ,approx = approx
  ,approxeq = approx.eq
  ,ast = ast
  ,beta = beta
  ,bigcap = sect.big
  ,bigcirc = circle.big
  ,bigcup = union.big
  ,bigodot = dot.circle.big
  ,bigoplus = plus.circle.big
  ,bigotimes = times.circle.big
  ,bigsqcup = union.sq.big
  ,bigtriangledown = triangle.b
  ,bigtriangleup = triangle.t
  ,biguplus = union.plus.big
  ,bigvee = or.big
  ,bigwedge = and.big
 %,bowtie = join
  ,bullet = bullet
  ,cap = sect
  ,cdot = {dot.c,dot.op}
  ,cdots = dots.c
  ,checkmark = checkmark
  ,chi = chi
  ,circ = {circle.small,compose}
  ,colon = colon
  ,cong = tilde.equiv
  ,coprod = product.co
  ,cup = union
  ,curlyvee = or.curly
  ,curlywedge = and.curly
  ,dagger = dagger
  ,dashv = tack.l
  ,ddagger = dagger.double
  ,delta = delta
  ,ddots = dots.down
  ,diamond = diamond
  ,div = div
  ,divideontimes = times.div
  ,dotplus = plus.dot
  ,downarrow = arrow.b
  ,ell = ell
  ,emptyset = nothing
  ,epsilon = epsilon.alt
  ,equiv = equiv
  ,eta = eta
  ,exists = exists
  ,forall = forall
 %,frown = paren.t
  ,gamma = gamma
  ,ge = gt.eq
  ,geq = gt.eq
  ,geqslant = gt.eq.slant
  ,gg = gt.double
  ,hbar = planck.reduce
  ,imath = dotless.i
  ,iiiint = intgral.quad
  ,iiint = integral.triple
  ,iint = integral.double
  ,in = in
  ,int = integral
  ,intercal = {top,tack.b}
  ,iota = iota
  ,jmath = dotless.j
  ,kappa = kappa
  ,lambda = lambda
  ,langle = angle.l
  ,lbrace = {brace,brace.l}
  ,lbrack = {bracket,bracket.l}
  ,ldots = {dots,dots.l}
  ,le = lt.eq
  ,leadsto = arrow.squiggly
  ,leftarrow = arrow.l
  ,leftthreetimes = times.three.l
  ,leftrightarrow = arrow.l.r
  ,leq = lt.eq
  ,leqslant = lt.eq.slant
  ,lhd = triangle.l
  ,ll = lt.double
  ,longmapsto = arrow.long.bar
  ,longrightarrow = arrow.long
  ,ltimes = times.l
  ,mapsto = arrow.bar
  ,measuredangle = angle.arc
  ,mid = divides
  ,models = models
  ,mp = minus.plus
  ,mu = mu
  ,nRightarrow = arrow.double.not
  ,nabla = nabla
  ,ncong = tilde.nequiv
  ,ne = eq.not
  ,neg = not
  ,neq = eq.not
  ,nmid = divides.not
  ,notin = in.not
  ,nleftarrow = arrow.l.not
  ,nrightarrow = arrow.not
  ,nsim = tilde.not
  ,nu = nu
  ,odot = dot.circle
  ,oint = integral.cont
  ,omega = omega
 %,omicron = omicron
  ,ominus = minus.circle
  ,oplus = plus.circle
  ,otimes = times.circle
  ,parallel = parallel
  ,partial = diff
  ,perp = perp
  ,phi = phi.alt
  ,pi = pi
  ,pm = plus.minus
  ,prec = prec
  ,preceq = prec.eq
  ,prime = prime
  ,prod = product
  ,propto = prop
  ,psi = psi
  ,rangle = angle.r
  ,rbrace = brace.r
  ,rbrack = bracket.r
  ,rhd = triangle
  ,rho = rho
  ,rightarrow = arrow.r
  ,rightthreetimes = times.three.r
  ,rtimes = times.r
  ,setminus = without
  ,sigma = sigma
  ,sim = tilde
  ,simeq = tilde.eq
 %,smile = paren.b
  ,sqcap = sect.sq
  ,sqcup = union.sq
  ,star = star
  ,subset = subset
  ,subseteq = subset.eq
  ,subsetneq = subset.neq
  ,succ = succ
  ,succeq = succ.eq
  ,sum = sum
  ,supset = supset
  ,supseteq = supset.eq
  ,supsetneq = supset.neq
  ,tau = tau
  ,theta = theta
  ,times = times
  ,to = arrow.r
  ,triangle = triangle.t
  ,triangleleft = triangle.l.small
  ,triangleright = triangle.small
  ,uparrow = arrow.t
  ,updownarrow = arrow.t.b
  ,upharpoonright = harpoon.tr
  ,uplus = union.plus
  ,upsilon = upsilon
  ,varepsilon = epsilon
  ,varphi = phi
  ,varpi = pi.alt
  ,varrho = rho.alt
  ,varsigma = sigma.alt
  ,vartheta = theta.alt
  ,vdash = tack.r
  ,vdots = dots.v
  ,vee = or
  ,wedge = and
  ,wr = wreath
  ,xi = xi
  ,zeta = zeta
}

\prgNewFunction\typstfun@init{m}{
  \propVarMapInline{\expName{c@typstfun@#1@prop}}{
    \tlSet{\expName{l@typstfun@name@##1@tl}}{##2}
  }
}

\typstfun@init{text@env}
\typstfun@init{text@cmd}
\typstfun@init{math@env}
\typstfun@init{math@cmd}
\typstfun@init{math@sym}

\NewDocumentCommand\typstfun{m}{
  \texttt{\expName{l@typstfun@name@#1@tl}}
}

\tlNew\l@typstfun@latex@type@tl
\tlSet\l@typstfun@latex@type@tl{Command}

\tlConst\c@typstfun@longtable@begin@tl{
  \begingroup
  \setlength\tabcolsep{0pt}
  \begin{longtable}{*{4}{p{0.25\linewidth}}}
  \toprule
  LaTeX~\l@typstfun@latex@type@tl & Typst~Function &
  LaTeX~\l@typstfun@latex@type@tl & Typst~Function \\
  \midrule
  \endhead
  \bottomrule
  \endfoot
}

\tlConst\c@typstfun@longtable@end@tl{
  \end{longtable}
  \endgroup
}

\prgNewFunction\typstfunPrintTable{Mmm}{
  \tlClear\lTmpaTl
  \intZero\lTmpaInt
  \propVarMapInline{#1}{
    \tlPutRight\lTmpaTl{#2&#3}
    \intIncr\lTmpaInt
    \intIfOddTF{\lTmpaInt}{
      \tlPutRight\lTmpaTl{&}
    }{
      \tlPutRight\lTmpaTl{\\}
    }
  }
  \c@typstfun@longtable@begin@tl
  \lTmpaTl
  \c@typstfun@longtable@end@tl
}

\prgNewFunction\typstfunPrintEnv{m}{
  \tlSet\l@typstfun@latex@type@tl{Environment}
  \typstfunPrintTable{
    \expName{c@typstfun@#1@env@prop}
  }{
    \texttt{##1}
  }{
    \texttt{##2}
  }
}

\prgNewFunction\typstfunPrintCmd{m}{
  \tlSet\l@typstfun@latex@type@tl{Command}
  \typstfunPrintTable{
    \expName{c@typstfun@#1@cmd@prop}
  }{
    \ExpandArgs{c}\fakeverb{##1}
  }{
    \texttt{##2}
  }
}

\prgNewFunction\typstfunPrintSym{m}{
  \tlSet\l@typstfun@latex@type@tl{Symbol}
  \typstfunPrintTable{
    \expName{c@typstfun@#1@sym@prop}
  }{
    \ExpandArgs{c}\fakeverb{##1}\hfill$\UseName{##1}$\hspace*{1em}
  }{
    \texttt{##2}
  }
}

\IgnoreSpacesOff
