I am trying to create a command \projlib_math_define_shortcut:nnn for defining shortcuts for math letters. Ideally, it should be able to use like \projlib_math_define_shortcut:nnn { mathcal } { cal, mc } { A, B, C }, which should do:
- create two short cuts
\caland\mcfor\mathcal - create shortcuts for the letters given, in this case,
\calAand\mcAfor\mathcal{A}, etc.
For this, I make use of the clist structure of expl3. I think it is my wrong usage of ## and ### that causes the errors (Illegal parameter number in definition of \__clist_map_1:w.). My current code is listed in the following MWE. Could you please tell me why does it produce errors and how should it be fixed?
\documentclass{article}
\usepackage{amssymb}
\ExplSyntaxOn
% \projlib_math_define_shortcut:nnn { math command } { shortcut name(s) } { shortcut member(s) }
\cs_new:Nn \projlib_math_define_shortcut:nnn
{
\clist_set:Nn \l_tmpa_clist { #2 }
\clist_set:Nn \l_tmpb_clist { #3 }
\clist_map_inline:Nn \l_tmpa_clist
{
% create \shortcut{}
\tl_if_blank:eF { ##1 }
{
\tl_if_exist:cF { ##1 }
{
\tl_gset:cn { ##1 }
{
\ensuremath { \tl_use:c { #1 } { ###1 } }
}
}
}
% create \shortcut
\clist_map_inline:Nn \l_tmpb_clist
{
\tl_if_exist:cF { ##1 ###1 }
{
\tl_gset:cn { ##1 ###1 }
{
\ensuremath { \tl_use:c { #1 } { ###1 } }
}
}
}
}
}
\projlib_math_define_shortcut:nnn { mathbb } { bb }
{
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
}
\projlib_math_define_shortcut:nnn { mathfrak } { mf, frak }
{
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
}
\projlib_math_define_shortcut:nnn { mathcal } { mc, cal }
{
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
}
% \projlib_math_define_shortcut:nnn { mathbb } { }
% {
% N, Z, Q, R, C, F, A
% }
\ExplSyntaxOff
\begin{document}
\fraka
\bbA
% \C
\end{document}


#is wrong. You'll have to double the number of#for each level of nesting. So#for direct parameter,##for parameter inside of a definition,####for a parameter inside the definition of a definition of a definition, etc. – Skillmon Feb 05 '22 at 12:54#shall be needed. – Jinwen Feb 05 '22 at 13:00##produces#just as#1produces the first argument, the fact that it doubles each time is a consequence of that: there is no special code for more than two#, just the outer definition you need##for each#so if you need##for the inner definition then you need####in the outer one. – David Carlisle Feb 05 '22 at 14:03