0

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!).

JamesT
  • 3,169
  • 1
    unrelated to that, you don't need to use \ExplSyntaxOn and \ExplSyntaxOff in an Expl Package. – Udi Fogiel Oct 11 '23 at 15:37
  • @UdiFogiel thank you, will remove it now, this is my first attempt at an Expl package so anything that can help is appreciated :) – JamesT Oct 11 '23 at 15:47

1 Answers1

1

You have an issue here because your last example (meaning in the old question) didn't use a maths-style command, but a font-size command.

The latter only affects your maths-material if used outside the inline maths. The former however has to be used inside your inline maths.

So if you want to only use \displaystyle, \textstyle, \scriptstyle, or \scriptscriptstyle you have to move the \cs_if_exist_use:c { \l_aminosymb_superscript_font_size_tl } (note that I changed the variable name, yours in this MWE is missing the module name -- which I also missed in my older answer) after the opening $.

But if you want to use \large and friends, you have to move it in front of the opening $.

If you want to have both, you'll need to either put in additional parsing effort (branching in the two cases), or provide an additional key.

The error isn't that .initial:n is not obeyed (which you can see by using \tl_show:N \l_aminosymb_superscript_font_size_tl after your \keys_define:nn block).

Skillmon
  • 60,462
  • Skillmon I can't believe that, I meant to write scriptsize not scriptstyle in my .initial value, thank you for pointing that out, just twigged reading your answer, sorry for the issue – JamesT Oct 11 '23 at 15:33
  • 1
    @JamesT don't worry, it happens to all of us :) – Skillmon Oct 11 '23 at 19:03