I asked a question earlier that was helpfully answered by Skillmon but have ran into an issue when relying on the .initial:N value of a package option e.g.
\usepackage[superscript-fontsize=large]{aminosymb}
compiles whereas
\usepackage{aminosymb}
doesn't and fails with
! Missing $ inserted.
<inserted text>
$
l.9 \noindent\aasp{h}{22}
What is causing this issue, I assumed that setting the .initial value of a package option would be respected, where have I went wrong please?
\begin{filecontents}[overwrite]{aminosymb.sty}
\ProvidesExplPackage
{aminosymb}
{today}
{version}
{Typesetting amino acid residues with notation and numbers}
\ExplSyntaxOn
\tl_new:N \l_aminosymb_residue_style_tl
\tl_new:N \l_superscript_font_size_tl
\keys_define:nn { AminoSymb / Package }
{
style .tl_set:N = \l_aminosymb_residue_style_tl,
style .initial:n = abbrev-firstcap,
superscript-fontsize .tl_set:N = \l_superscript_font_size_tl,
superscript-fontsize .initial:n = scriptstyle,
}
\cs_if_exist:NTF \ProcessKeyOptions
{
\ProcessKeyOptions [ AminoSymb / Package ]
}
{
\RequirePackage{l3keys2e}
\ProcessKeysOptions { AminoSymb / Package }
}
\prop_new:N \l_aminosymb_abbrev_ala_prop
\prop_new:N \l_aminosymb_abbrev_all_prop
\prop_set_from_keyval:Nn \l_aminosymb_abbrev_ala_prop
{
initial-lower=a,
abbrev-firstcap = Ala,
}
\prop_set_from_keyval:Nn \l_aminosymb_abbrev_all_prop
{
ala = \l_aminosymb_abbrev_ala_prop,
}
\cs_new:Npn \aminosymb_residueString:nn #1#2
{
\tl_set:Nx\l_aminosymb_residue_tl{#1}
\tl_set:Nx\l_aminosymb_style_tl{#2}
\prop_map_function:NN \l_aminosymb_abbrev_all_prop __aminosymb_abbrev_aux:nn
}
\cs_generate_variant:Nn\prop_item:Nn{Ne}
\cs_new:Npn __aminosymb_abbrev_aux:nn #1#2
{
\prop_map_inline:Nn #2
{
\tl_if_eq:NnT
\l_aminosymb_residue_tl
{##2}
{\prop_item:Ne#2{\l_aminosymb_style_tl}}
}
}
\NewDocumentCommand { \aasp } { m m }
{
\aminosymb_residueString:nn { #1 } { \l_aminosymb_residue_style_tl }
\textsuperscript
{
\cs_if_exist_use:c { \l_superscript_font_size_tl }
$ \mkern-1mu\exp_stop_f: #2 \mkern-1.5mu\exp_stop_f: $
}
}
\ExplSyntaxOff
\end{filecontents}
\documentclass{article}
\usepackage{aminosymb} % <--- doesn't work
%\usepackage[superscript-fontsize=large]{aminosymb} % <--- works
\begin{document}
\aasp{a}{323}
\end{document}
Note: I have made more changes to the naming conventions in my main .sty file (\l_aminosymb_superscriptfontsize_tl etc) and further edits but the code above is the code as answered in the linked question, I think it is probably too substantial for a comment on that answer and perhaps could help others by being its own question (hopefully!).
\ExplSyntaxOnand\ExplSyntaxOffin an Expl Package. – Udi Fogiel Oct 11 '23 at 15:37