Using expanded macro as search pattern for patchcmd Unicorn Meta Zoo #1: Why another...

What's the difference between using dependency injection with a container and using a service locator?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Was Dennis Ritchie being too modest in this quote about C and Pascal?

Can I criticise the more senior developers around me for not writing clean code?

How to not starve gigantic beasts

Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?

Contradiction proof for inequality of P and NP?

Why do distances seem to matter in the Foundation world?

Is there really no use for MD5 anymore?

Map material from china not allowed to leave the country

What makes accurate emulation of old systems a difficult task?

Tikz positioning above circle exact alignment

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

Arriving in Atlanta after US Preclearance in Dublin. Will I go through TSA security in Atlanta to transfer to a connecting flight?

When do you need buffers/drivers on buses in a microprocessor design?

How to translate "red flag" into Spanish?

Is Bran literally the world's memory?

Is Diceware more secure than a long passphrase?

How to keep bees out of canned beverages?

Mistake in years of experience in resume?

Is it possible to cast 2x Final Payment while sacrificing just one creature?

What is purpose of DB Browser(dbbrowser.aspx) under admin tool?

Has a Nobel Peace laureate ever been accused of war crimes?

All ASCII characters with a given bit count



Using expanded macro as search pattern for patchcmd



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraCurrent section title macro using titlesecIs there a workaround for this limitation of patchcmd?Why is patchcmd not working when also using @ifclassloaded?Using an expanded macro for optional environment argumentPattern for vruleSafe test for an empty expanded macro argument?Using MakeUppercase on expanded macro with argumentMacro: Expand differently depending on pattern?Macro - Repeat the pattern for any (even) number of argumentsFixing part layout using patchcmd












10















Is there any way to use the value of an expanded macro as the search pattern for etoolbox's patchcmd (or xpatch's xpatchcmd, etc), so that one can have some sort of a "dynamic" patch, by way of change catcodes?



Here's a MWE.



documentclass{article}

usepackage{etoolbox}
usepackage{xcolor}

begin{document}

newcommand{wordlist}{cat dog parrot goldfish hamster}

newcommandselectpet[1]{%
bgroup
patchcmd{wordlist}{#1}{textcolor{red}{#1}}{}{}
wordlist
egroup
}

selectpet{dog} %% This works

defmychoice{dog}
selectpet{mychoice} %% This doesn't

end{document}









share|improve this question




















  • 2





    Full expansion or once?

    – percusse
    Feb 5 '16 at 10:00






  • 1





    expandafterselectpetexpandafter{mychoice}

    – David Carlisle
    Feb 5 '16 at 10:08











  • Perhaps this is easier with expl3 sequences code instead of patching?

    – user31729
    Feb 5 '16 at 10:51











  • Thanks @percusse, you pointed me in the right direction, and @David hit it on the head! @Christian Unfortunately my expl3-fu is not up to scratch at all. :-/

    – LianTze Lim
    Feb 5 '16 at 13:24











  • @DavidCarlisle Ahem... an answer maybe ?

    – percusse
    Feb 5 '16 at 13:30
















10















Is there any way to use the value of an expanded macro as the search pattern for etoolbox's patchcmd (or xpatch's xpatchcmd, etc), so that one can have some sort of a "dynamic" patch, by way of change catcodes?



Here's a MWE.



documentclass{article}

usepackage{etoolbox}
usepackage{xcolor}

begin{document}

newcommand{wordlist}{cat dog parrot goldfish hamster}

newcommandselectpet[1]{%
bgroup
patchcmd{wordlist}{#1}{textcolor{red}{#1}}{}{}
wordlist
egroup
}

selectpet{dog} %% This works

defmychoice{dog}
selectpet{mychoice} %% This doesn't

end{document}









share|improve this question




















  • 2





    Full expansion or once?

    – percusse
    Feb 5 '16 at 10:00






  • 1





    expandafterselectpetexpandafter{mychoice}

    – David Carlisle
    Feb 5 '16 at 10:08











  • Perhaps this is easier with expl3 sequences code instead of patching?

    – user31729
    Feb 5 '16 at 10:51











  • Thanks @percusse, you pointed me in the right direction, and @David hit it on the head! @Christian Unfortunately my expl3-fu is not up to scratch at all. :-/

    – LianTze Lim
    Feb 5 '16 at 13:24











  • @DavidCarlisle Ahem... an answer maybe ?

    – percusse
    Feb 5 '16 at 13:30














10












10








10


0






Is there any way to use the value of an expanded macro as the search pattern for etoolbox's patchcmd (or xpatch's xpatchcmd, etc), so that one can have some sort of a "dynamic" patch, by way of change catcodes?



Here's a MWE.



documentclass{article}

usepackage{etoolbox}
usepackage{xcolor}

begin{document}

newcommand{wordlist}{cat dog parrot goldfish hamster}

newcommandselectpet[1]{%
bgroup
patchcmd{wordlist}{#1}{textcolor{red}{#1}}{}{}
wordlist
egroup
}

selectpet{dog} %% This works

defmychoice{dog}
selectpet{mychoice} %% This doesn't

end{document}









share|improve this question
















Is there any way to use the value of an expanded macro as the search pattern for etoolbox's patchcmd (or xpatch's xpatchcmd, etc), so that one can have some sort of a "dynamic" patch, by way of change catcodes?



Here's a MWE.



documentclass{article}

usepackage{etoolbox}
usepackage{xcolor}

begin{document}

newcommand{wordlist}{cat dog parrot goldfish hamster}

newcommandselectpet[1]{%
bgroup
patchcmd{wordlist}{#1}{textcolor{red}{#1}}{}{}
wordlist
egroup
}

selectpet{dog} %% This works

defmychoice{dog}
selectpet{mychoice} %% This doesn't

end{document}






macros expansion etoolbox patching






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 17 mins ago









David Carlisle

501k4211471897




501k4211471897










asked Feb 5 '16 at 9:40









LianTze LimLianTze Lim

8,77323068




8,77323068








  • 2





    Full expansion or once?

    – percusse
    Feb 5 '16 at 10:00






  • 1





    expandafterselectpetexpandafter{mychoice}

    – David Carlisle
    Feb 5 '16 at 10:08











  • Perhaps this is easier with expl3 sequences code instead of patching?

    – user31729
    Feb 5 '16 at 10:51











  • Thanks @percusse, you pointed me in the right direction, and @David hit it on the head! @Christian Unfortunately my expl3-fu is not up to scratch at all. :-/

    – LianTze Lim
    Feb 5 '16 at 13:24











  • @DavidCarlisle Ahem... an answer maybe ?

    – percusse
    Feb 5 '16 at 13:30














  • 2





    Full expansion or once?

    – percusse
    Feb 5 '16 at 10:00






  • 1





    expandafterselectpetexpandafter{mychoice}

    – David Carlisle
    Feb 5 '16 at 10:08











  • Perhaps this is easier with expl3 sequences code instead of patching?

    – user31729
    Feb 5 '16 at 10:51











  • Thanks @percusse, you pointed me in the right direction, and @David hit it on the head! @Christian Unfortunately my expl3-fu is not up to scratch at all. :-/

    – LianTze Lim
    Feb 5 '16 at 13:24











  • @DavidCarlisle Ahem... an answer maybe ?

    – percusse
    Feb 5 '16 at 13:30








2




2





Full expansion or once?

– percusse
Feb 5 '16 at 10:00





Full expansion or once?

– percusse
Feb 5 '16 at 10:00




1




1





expandafterselectpetexpandafter{mychoice}

– David Carlisle
Feb 5 '16 at 10:08





expandafterselectpetexpandafter{mychoice}

– David Carlisle
Feb 5 '16 at 10:08













Perhaps this is easier with expl3 sequences code instead of patching?

– user31729
Feb 5 '16 at 10:51





Perhaps this is easier with expl3 sequences code instead of patching?

– user31729
Feb 5 '16 at 10:51













Thanks @percusse, you pointed me in the right direction, and @David hit it on the head! @Christian Unfortunately my expl3-fu is not up to scratch at all. :-/

– LianTze Lim
Feb 5 '16 at 13:24





Thanks @percusse, you pointed me in the right direction, and @David hit it on the head! @Christian Unfortunately my expl3-fu is not up to scratch at all. :-/

– LianTze Lim
Feb 5 '16 at 13:24













@DavidCarlisle Ahem... an answer maybe ?

– percusse
Feb 5 '16 at 13:30





@DavidCarlisle Ahem... an answer maybe ?

– percusse
Feb 5 '16 at 13:30










1 Answer
1






active

oldest

votes


















7














You want to expand mychoice before calling selectpet so:



expandafterselectpetexpandafter{mychoice}





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/3.0/"u003ecc by-sa 3.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%2f291258%2fusing-expanded-macro-as-search-pattern-for-patchcmd%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7














    You want to expand mychoice before calling selectpet so:



    expandafterselectpetexpandafter{mychoice}





    share|improve this answer




























      7














      You want to expand mychoice before calling selectpet so:



      expandafterselectpetexpandafter{mychoice}





      share|improve this answer


























        7












        7








        7







        You want to expand mychoice before calling selectpet so:



        expandafterselectpetexpandafter{mychoice}





        share|improve this answer













        You want to expand mychoice before calling selectpet so:



        expandafterselectpetexpandafter{mychoice}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 5 '16 at 13:41









        David CarlisleDavid Carlisle

        501k4211471897




        501k4211471897






























            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%2f291258%2fusing-expanded-macro-as-search-pattern-for-patchcmd%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

            El tren de la libertad Índice Antecedentes "Porque yo decido" Desarrollo de la...

            Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...

            Castillo d'Acher Características Menú de navegación