Looping over characters in a string and applying a macro with an additional argumentmacro names with special...

Multiple options vs single option UI

How to prevent z-fighting in OpenSCAD?

Alignment of various blocks in tikz

Is it idiomatic to construct against `this`

On The Origin of Dissonant Chords

Don’t seats that recline flat defeat the purpose of having seatbelts?

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

Coordinate my way to the name of the (video) game

Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?

"You've called the wrong number" or "You called the wrong number"

What term is being referred to with "reflected-sound-of-underground-spirits"?

Is there a way to generate a list of distinct numbers such that no two subsets ever have an equal sum?

How do I reattach a shelf to the wall when it ripped out of the wall?

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

Apply MapThread to all but one variable

How does Captain America channel this power?

How to fry ground beef so it is well-browned

Is the claim "Employers won't employ people with no 'social media presence'" realistic?

Initiative: Do I lose my attack/action if my target moves or dies before my turn in combat?

Two field separators (colon and space) in awk

What does the integral of a function times a function of a random variable represent, conceptually?

A ​Note ​on ​N!

How to not starve gigantic beasts

How to limit Drive Letters Windows assigns to new removable USB drives



Looping over characters in a string and applying a macro with an additional argument


macro names with special charactersRenewdefine section with additional argumentProblem with addition and macro argumentWrite a macro with command, {, and } in argumentConcatenate macro with stringUsing macro with optional argument inside macro with optional argumentHow to repeat over all characters in a string?Concatenate macro, string and counterConcatenate string and `today` macroExpandable, global definition with an argument inside a macro in L3













2















The following code was kindly provided for me in TeX Chat by @egreg.



This LaTeX 3 code loops over a list of characters, and puts a box around each character. It does not skip whitespace



documentclass[12pt]{article}
usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{spacechars}{m}
{
tl_set:Nn l_tmpa_tl { #1 }
tl_replace_all:Nnn l_tmpa_tl { ~ } { c_space_tl }
tl_map_function:NN l_tmpa_tl boxedchar
}
ExplSyntaxOff

NewDocumentCommand{boxedchar}{m}{%
framebox[2em]{strut#1}%
}

begin{document}

spacechars{ab c d}

end{document}


I'd like an enhancement of this code, with a variation of spacechars which allows one to include a width argument that can then be passed to framebox.



But it does not look like tl_map_function will do the job, unless there is some way to pass it a macro which is a version of boxedchar where the width argument has been applied (i.e. as in partial function application).



I looked at the functions in the LaTeX 3 interface document, (which is
/usr/share/texlive/texmf-dist/doc/latex/l3kernel/interface3.pdf on my system), but didn't see anything that looked like it fit the bill.










share|improve this question



























    2















    The following code was kindly provided for me in TeX Chat by @egreg.



    This LaTeX 3 code loops over a list of characters, and puts a box around each character. It does not skip whitespace



    documentclass[12pt]{article}
    usepackage{xparse}

    ExplSyntaxOn
    NewDocumentCommand{spacechars}{m}
    {
    tl_set:Nn l_tmpa_tl { #1 }
    tl_replace_all:Nnn l_tmpa_tl { ~ } { c_space_tl }
    tl_map_function:NN l_tmpa_tl boxedchar
    }
    ExplSyntaxOff

    NewDocumentCommand{boxedchar}{m}{%
    framebox[2em]{strut#1}%
    }

    begin{document}

    spacechars{ab c d}

    end{document}


    I'd like an enhancement of this code, with a variation of spacechars which allows one to include a width argument that can then be passed to framebox.



    But it does not look like tl_map_function will do the job, unless there is some way to pass it a macro which is a version of boxedchar where the width argument has been applied (i.e. as in partial function application).



    I looked at the functions in the LaTeX 3 interface document, (which is
    /usr/share/texlive/texmf-dist/doc/latex/l3kernel/interface3.pdf on my system), but didn't see anything that looked like it fit the bill.










    share|improve this question

























      2












      2








      2








      The following code was kindly provided for me in TeX Chat by @egreg.



      This LaTeX 3 code loops over a list of characters, and puts a box around each character. It does not skip whitespace



      documentclass[12pt]{article}
      usepackage{xparse}

      ExplSyntaxOn
      NewDocumentCommand{spacechars}{m}
      {
      tl_set:Nn l_tmpa_tl { #1 }
      tl_replace_all:Nnn l_tmpa_tl { ~ } { c_space_tl }
      tl_map_function:NN l_tmpa_tl boxedchar
      }
      ExplSyntaxOff

      NewDocumentCommand{boxedchar}{m}{%
      framebox[2em]{strut#1}%
      }

      begin{document}

      spacechars{ab c d}

      end{document}


      I'd like an enhancement of this code, with a variation of spacechars which allows one to include a width argument that can then be passed to framebox.



      But it does not look like tl_map_function will do the job, unless there is some way to pass it a macro which is a version of boxedchar where the width argument has been applied (i.e. as in partial function application).



      I looked at the functions in the LaTeX 3 interface document, (which is
      /usr/share/texlive/texmf-dist/doc/latex/l3kernel/interface3.pdf on my system), but didn't see anything that looked like it fit the bill.










      share|improve this question














      The following code was kindly provided for me in TeX Chat by @egreg.



      This LaTeX 3 code loops over a list of characters, and puts a box around each character. It does not skip whitespace



      documentclass[12pt]{article}
      usepackage{xparse}

      ExplSyntaxOn
      NewDocumentCommand{spacechars}{m}
      {
      tl_set:Nn l_tmpa_tl { #1 }
      tl_replace_all:Nnn l_tmpa_tl { ~ } { c_space_tl }
      tl_map_function:NN l_tmpa_tl boxedchar
      }
      ExplSyntaxOff

      NewDocumentCommand{boxedchar}{m}{%
      framebox[2em]{strut#1}%
      }

      begin{document}

      spacechars{ab c d}

      end{document}


      I'd like an enhancement of this code, with a variation of spacechars which allows one to include a width argument that can then be passed to framebox.



      But it does not look like tl_map_function will do the job, unless there is some way to pass it a macro which is a version of boxedchar where the width argument has been applied (i.e. as in partial function application).



      I looked at the functions in the LaTeX 3 interface document, (which is
      /usr/share/texlive/texmf-dist/doc/latex/l3kernel/interface3.pdf on my system), but didn't see anything that looked like it fit the bill.







      macros latex3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Faheem MithaFaheem Mitha

      3,34153964




      3,34153964






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You can do it easily. ;-)



          documentclass[12pt]{article}
          usepackage{xparse}

          ExplSyntaxOn
          NewDocumentCommand{spacechars}{O{1em}m}
          {
          faheem_spacechars:nn { #1 } { #2 }
          }

          NewDocumentCommand{boxedchar}{O{1em}m}
          {
          faheem_spacechars_box:nn { #1 } { #2 }
          }

          tl_new:N l__faheem_spacechars_tl
          tl_new:N l__faheem_spacechars_char_tl

          cs_new_protected:Nn faheem_spacechars:nn
          {
          tl_set:Nn l__faheem_spacechars_tl { #2 }
          tl_replace_all:Nnn l__faheem_spacechars_tl { ~ } { c_space_tl }
          tl_map_variable:NNn l__faheem_spacechars_tl l__faheem_spacechars_char_tl
          { faheem_spacechars_box:nV { #1 } l__faheem_spacechars_char_tl }
          }

          cs_new_protected:Nn faheem_spacechars_box:nn
          {
          framebox[#1]{strut #2}
          }
          cs_generate_variant:Nn faheem_spacechars_box:nn { nV }

          ExplSyntaxOff

          begin{document}

          spacechars{ab c d}

          spacechars[2em]{ab c d}

          end{document}


          The trick is tl_map_variable:NNn.



          enter image description here






          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%2f487846%2flooping-over-characters-in-a-string-and-applying-a-macro-with-an-additional-argu%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









            1














            You can do it easily. ;-)



            documentclass[12pt]{article}
            usepackage{xparse}

            ExplSyntaxOn
            NewDocumentCommand{spacechars}{O{1em}m}
            {
            faheem_spacechars:nn { #1 } { #2 }
            }

            NewDocumentCommand{boxedchar}{O{1em}m}
            {
            faheem_spacechars_box:nn { #1 } { #2 }
            }

            tl_new:N l__faheem_spacechars_tl
            tl_new:N l__faheem_spacechars_char_tl

            cs_new_protected:Nn faheem_spacechars:nn
            {
            tl_set:Nn l__faheem_spacechars_tl { #2 }
            tl_replace_all:Nnn l__faheem_spacechars_tl { ~ } { c_space_tl }
            tl_map_variable:NNn l__faheem_spacechars_tl l__faheem_spacechars_char_tl
            { faheem_spacechars_box:nV { #1 } l__faheem_spacechars_char_tl }
            }

            cs_new_protected:Nn faheem_spacechars_box:nn
            {
            framebox[#1]{strut #2}
            }
            cs_generate_variant:Nn faheem_spacechars_box:nn { nV }

            ExplSyntaxOff

            begin{document}

            spacechars{ab c d}

            spacechars[2em]{ab c d}

            end{document}


            The trick is tl_map_variable:NNn.



            enter image description here






            share|improve this answer




























              1














              You can do it easily. ;-)



              documentclass[12pt]{article}
              usepackage{xparse}

              ExplSyntaxOn
              NewDocumentCommand{spacechars}{O{1em}m}
              {
              faheem_spacechars:nn { #1 } { #2 }
              }

              NewDocumentCommand{boxedchar}{O{1em}m}
              {
              faheem_spacechars_box:nn { #1 } { #2 }
              }

              tl_new:N l__faheem_spacechars_tl
              tl_new:N l__faheem_spacechars_char_tl

              cs_new_protected:Nn faheem_spacechars:nn
              {
              tl_set:Nn l__faheem_spacechars_tl { #2 }
              tl_replace_all:Nnn l__faheem_spacechars_tl { ~ } { c_space_tl }
              tl_map_variable:NNn l__faheem_spacechars_tl l__faheem_spacechars_char_tl
              { faheem_spacechars_box:nV { #1 } l__faheem_spacechars_char_tl }
              }

              cs_new_protected:Nn faheem_spacechars_box:nn
              {
              framebox[#1]{strut #2}
              }
              cs_generate_variant:Nn faheem_spacechars_box:nn { nV }

              ExplSyntaxOff

              begin{document}

              spacechars{ab c d}

              spacechars[2em]{ab c d}

              end{document}


              The trick is tl_map_variable:NNn.



              enter image description here






              share|improve this answer


























                1












                1








                1







                You can do it easily. ;-)



                documentclass[12pt]{article}
                usepackage{xparse}

                ExplSyntaxOn
                NewDocumentCommand{spacechars}{O{1em}m}
                {
                faheem_spacechars:nn { #1 } { #2 }
                }

                NewDocumentCommand{boxedchar}{O{1em}m}
                {
                faheem_spacechars_box:nn { #1 } { #2 }
                }

                tl_new:N l__faheem_spacechars_tl
                tl_new:N l__faheem_spacechars_char_tl

                cs_new_protected:Nn faheem_spacechars:nn
                {
                tl_set:Nn l__faheem_spacechars_tl { #2 }
                tl_replace_all:Nnn l__faheem_spacechars_tl { ~ } { c_space_tl }
                tl_map_variable:NNn l__faheem_spacechars_tl l__faheem_spacechars_char_tl
                { faheem_spacechars_box:nV { #1 } l__faheem_spacechars_char_tl }
                }

                cs_new_protected:Nn faheem_spacechars_box:nn
                {
                framebox[#1]{strut #2}
                }
                cs_generate_variant:Nn faheem_spacechars_box:nn { nV }

                ExplSyntaxOff

                begin{document}

                spacechars{ab c d}

                spacechars[2em]{ab c d}

                end{document}


                The trick is tl_map_variable:NNn.



                enter image description here






                share|improve this answer













                You can do it easily. ;-)



                documentclass[12pt]{article}
                usepackage{xparse}

                ExplSyntaxOn
                NewDocumentCommand{spacechars}{O{1em}m}
                {
                faheem_spacechars:nn { #1 } { #2 }
                }

                NewDocumentCommand{boxedchar}{O{1em}m}
                {
                faheem_spacechars_box:nn { #1 } { #2 }
                }

                tl_new:N l__faheem_spacechars_tl
                tl_new:N l__faheem_spacechars_char_tl

                cs_new_protected:Nn faheem_spacechars:nn
                {
                tl_set:Nn l__faheem_spacechars_tl { #2 }
                tl_replace_all:Nnn l__faheem_spacechars_tl { ~ } { c_space_tl }
                tl_map_variable:NNn l__faheem_spacechars_tl l__faheem_spacechars_char_tl
                { faheem_spacechars_box:nV { #1 } l__faheem_spacechars_char_tl }
                }

                cs_new_protected:Nn faheem_spacechars_box:nn
                {
                framebox[#1]{strut #2}
                }
                cs_generate_variant:Nn faheem_spacechars_box:nn { nV }

                ExplSyntaxOff

                begin{document}

                spacechars{ab c d}

                spacechars[2em]{ab c d}

                end{document}


                The trick is tl_map_variable:NNn.



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 58 mins ago









                egregegreg

                737k8919373265




                737k8919373265






























                    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%2f487846%2flooping-over-characters-in-a-string-and-applying-a-macro-with-an-additional-argu%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