2

I am wanting to produce a simple package called aminosymb for CTAN as I have macros for typesetting amino acids and residue numbers (with optional symbols above the residue name like *, improved from an old question: Custom asterisk for amino acid names). I want to write the package in expl3 but my efforts are inadequate so far. I have the following non-working MWE:

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\AminoAcidPrinter}{mm}
    {
        \aminoacid_printer:n { #1 #2 }
    }

\str_new:N \s__aminoacid_printer_str

\cs_new_protected:Nn \aminoacid_printer:n
    {
        \str_clear:N \s__aminoacid_printer_str
        \tl_map_function:nN { #1 } \__aminoacid_printer_str_add:n
        \str_use:Nn \s__aminoacid_printer_str
    }

\cs_new_protected:Nn \__aminoacid_printer_str_add:n
    {
    \str_put_right:Nx \s__aminoacid_printer_str
    {
        \str_case:nn { #1 }
        {
        {HIS}{His}
        {His}{His}
        {H}{His}
        {h}{His}
        }
    }
    }

\ExplSyntaxOff

\begin{document}
\noindent\AminoAcidPrinter{h}{442}\newline
\AminoAcidPrinter{HIS}{442}\newline
\AminoAcidPrinter{His}{442}\newline
\AminoAcidPrinter{H}{442}\newline
\end{document}

All four options should print out the same output i.e. His 442. The code itself doesn't work with the first error being

Undefined control sequence.
\aminoacid_printer:n ...ter_str_add:n \str_use:Nn 
                                                  \s__aminoacid_printer_str 

which whilst being informative, I am not sure how to proceed nor how to manage a second argument within the \NewDocumentCommand. I am not even sure if I should be using \s__ for string or if this is a token/other datatype. How can I make this document compile and print out His 442 for all four varying inputs please?

I am new to expl3 and have been reading through the LaTeX3 Interfaces but it is a steep learning curve and I wouldn't mind a working basic document I can build on to adapt my macros for expl3 plus helpful hints with respect to this MWE please.

9
  • 1
    The prefix should be l, g, or c indicating local, global or constant definition, in this case I expect l
    – Dai Bowen
    May 24, 2023 at 14:47
  • 1
    there is no \str_use:Nn, did you mean to use \str_use:N?
    – Udi Fogiel
    May 24, 2023 at 14:48
  • 2
    the error message seems clear you used \str_use:Nn which is not defined, what did you want this to do? May 24, 2023 at 14:51
  • @DavidCarlisle I think I used that due to the second argument and then accidentally left it in, it compiles after changing it now although I am not sure how to use the second argument in it now, should I replicate \str_use:N for the 2nd argument?
    – JamesT
    May 24, 2023 at 14:53
  • @UdiFogiel yes I meant that, my mistake I thought I needed 2 for the second argument
    – JamesT
    May 24, 2023 at 14:53

1 Answer 1

2

It is not at all clear what you want this code to do, but this runs without error

enter image description here

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\AminoAcidPrinter}{mm}
    {
        \aminoacid_printer:nn { #1 }{ #2 }
    }

\str_new:N \l__aminoacid_printer_str

\cs_new_protected:Nn \aminoacid_printer:nn
    {
        \str_clear:N \l__aminoacid_printer_str
        \tl_map_function:nN { #1 } \__aminoacid_printer_str_add:n
        \str_use:N \l__aminoacid_printer_str
         ???
        \str_clear:N \l__aminoacid_printer_str
        \tl_map_function:nN { #2 } \__aminoacid_printer_str_add:n
        \str_use:N \l__aminoacid_printer_str
    }

\cs_new_protected:Nn \__aminoacid_printer_str_add:n
    {
    \str_put_right:Nx \l__aminoacid_printer_str
    {
        \str_case:nn { #1 }
        {
        {HIS}{His}
        {His}{His}
        {H}{His}
        {h}{His}
        }
    }
    }

\ExplSyntaxOff

\begin{document}
\noindent\AminoAcidPrinter{h}{442}\newline
\AminoAcidPrinter{HIS}{442}\newline
\AminoAcidPrinter{His}{442}\newline
\AminoAcidPrinter{H}{442}
\end{document}
2
  • 1
    @JamesT well you asked for a compilable example you could experiment with and hopefully this provides that. It is hard to match any of this code with your requirement which seems to be simply to print #1~#2 with no loops. This code loops through each letter and prints His if h or H appears , so in each case you get His for the first argument and nothing for the second May 24, 2023 at 15:15
  • 1
    Thanks, I will accept as it is a basis to start from and answered the question, think I need to read significantly more before I ask again, this issue was fixed too quickly!
    – JamesT
    May 24, 2023 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .