how do I test for a unique string with multiple possibilities?String test, with complicated argumentsString test, with an OR connectorHow to do multiple string replacements?Numerical conditional within tikz keys?How to test if a string is emptyPackage to test whether a string is in a listTest whether a string is in a list with variableVisualize multiple string segmentsExpandable case insensitive switch case for string comparison

Was Switzerland pressured either by Allies or Axis to take part in World War 2 at any time?

Are commoners actually this squishy?

Heat-shrink tubing available as a roll like adhesive tape?

Do any languages mark social distinctions other than gender and status?

When and why did the House rules change to permit an inquiry without a vote?

Why are there never-ending wars in the Middle East?

RAM stress test

Is the EU Settlement Scheme legal?

Vertical Yagi spun at 1000 RPM: gain properties?

Is rent considered a debt?

Length-terminated sequences

Are translation journals still a thing any more?

Repeating Numbered Items in Beamer

It's right here. It's very very far

Can US Congress members be (successfully) sued for defamation?

What does "he was equally game to slip into bit parts" mean?

Truth table generator for an arbitrary function

What is the white stuff emerging from a hole on the surface of Mars?

Implement the 2D Hadamard Transform

The use of SlotSequence in If[#1 > #2, ##] &

How would a race of humanoids with tails design [vehicle] seats?

Remove x last elements of an array and reinsert them before position y

Protecting yourself against OSINT?

Are there any known problems or attacks for using SHA1(AES_key) as the HMAC key?



how do I test for a unique string with multiple possibilities?


String test, with complicated argumentsString test, with an OR connectorHow to do multiple string replacements?Numerical conditional within tikz keys?How to test if a string is emptyPackage to test whether a string is in a listTest whether a string is in a list with variableVisualize multiple string segmentsExpandable case insensitive switch case for string comparison






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









3

















I'm writing a macro that takes a string and it returns an href based on that string. The string could have 150 different values. My question is how to write this in an efficient way. Using pdflatex.



Here's what I've got right now, shortened to two conditions for explanation:



documentclassarticle
usepackagehyperref
newcommandmyref[1]%
ifnumpdfstrcmp#1aaa=0%
hrefexample.com/aaamy aaa link
fi
ifnumpdfstrcmp#1bbb=0%
hrefexample.com/bbbmy bbb link
fi

begindocument
Here is myrefaaa.
enddocument


But of course once I get a success (#1=aaa, say), I'm still testing the other 149 conditions for no reason. How to code this efficiently?










share|improve this question


























  • Are all of the outcomes of the form hrefexample.com/<string>my <string> link?

    – Joseph Wright
    May 28 at 13:13











  • Ah, I simplified too much. It will actually take two args. first arg goes in the link address, the second provides the link text. Like hrefexample.com/aaaThe Title of the AAA Document (link text will have completely different text on each invocation of the macro.

    – Tim A
    May 28 at 13:16

















3

















I'm writing a macro that takes a string and it returns an href based on that string. The string could have 150 different values. My question is how to write this in an efficient way. Using pdflatex.



Here's what I've got right now, shortened to two conditions for explanation:



documentclassarticle
usepackagehyperref
newcommandmyref[1]%
ifnumpdfstrcmp#1aaa=0%
hrefexample.com/aaamy aaa link
fi
ifnumpdfstrcmp#1bbb=0%
hrefexample.com/bbbmy bbb link
fi

begindocument
Here is myrefaaa.
enddocument


But of course once I get a success (#1=aaa, say), I'm still testing the other 149 conditions for no reason. How to code this efficiently?










share|improve this question


























  • Are all of the outcomes of the form hrefexample.com/<string>my <string> link?

    – Joseph Wright
    May 28 at 13:13











  • Ah, I simplified too much. It will actually take two args. first arg goes in the link address, the second provides the link text. Like hrefexample.com/aaaThe Title of the AAA Document (link text will have completely different text on each invocation of the macro.

    – Tim A
    May 28 at 13:16













3












3








3


1






I'm writing a macro that takes a string and it returns an href based on that string. The string could have 150 different values. My question is how to write this in an efficient way. Using pdflatex.



Here's what I've got right now, shortened to two conditions for explanation:



documentclassarticle
usepackagehyperref
newcommandmyref[1]%
ifnumpdfstrcmp#1aaa=0%
hrefexample.com/aaamy aaa link
fi
ifnumpdfstrcmp#1bbb=0%
hrefexample.com/bbbmy bbb link
fi

begindocument
Here is myrefaaa.
enddocument


But of course once I get a success (#1=aaa, say), I'm still testing the other 149 conditions for no reason. How to code this efficiently?










share|improve this question















I'm writing a macro that takes a string and it returns an href based on that string. The string could have 150 different values. My question is how to write this in an efficient way. Using pdflatex.



Here's what I've got right now, shortened to two conditions for explanation:



documentclassarticle
usepackagehyperref
newcommandmyref[1]%
ifnumpdfstrcmp#1aaa=0%
hrefexample.com/aaamy aaa link
fi
ifnumpdfstrcmp#1bbb=0%
hrefexample.com/bbbmy bbb link
fi

begindocument
Here is myrefaaa.
enddocument


But of course once I get a success (#1=aaa, say), I'm still testing the other 149 conditions for no reason. How to code this efficiently?







conditionals strings pdfstrcmp






share|improve this question














share|improve this question











share|improve this question




share|improve this question










asked May 28 at 12:59









Tim ATim A

1,1775 silver badges14 bronze badges




1,1775 silver badges14 bronze badges















  • Are all of the outcomes of the form hrefexample.com/<string>my <string> link?

    – Joseph Wright
    May 28 at 13:13











  • Ah, I simplified too much. It will actually take two args. first arg goes in the link address, the second provides the link text. Like hrefexample.com/aaaThe Title of the AAA Document (link text will have completely different text on each invocation of the macro.

    – Tim A
    May 28 at 13:16

















  • Are all of the outcomes of the form hrefexample.com/<string>my <string> link?

    – Joseph Wright
    May 28 at 13:13











  • Ah, I simplified too much. It will actually take two args. first arg goes in the link address, the second provides the link text. Like hrefexample.com/aaaThe Title of the AAA Document (link text will have completely different text on each invocation of the macro.

    – Tim A
    May 28 at 13:16
















Are all of the outcomes of the form hrefexample.com/<string>my <string> link?

– Joseph Wright
May 28 at 13:13





Are all of the outcomes of the form hrefexample.com/<string>my <string> link?

– Joseph Wright
May 28 at 13:13













Ah, I simplified too much. It will actually take two args. first arg goes in the link address, the second provides the link text. Like hrefexample.com/aaaThe Title of the AAA Document (link text will have completely different text on each invocation of the macro.

– Tim A
May 28 at 13:16





Ah, I simplified too much. It will actually take two args. first arg goes in the link address, the second provides the link text. Like hrefexample.com/aaaThe Title of the AAA Document (link text will have completely different text on each invocation of the macro.

– Tim A
May 28 at 13:16










3 Answers
3






active

oldest

votes


















5


















I would e.g. create command names:



documentclassarticle
usepackagehyperref
makeatletter
@namedefaaa@linkhrefexample.com/aaamy aaa link
@namedefbbb@linkhrefexample.com/bbbmy bbb link

newcommandmyref[1]%
csname #1@linkendcsname

begindocument
Here is myrefaaa.
enddocument





share|improve this answer



































    2


















    let biber do the searching for you:



    assuming there is a file test.bib with



    @onlinetex,
    note=my aaa text,
    url=tex.stackexchange.com


    @onlinegoogle,
    note=my bbb text,
    url=www.google.com



    then



    documentclassarticle
    usepackagebiblatex

    addbibresourcetest.bib

    DeclareFieldFormaturlhref#1printfieldnote
    DeclareCiteCommandmyrefusebibmacrourl

    usepackagehyperref

    begindocument
    Here is myreftex

    myrefgoogle

    enddocument





    share|improve this answer



































      2


















      You can use xparse:



      pdfcompresslevel=0
      documentclassarticle
      usepackagexparse
      usepackagehyperref

      ExplSyntaxOn

      NewDocumentCommandnewrefmmm
      % #1 = key, #2 = URL, #3 = description, #4 = options for href
      prop_gput:Nnx g_tima_sites_prop #1 @ url tl_to_str:n #2
      prop_gput:Nnn g_tima_sites_prop #1 @ desc #3


      NewDocumentCommandmyrefm
      % #1 = key
      tima_href:xx
      prop_item:Nn g_tima_sites_prop #1 @ url
      prop_item:Nn g_tima_sites_prop #1 @ desc


      prop_new:N g_tima_sites_prop
      cs_new_protected:Nn tima_href:nn href#1#2
      cs_generate_variant:Nn tima_href:nn xx

      ExplSyntaxOff

      newreftexworkshttp://profs.scienze.univr.it/~gregorio/introtexworksTeX works intro
      newrefararahttp://profs.scienze.univr.it/~gregorio/introararaArara intro
      newreftex.sxhttps://tex.stackexchange.comNice site

      begindocument

      myreftexworks

      myrefarara

      myreftex.sx

      enddocument





      share|improve this answer



























        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "85"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f493041%2fhow-do-i-test-for-a-unique-string-with-multiple-possibilities%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown


























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        5


















        I would e.g. create command names:



        documentclassarticle
        usepackagehyperref
        makeatletter
        @namedefaaa@linkhrefexample.com/aaamy aaa link
        @namedefbbb@linkhrefexample.com/bbbmy bbb link

        newcommandmyref[1]%
        csname #1@linkendcsname

        begindocument
        Here is myrefaaa.
        enddocument





        share|improve this answer
































          5


















          I would e.g. create command names:



          documentclassarticle
          usepackagehyperref
          makeatletter
          @namedefaaa@linkhrefexample.com/aaamy aaa link
          @namedefbbb@linkhrefexample.com/bbbmy bbb link

          newcommandmyref[1]%
          csname #1@linkendcsname

          begindocument
          Here is myrefaaa.
          enddocument





          share|improve this answer






























            5














            5










            5









            I would e.g. create command names:



            documentclassarticle
            usepackagehyperref
            makeatletter
            @namedefaaa@linkhrefexample.com/aaamy aaa link
            @namedefbbb@linkhrefexample.com/bbbmy bbb link

            newcommandmyref[1]%
            csname #1@linkendcsname

            begindocument
            Here is myrefaaa.
            enddocument





            share|improve this answer
















            I would e.g. create command names:



            documentclassarticle
            usepackagehyperref
            makeatletter
            @namedefaaa@linkhrefexample.com/aaamy aaa link
            @namedefbbb@linkhrefexample.com/bbbmy bbb link

            newcommandmyref[1]%
            csname #1@linkendcsname

            begindocument
            Here is myrefaaa.
            enddocument






            share|improve this answer















            share|improve this answer




            share|improve this answer








            edited May 28 at 13:33

























            answered May 28 at 13:14









            Ulrike FischerUlrike Fischer

            218k9 gold badges326 silver badges727 bronze badges




            218k9 gold badges326 silver badges727 bronze badges


























                2


















                let biber do the searching for you:



                assuming there is a file test.bib with



                @onlinetex,
                note=my aaa text,
                url=tex.stackexchange.com


                @onlinegoogle,
                note=my bbb text,
                url=www.google.com



                then



                documentclassarticle
                usepackagebiblatex

                addbibresourcetest.bib

                DeclareFieldFormaturlhref#1printfieldnote
                DeclareCiteCommandmyrefusebibmacrourl

                usepackagehyperref

                begindocument
                Here is myreftex

                myrefgoogle

                enddocument





                share|improve this answer
































                  2


















                  let biber do the searching for you:



                  assuming there is a file test.bib with



                  @onlinetex,
                  note=my aaa text,
                  url=tex.stackexchange.com


                  @onlinegoogle,
                  note=my bbb text,
                  url=www.google.com



                  then



                  documentclassarticle
                  usepackagebiblatex

                  addbibresourcetest.bib

                  DeclareFieldFormaturlhref#1printfieldnote
                  DeclareCiteCommandmyrefusebibmacrourl

                  usepackagehyperref

                  begindocument
                  Here is myreftex

                  myrefgoogle

                  enddocument





                  share|improve this answer






























                    2














                    2










                    2









                    let biber do the searching for you:



                    assuming there is a file test.bib with



                    @onlinetex,
                    note=my aaa text,
                    url=tex.stackexchange.com


                    @onlinegoogle,
                    note=my bbb text,
                    url=www.google.com



                    then



                    documentclassarticle
                    usepackagebiblatex

                    addbibresourcetest.bib

                    DeclareFieldFormaturlhref#1printfieldnote
                    DeclareCiteCommandmyrefusebibmacrourl

                    usepackagehyperref

                    begindocument
                    Here is myreftex

                    myrefgoogle

                    enddocument





                    share|improve this answer
















                    let biber do the searching for you:



                    assuming there is a file test.bib with



                    @onlinetex,
                    note=my aaa text,
                    url=tex.stackexchange.com


                    @onlinegoogle,
                    note=my bbb text,
                    url=www.google.com



                    then



                    documentclassarticle
                    usepackagebiblatex

                    addbibresourcetest.bib

                    DeclareFieldFormaturlhref#1printfieldnote
                    DeclareCiteCommandmyrefusebibmacrourl

                    usepackagehyperref

                    begindocument
                    Here is myreftex

                    myrefgoogle

                    enddocument






                    share|improve this answer















                    share|improve this answer




                    share|improve this answer








                    edited May 28 at 13:27

























                    answered May 28 at 13:11









                    ianian

                    2868 bronze badges




                    2868 bronze badges
























                        2


















                        You can use xparse:



                        pdfcompresslevel=0
                        documentclassarticle
                        usepackagexparse
                        usepackagehyperref

                        ExplSyntaxOn

                        NewDocumentCommandnewrefmmm
                        % #1 = key, #2 = URL, #3 = description, #4 = options for href
                        prop_gput:Nnx g_tima_sites_prop #1 @ url tl_to_str:n #2
                        prop_gput:Nnn g_tima_sites_prop #1 @ desc #3


                        NewDocumentCommandmyrefm
                        % #1 = key
                        tima_href:xx
                        prop_item:Nn g_tima_sites_prop #1 @ url
                        prop_item:Nn g_tima_sites_prop #1 @ desc


                        prop_new:N g_tima_sites_prop
                        cs_new_protected:Nn tima_href:nn href#1#2
                        cs_generate_variant:Nn tima_href:nn xx

                        ExplSyntaxOff

                        newreftexworkshttp://profs.scienze.univr.it/~gregorio/introtexworksTeX works intro
                        newrefararahttp://profs.scienze.univr.it/~gregorio/introararaArara intro
                        newreftex.sxhttps://tex.stackexchange.comNice site

                        begindocument

                        myreftexworks

                        myrefarara

                        myreftex.sx

                        enddocument





                        share|improve this answer






























                          2


















                          You can use xparse:



                          pdfcompresslevel=0
                          documentclassarticle
                          usepackagexparse
                          usepackagehyperref

                          ExplSyntaxOn

                          NewDocumentCommandnewrefmmm
                          % #1 = key, #2 = URL, #3 = description, #4 = options for href
                          prop_gput:Nnx g_tima_sites_prop #1 @ url tl_to_str:n #2
                          prop_gput:Nnn g_tima_sites_prop #1 @ desc #3


                          NewDocumentCommandmyrefm
                          % #1 = key
                          tima_href:xx
                          prop_item:Nn g_tima_sites_prop #1 @ url
                          prop_item:Nn g_tima_sites_prop #1 @ desc


                          prop_new:N g_tima_sites_prop
                          cs_new_protected:Nn tima_href:nn href#1#2
                          cs_generate_variant:Nn tima_href:nn xx

                          ExplSyntaxOff

                          newreftexworkshttp://profs.scienze.univr.it/~gregorio/introtexworksTeX works intro
                          newrefararahttp://profs.scienze.univr.it/~gregorio/introararaArara intro
                          newreftex.sxhttps://tex.stackexchange.comNice site

                          begindocument

                          myreftexworks

                          myrefarara

                          myreftex.sx

                          enddocument





                          share|improve this answer




























                            2














                            2










                            2









                            You can use xparse:



                            pdfcompresslevel=0
                            documentclassarticle
                            usepackagexparse
                            usepackagehyperref

                            ExplSyntaxOn

                            NewDocumentCommandnewrefmmm
                            % #1 = key, #2 = URL, #3 = description, #4 = options for href
                            prop_gput:Nnx g_tima_sites_prop #1 @ url tl_to_str:n #2
                            prop_gput:Nnn g_tima_sites_prop #1 @ desc #3


                            NewDocumentCommandmyrefm
                            % #1 = key
                            tima_href:xx
                            prop_item:Nn g_tima_sites_prop #1 @ url
                            prop_item:Nn g_tima_sites_prop #1 @ desc


                            prop_new:N g_tima_sites_prop
                            cs_new_protected:Nn tima_href:nn href#1#2
                            cs_generate_variant:Nn tima_href:nn xx

                            ExplSyntaxOff

                            newreftexworkshttp://profs.scienze.univr.it/~gregorio/introtexworksTeX works intro
                            newrefararahttp://profs.scienze.univr.it/~gregorio/introararaArara intro
                            newreftex.sxhttps://tex.stackexchange.comNice site

                            begindocument

                            myreftexworks

                            myrefarara

                            myreftex.sx

                            enddocument





                            share|improve this answer














                            You can use xparse:



                            pdfcompresslevel=0
                            documentclassarticle
                            usepackagexparse
                            usepackagehyperref

                            ExplSyntaxOn

                            NewDocumentCommandnewrefmmm
                            % #1 = key, #2 = URL, #3 = description, #4 = options for href
                            prop_gput:Nnx g_tima_sites_prop #1 @ url tl_to_str:n #2
                            prop_gput:Nnn g_tima_sites_prop #1 @ desc #3


                            NewDocumentCommandmyrefm
                            % #1 = key
                            tima_href:xx
                            prop_item:Nn g_tima_sites_prop #1 @ url
                            prop_item:Nn g_tima_sites_prop #1 @ desc


                            prop_new:N g_tima_sites_prop
                            cs_new_protected:Nn tima_href:nn href#1#2
                            cs_generate_variant:Nn tima_href:nn xx

                            ExplSyntaxOff

                            newreftexworkshttp://profs.scienze.univr.it/~gregorio/introtexworksTeX works intro
                            newrefararahttp://profs.scienze.univr.it/~gregorio/introararaArara intro
                            newreftex.sxhttps://tex.stackexchange.comNice site

                            begindocument

                            myreftexworks

                            myrefarara

                            myreftex.sx

                            enddocument






                            share|improve this answer













                            share|improve this answer




                            share|improve this answer










                            answered May 28 at 15:38









                            egregegreg

                            775k92 gold badges2020 silver badges3381 bronze badges




                            775k92 gold badges2020 silver badges3381 bronze badges































                                draft saved

                                draft discarded















































                                Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f493041%2fhow-do-i-test-for-a-unique-string-with-multiple-possibilities%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown









                                Popular posts from this blog

                                Tamil (spriik) Luke uk diar | Nawigatjuun

                                Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                                Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?