Identifying if macro is an alias

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I use a def as an alias like so:



defaliasfoo


later on I would like to check if alias is an alias for foo. (X is an alias of Y means the current definition of X is defXY).



See the MWE below for what I tried:



MWE:



documentclassarticle
%usepackagetrace
deffoobar
defbarbar

newcommandisFoo[1]
% expandafterifexpandafternoexpandaliasnoexpandfoo %false positives
% expandafterifxaliasfoo %this one compares text
% expandafterifxexpandafternoexpandaliasnoexpandfoo %false negatives
It is a textbackslash foo #1
else
Not a textbackslash foo #1
fi

begindocument
defaliasfoo
isFooab

defaliasbar
isFooxy

defbarbaz
isFooxy
enddocument


The idea behind the expandafter/noexpand code is to expand alias exactly once and then compare the two tokens without any further expansion to avoid comparing their return values.










share|improve this question





















  • I don't think I understand... You want to check if alias expands to foo without comparing if the contents of foo using, for example, expandafterifxaliasfoo?
    – Phelype Oleinik
    Aug 10 at 19:35






  • 1




    @PhelypeOleinik this is not fail proofed: deffoobardefbarAdefbazAexpandafterifxfoobaz trueelse falsefi yields true, though it should yield false.
    – Skillmon
    Aug 10 at 20:17










  • @Skillmon Makes sense... If OP had replied I would've done something similar to your approach, but using string and ifx instead of detokenize and pdf@strcmp, but then I forgot :P
    – Phelype Oleinik
    Aug 10 at 20:28










  • @PhelypeOleinik: Op disappeared from the keyboard for a while,... but in my simple case what you described did not work (see Skillmon's comment) which lead me to try getting noexpand in the mix.
    – ted
    Aug 10 at 21:00










  • @ted No problem :) Good that OP's problem is solved ;)
    – Phelype Oleinik
    Aug 10 at 21:12














up vote
2
down vote

favorite












I use a def as an alias like so:



defaliasfoo


later on I would like to check if alias is an alias for foo. (X is an alias of Y means the current definition of X is defXY).



See the MWE below for what I tried:



MWE:



documentclassarticle
%usepackagetrace
deffoobar
defbarbar

newcommandisFoo[1]
% expandafterifexpandafternoexpandaliasnoexpandfoo %false positives
% expandafterifxaliasfoo %this one compares text
% expandafterifxexpandafternoexpandaliasnoexpandfoo %false negatives
It is a textbackslash foo #1
else
Not a textbackslash foo #1
fi

begindocument
defaliasfoo
isFooab

defaliasbar
isFooxy

defbarbaz
isFooxy
enddocument


The idea behind the expandafter/noexpand code is to expand alias exactly once and then compare the two tokens without any further expansion to avoid comparing their return values.










share|improve this question





















  • I don't think I understand... You want to check if alias expands to foo without comparing if the contents of foo using, for example, expandafterifxaliasfoo?
    – Phelype Oleinik
    Aug 10 at 19:35






  • 1




    @PhelypeOleinik this is not fail proofed: deffoobardefbarAdefbazAexpandafterifxfoobaz trueelse falsefi yields true, though it should yield false.
    – Skillmon
    Aug 10 at 20:17










  • @Skillmon Makes sense... If OP had replied I would've done something similar to your approach, but using string and ifx instead of detokenize and pdf@strcmp, but then I forgot :P
    – Phelype Oleinik
    Aug 10 at 20:28










  • @PhelypeOleinik: Op disappeared from the keyboard for a while,... but in my simple case what you described did not work (see Skillmon's comment) which lead me to try getting noexpand in the mix.
    – ted
    Aug 10 at 21:00










  • @ted No problem :) Good that OP's problem is solved ;)
    – Phelype Oleinik
    Aug 10 at 21:12












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I use a def as an alias like so:



defaliasfoo


later on I would like to check if alias is an alias for foo. (X is an alias of Y means the current definition of X is defXY).



See the MWE below for what I tried:



MWE:



documentclassarticle
%usepackagetrace
deffoobar
defbarbar

newcommandisFoo[1]
% expandafterifexpandafternoexpandaliasnoexpandfoo %false positives
% expandafterifxaliasfoo %this one compares text
% expandafterifxexpandafternoexpandaliasnoexpandfoo %false negatives
It is a textbackslash foo #1
else
Not a textbackslash foo #1
fi

begindocument
defaliasfoo
isFooab

defaliasbar
isFooxy

defbarbaz
isFooxy
enddocument


The idea behind the expandafter/noexpand code is to expand alias exactly once and then compare the two tokens without any further expansion to avoid comparing their return values.










share|improve this question













I use a def as an alias like so:



defaliasfoo


later on I would like to check if alias is an alias for foo. (X is an alias of Y means the current definition of X is defXY).



See the MWE below for what I tried:



MWE:



documentclassarticle
%usepackagetrace
deffoobar
defbarbar

newcommandisFoo[1]
% expandafterifexpandafternoexpandaliasnoexpandfoo %false positives
% expandafterifxaliasfoo %this one compares text
% expandafterifxexpandafternoexpandaliasnoexpandfoo %false negatives
It is a textbackslash foo #1
else
Not a textbackslash foo #1
fi

begindocument
defaliasfoo
isFooab

defaliasbar
isFooxy

defbarbaz
isFooxy
enddocument


The idea behind the expandafter/noexpand code is to expand alias exactly once and then compare the two tokens without any further expansion to avoid comparing their return values.







conditionals






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 10 at 19:03









ted

1,58421440




1,58421440











  • I don't think I understand... You want to check if alias expands to foo without comparing if the contents of foo using, for example, expandafterifxaliasfoo?
    – Phelype Oleinik
    Aug 10 at 19:35






  • 1




    @PhelypeOleinik this is not fail proofed: deffoobardefbarAdefbazAexpandafterifxfoobaz trueelse falsefi yields true, though it should yield false.
    – Skillmon
    Aug 10 at 20:17










  • @Skillmon Makes sense... If OP had replied I would've done something similar to your approach, but using string and ifx instead of detokenize and pdf@strcmp, but then I forgot :P
    – Phelype Oleinik
    Aug 10 at 20:28










  • @PhelypeOleinik: Op disappeared from the keyboard for a while,... but in my simple case what you described did not work (see Skillmon's comment) which lead me to try getting noexpand in the mix.
    – ted
    Aug 10 at 21:00










  • @ted No problem :) Good that OP's problem is solved ;)
    – Phelype Oleinik
    Aug 10 at 21:12
















  • I don't think I understand... You want to check if alias expands to foo without comparing if the contents of foo using, for example, expandafterifxaliasfoo?
    – Phelype Oleinik
    Aug 10 at 19:35






  • 1




    @PhelypeOleinik this is not fail proofed: deffoobardefbarAdefbazAexpandafterifxfoobaz trueelse falsefi yields true, though it should yield false.
    – Skillmon
    Aug 10 at 20:17










  • @Skillmon Makes sense... If OP had replied I would've done something similar to your approach, but using string and ifx instead of detokenize and pdf@strcmp, but then I forgot :P
    – Phelype Oleinik
    Aug 10 at 20:28










  • @PhelypeOleinik: Op disappeared from the keyboard for a while,... but in my simple case what you described did not work (see Skillmon's comment) which lead me to try getting noexpand in the mix.
    – ted
    Aug 10 at 21:00










  • @ted No problem :) Good that OP's problem is solved ;)
    – Phelype Oleinik
    Aug 10 at 21:12















I don't think I understand... You want to check if alias expands to foo without comparing if the contents of foo using, for example, expandafterifxaliasfoo?
– Phelype Oleinik
Aug 10 at 19:35




I don't think I understand... You want to check if alias expands to foo without comparing if the contents of foo using, for example, expandafterifxaliasfoo?
– Phelype Oleinik
Aug 10 at 19:35




1




1




@PhelypeOleinik this is not fail proofed: deffoobardefbarAdefbazAexpandafterifxfoobaz trueelse falsefi yields true, though it should yield false.
– Skillmon
Aug 10 at 20:17




@PhelypeOleinik this is not fail proofed: deffoobardefbarAdefbazAexpandafterifxfoobaz trueelse falsefi yields true, though it should yield false.
– Skillmon
Aug 10 at 20:17












@Skillmon Makes sense... If OP had replied I would've done something similar to your approach, but using string and ifx instead of detokenize and pdf@strcmp, but then I forgot :P
– Phelype Oleinik
Aug 10 at 20:28




@Skillmon Makes sense... If OP had replied I would've done something similar to your approach, but using string and ifx instead of detokenize and pdf@strcmp, but then I forgot :P
– Phelype Oleinik
Aug 10 at 20:28












@PhelypeOleinik: Op disappeared from the keyboard for a while,... but in my simple case what you described did not work (see Skillmon's comment) which lead me to try getting noexpand in the mix.
– ted
Aug 10 at 21:00




@PhelypeOleinik: Op disappeared from the keyboard for a while,... but in my simple case what you described did not work (see Skillmon's comment) which lead me to try getting noexpand in the mix.
– ted
Aug 10 at 21:00












@ted No problem :) Good that OP's problem is solved ;)
– Phelype Oleinik
Aug 10 at 21:12




@ted No problem :) Good that OP's problem is solved ;)
– Phelype Oleinik
Aug 10 at 21:12










3 Answers
3






active

oldest

votes

















up vote
3
down vote



accepted










You could also just set up another alias for foo and compare alias to that with ifx.



documentclassarticle

% deffoobar
% defbarbar

defknownaliasforfoofoo
newcommandisFoo[1]%
ifxaliasknownaliasforfoo
It is a textbackslash foo #1%
else
Not a textbackslash foo #1%
fi


begindocument
defaliasfoo
isFooab

defaliasbar
isFooxy

defbarbaz
isFooxy
enddocument


enter image description here



You can uncomment either or both of the commented lines and the output would remain the same.






share|improve this answer



























    up vote
    5
    down vote













    With expl3:



    documentclassarticle
    usepackagexparse

    ExplSyntaxOn
    NewExpandableDocumentCommandifisaliasTFmmmm
    % #1 = token to test
    % #2 = macro
    % #3 = true case
    % #4 = false case
    ted_ifisalias:nnTF #1 #2 #3 #4


    prg_generate_conditional_variant:Nnn tl_if_empty:n f T,F,TF,p
    prg_generate_conditional_variant:Nnn tl_if_single:n o T,F,TF,p

    prg_new_conditional:Nnn ted_ifisalias:nn T,F,TF,p

    token_if_macro:NTF #1
    % the first argument is a macro
    tl_if_empty:fTF token_get_arg_spec:N #1
    % the macro has no arguments
    tl_if_single:oTF #1
    % the expansion is a single token
    exp_last_unbraced:No token_if_eq_meaning:NNTF #1 #2
    % the first level expansion of #1 is the same as #2
    prg_return_true:

    % false
    prg_return_false:


    % false
    prg_return_false:


    % false
    prg_return_false:


    % false
    prg_return_false:


    ExplSyntaxOff

    newcommandfooWhatever
    newcommandaliasfoo
    newcommandnotaliasA[1]foo
    newcommandnotaliasBfoofoo

    begindocument

    ifisaliasTFaliasfooAliasNot alias

    ifisaliasTFfoofooAliasNot alias

    ifisaliasTFnotaliasAfooAliasNot alias

    ifisaliasTFnotaliasBfooAliasNot alias

    enddocument


    enter image description here






    share|improve this answer



























      up vote
      4
      down vote













      The following should do what you want.



      documentclassarticle

      usepackagepdftexcmds

      defaliasfoo
      makeatletter
      newcommandcheckalias[2]
      %
      expandafterexpandafterexpandafter
      checkalias@aexpandafterexpandafterexpandafter
      expandafterdetokenizeexpandafter#1#2%

      newcommandcheckalias@a[2]
      %
      expandafterifnum
      expandafterpdf@strcmpexpandafterdetokenize#2#1=0
      expandafter@firstoftwo
      else
      expandafter@secondoftwo
      fi

      makeatother

      begindocument
      checkaliasaliasfoo
      still an aliasno longer an alias
      defaliasbar
      checkaliasaliasfoo
      still an aliasno longer an alias
      enddocument


      It doesn't check whether the first argument would grab any arguments though and is therefore not as safe as @egreg's check. I don't think it is worth it implementing the necessary checks without expl3 though.






      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',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        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%2f445544%2fidentifying-if-macro-is-an-alias%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        3
        down vote



        accepted










        You could also just set up another alias for foo and compare alias to that with ifx.



        documentclassarticle

        % deffoobar
        % defbarbar

        defknownaliasforfoofoo
        newcommandisFoo[1]%
        ifxaliasknownaliasforfoo
        It is a textbackslash foo #1%
        else
        Not a textbackslash foo #1%
        fi


        begindocument
        defaliasfoo
        isFooab

        defaliasbar
        isFooxy

        defbarbaz
        isFooxy
        enddocument


        enter image description here



        You can uncomment either or both of the commented lines and the output would remain the same.






        share|improve this answer
























          up vote
          3
          down vote



          accepted










          You could also just set up another alias for foo and compare alias to that with ifx.



          documentclassarticle

          % deffoobar
          % defbarbar

          defknownaliasforfoofoo
          newcommandisFoo[1]%
          ifxaliasknownaliasforfoo
          It is a textbackslash foo #1%
          else
          Not a textbackslash foo #1%
          fi


          begindocument
          defaliasfoo
          isFooab

          defaliasbar
          isFooxy

          defbarbaz
          isFooxy
          enddocument


          enter image description here



          You can uncomment either or both of the commented lines and the output would remain the same.






          share|improve this answer






















            up vote
            3
            down vote



            accepted







            up vote
            3
            down vote



            accepted






            You could also just set up another alias for foo and compare alias to that with ifx.



            documentclassarticle

            % deffoobar
            % defbarbar

            defknownaliasforfoofoo
            newcommandisFoo[1]%
            ifxaliasknownaliasforfoo
            It is a textbackslash foo #1%
            else
            Not a textbackslash foo #1%
            fi


            begindocument
            defaliasfoo
            isFooab

            defaliasbar
            isFooxy

            defbarbaz
            isFooxy
            enddocument


            enter image description here



            You can uncomment either or both of the commented lines and the output would remain the same.






            share|improve this answer












            You could also just set up another alias for foo and compare alias to that with ifx.



            documentclassarticle

            % deffoobar
            % defbarbar

            defknownaliasforfoofoo
            newcommandisFoo[1]%
            ifxaliasknownaliasforfoo
            It is a textbackslash foo #1%
            else
            Not a textbackslash foo #1%
            fi


            begindocument
            defaliasfoo
            isFooab

            defaliasbar
            isFooxy

            defbarbaz
            isFooxy
            enddocument


            enter image description here



            You can uncomment either or both of the commented lines and the output would remain the same.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 10 at 20:32









            Circumscribe

            2,033320




            2,033320




















                up vote
                5
                down vote













                With expl3:



                documentclassarticle
                usepackagexparse

                ExplSyntaxOn
                NewExpandableDocumentCommandifisaliasTFmmmm
                % #1 = token to test
                % #2 = macro
                % #3 = true case
                % #4 = false case
                ted_ifisalias:nnTF #1 #2 #3 #4


                prg_generate_conditional_variant:Nnn tl_if_empty:n f T,F,TF,p
                prg_generate_conditional_variant:Nnn tl_if_single:n o T,F,TF,p

                prg_new_conditional:Nnn ted_ifisalias:nn T,F,TF,p

                token_if_macro:NTF #1
                % the first argument is a macro
                tl_if_empty:fTF token_get_arg_spec:N #1
                % the macro has no arguments
                tl_if_single:oTF #1
                % the expansion is a single token
                exp_last_unbraced:No token_if_eq_meaning:NNTF #1 #2
                % the first level expansion of #1 is the same as #2
                prg_return_true:

                % false
                prg_return_false:


                % false
                prg_return_false:


                % false
                prg_return_false:


                % false
                prg_return_false:


                ExplSyntaxOff

                newcommandfooWhatever
                newcommandaliasfoo
                newcommandnotaliasA[1]foo
                newcommandnotaliasBfoofoo

                begindocument

                ifisaliasTFaliasfooAliasNot alias

                ifisaliasTFfoofooAliasNot alias

                ifisaliasTFnotaliasAfooAliasNot alias

                ifisaliasTFnotaliasBfooAliasNot alias

                enddocument


                enter image description here






                share|improve this answer
























                  up vote
                  5
                  down vote













                  With expl3:



                  documentclassarticle
                  usepackagexparse

                  ExplSyntaxOn
                  NewExpandableDocumentCommandifisaliasTFmmmm
                  % #1 = token to test
                  % #2 = macro
                  % #3 = true case
                  % #4 = false case
                  ted_ifisalias:nnTF #1 #2 #3 #4


                  prg_generate_conditional_variant:Nnn tl_if_empty:n f T,F,TF,p
                  prg_generate_conditional_variant:Nnn tl_if_single:n o T,F,TF,p

                  prg_new_conditional:Nnn ted_ifisalias:nn T,F,TF,p

                  token_if_macro:NTF #1
                  % the first argument is a macro
                  tl_if_empty:fTF token_get_arg_spec:N #1
                  % the macro has no arguments
                  tl_if_single:oTF #1
                  % the expansion is a single token
                  exp_last_unbraced:No token_if_eq_meaning:NNTF #1 #2
                  % the first level expansion of #1 is the same as #2
                  prg_return_true:

                  % false
                  prg_return_false:


                  % false
                  prg_return_false:


                  % false
                  prg_return_false:


                  % false
                  prg_return_false:


                  ExplSyntaxOff

                  newcommandfooWhatever
                  newcommandaliasfoo
                  newcommandnotaliasA[1]foo
                  newcommandnotaliasBfoofoo

                  begindocument

                  ifisaliasTFaliasfooAliasNot alias

                  ifisaliasTFfoofooAliasNot alias

                  ifisaliasTFnotaliasAfooAliasNot alias

                  ifisaliasTFnotaliasBfooAliasNot alias

                  enddocument


                  enter image description here






                  share|improve this answer






















                    up vote
                    5
                    down vote










                    up vote
                    5
                    down vote









                    With expl3:



                    documentclassarticle
                    usepackagexparse

                    ExplSyntaxOn
                    NewExpandableDocumentCommandifisaliasTFmmmm
                    % #1 = token to test
                    % #2 = macro
                    % #3 = true case
                    % #4 = false case
                    ted_ifisalias:nnTF #1 #2 #3 #4


                    prg_generate_conditional_variant:Nnn tl_if_empty:n f T,F,TF,p
                    prg_generate_conditional_variant:Nnn tl_if_single:n o T,F,TF,p

                    prg_new_conditional:Nnn ted_ifisalias:nn T,F,TF,p

                    token_if_macro:NTF #1
                    % the first argument is a macro
                    tl_if_empty:fTF token_get_arg_spec:N #1
                    % the macro has no arguments
                    tl_if_single:oTF #1
                    % the expansion is a single token
                    exp_last_unbraced:No token_if_eq_meaning:NNTF #1 #2
                    % the first level expansion of #1 is the same as #2
                    prg_return_true:

                    % false
                    prg_return_false:


                    % false
                    prg_return_false:


                    % false
                    prg_return_false:


                    % false
                    prg_return_false:


                    ExplSyntaxOff

                    newcommandfooWhatever
                    newcommandaliasfoo
                    newcommandnotaliasA[1]foo
                    newcommandnotaliasBfoofoo

                    begindocument

                    ifisaliasTFaliasfooAliasNot alias

                    ifisaliasTFfoofooAliasNot alias

                    ifisaliasTFnotaliasAfooAliasNot alias

                    ifisaliasTFnotaliasBfooAliasNot alias

                    enddocument


                    enter image description here






                    share|improve this answer












                    With expl3:



                    documentclassarticle
                    usepackagexparse

                    ExplSyntaxOn
                    NewExpandableDocumentCommandifisaliasTFmmmm
                    % #1 = token to test
                    % #2 = macro
                    % #3 = true case
                    % #4 = false case
                    ted_ifisalias:nnTF #1 #2 #3 #4


                    prg_generate_conditional_variant:Nnn tl_if_empty:n f T,F,TF,p
                    prg_generate_conditional_variant:Nnn tl_if_single:n o T,F,TF,p

                    prg_new_conditional:Nnn ted_ifisalias:nn T,F,TF,p

                    token_if_macro:NTF #1
                    % the first argument is a macro
                    tl_if_empty:fTF token_get_arg_spec:N #1
                    % the macro has no arguments
                    tl_if_single:oTF #1
                    % the expansion is a single token
                    exp_last_unbraced:No token_if_eq_meaning:NNTF #1 #2
                    % the first level expansion of #1 is the same as #2
                    prg_return_true:

                    % false
                    prg_return_false:


                    % false
                    prg_return_false:


                    % false
                    prg_return_false:


                    % false
                    prg_return_false:


                    ExplSyntaxOff

                    newcommandfooWhatever
                    newcommandaliasfoo
                    newcommandnotaliasA[1]foo
                    newcommandnotaliasBfoofoo

                    begindocument

                    ifisaliasTFaliasfooAliasNot alias

                    ifisaliasTFfoofooAliasNot alias

                    ifisaliasTFnotaliasAfooAliasNot alias

                    ifisaliasTFnotaliasBfooAliasNot alias

                    enddocument


                    enter image description here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 10 at 20:20









                    egreg

                    682k8318143061




                    682k8318143061




















                        up vote
                        4
                        down vote













                        The following should do what you want.



                        documentclassarticle

                        usepackagepdftexcmds

                        defaliasfoo
                        makeatletter
                        newcommandcheckalias[2]
                        %
                        expandafterexpandafterexpandafter
                        checkalias@aexpandafterexpandafterexpandafter
                        expandafterdetokenizeexpandafter#1#2%

                        newcommandcheckalias@a[2]
                        %
                        expandafterifnum
                        expandafterpdf@strcmpexpandafterdetokenize#2#1=0
                        expandafter@firstoftwo
                        else
                        expandafter@secondoftwo
                        fi

                        makeatother

                        begindocument
                        checkaliasaliasfoo
                        still an aliasno longer an alias
                        defaliasbar
                        checkaliasaliasfoo
                        still an aliasno longer an alias
                        enddocument


                        It doesn't check whether the first argument would grab any arguments though and is therefore not as safe as @egreg's check. I don't think it is worth it implementing the necessary checks without expl3 though.






                        share|improve this answer


























                          up vote
                          4
                          down vote













                          The following should do what you want.



                          documentclassarticle

                          usepackagepdftexcmds

                          defaliasfoo
                          makeatletter
                          newcommandcheckalias[2]
                          %
                          expandafterexpandafterexpandafter
                          checkalias@aexpandafterexpandafterexpandafter
                          expandafterdetokenizeexpandafter#1#2%

                          newcommandcheckalias@a[2]
                          %
                          expandafterifnum
                          expandafterpdf@strcmpexpandafterdetokenize#2#1=0
                          expandafter@firstoftwo
                          else
                          expandafter@secondoftwo
                          fi

                          makeatother

                          begindocument
                          checkaliasaliasfoo
                          still an aliasno longer an alias
                          defaliasbar
                          checkaliasaliasfoo
                          still an aliasno longer an alias
                          enddocument


                          It doesn't check whether the first argument would grab any arguments though and is therefore not as safe as @egreg's check. I don't think it is worth it implementing the necessary checks without expl3 though.






                          share|improve this answer
























                            up vote
                            4
                            down vote










                            up vote
                            4
                            down vote









                            The following should do what you want.



                            documentclassarticle

                            usepackagepdftexcmds

                            defaliasfoo
                            makeatletter
                            newcommandcheckalias[2]
                            %
                            expandafterexpandafterexpandafter
                            checkalias@aexpandafterexpandafterexpandafter
                            expandafterdetokenizeexpandafter#1#2%

                            newcommandcheckalias@a[2]
                            %
                            expandafterifnum
                            expandafterpdf@strcmpexpandafterdetokenize#2#1=0
                            expandafter@firstoftwo
                            else
                            expandafter@secondoftwo
                            fi

                            makeatother

                            begindocument
                            checkaliasaliasfoo
                            still an aliasno longer an alias
                            defaliasbar
                            checkaliasaliasfoo
                            still an aliasno longer an alias
                            enddocument


                            It doesn't check whether the first argument would grab any arguments though and is therefore not as safe as @egreg's check. I don't think it is worth it implementing the necessary checks without expl3 though.






                            share|improve this answer














                            The following should do what you want.



                            documentclassarticle

                            usepackagepdftexcmds

                            defaliasfoo
                            makeatletter
                            newcommandcheckalias[2]
                            %
                            expandafterexpandafterexpandafter
                            checkalias@aexpandafterexpandafterexpandafter
                            expandafterdetokenizeexpandafter#1#2%

                            newcommandcheckalias@a[2]
                            %
                            expandafterifnum
                            expandafterpdf@strcmpexpandafterdetokenize#2#1=0
                            expandafter@firstoftwo
                            else
                            expandafter@secondoftwo
                            fi

                            makeatother

                            begindocument
                            checkaliasaliasfoo
                            still an aliasno longer an alias
                            defaliasbar
                            checkaliasaliasfoo
                            still an aliasno longer an alias
                            enddocument


                            It doesn't check whether the first argument would grab any arguments though and is therefore not as safe as @egreg's check. I don't think it is worth it implementing the necessary checks without expl3 though.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Aug 10 at 20:45

























                            answered Aug 10 at 20:11









                            Skillmon

                            17.7k11535




                            17.7k11535



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f445544%2fidentifying-if-macro-is-an-alias%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay