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

What happens in the secondary winding if there's no spark plug connected?

How to denote matrix elements succinctly?

Does tea made with boiling water cool faster than tea made with boiled (but still hot) water?

Why does Mind Blank stop the Feeblemind spell?

Do I have an "anti-research" personality?

Pulling the rope with one hand is as heavy as with two hands?

Aligning equation numbers vertically

Minor Revision with suggestion of an alternative proof by reviewer

What happens to Mjolnir (Thor's hammer) at the end of Endgame?

How to not starve gigantic beasts

Is Diceware more secure than a long passphrase?

What is the philosophical significance of speech acts/implicature?

How can I print the prosodic symbols in LaTeX?

Is it idiomatic to construct against `this`

Overlay of two functions leaves gaps

Check if a string is entirely made of the same substring

Extension of 2-adic valuation to the real numbers

Was there a Viking Exchange as well as a Columbian one?

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

What makes accurate emulation of old systems a difficult task?

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

Can't get 5V 3A DC constant

Dynamic SOQL query relationship with field visibility for Users

How does Captain America channel this power?



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













0















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



























    0















    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

























      0












      0








      0








      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














      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












      share










      share



      share










      asked 6 mins ago









      Faheem MithaFaheem Mitha

      3,33153964




      3,33153964






















          0






          active

          oldest

          votes












          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

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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

          Paper upload error, “Upload failed: The top margin is 0.715 in on page 3, which is below the required...

          Emraan Hashmi Filmografia | Linki zewnętrzne | Menu nawigacyjneGulshan GroverGulshan...

          How can I write this formula?newline and italics added with leqWhy does widehat behave differently if I...