Replacing function, how to use + as delimiter












4














I am using a function for summing numbers like in paper and my input at arguments is like this:
showsum{123+456}



I need to replace the custom function with other from package xlop - opadd.
I want the same function name but there are 2 separated arguments in opadd and I want to use {123+456} for opadd arguments. How to make this delimiter?



documentclass{article}
usepackage{xlop}
usepackage{amsmath}
usepackage{setspace}
newcommand{showsum}[2][c]{%
$edeforiginalplusmathcode{themathcode`+}%
begingrouplccode`~=`+ lowercase{endgroupdef~}{\mathcharoriginalplusmathcode&}%
edeforiginalminusmathcode{themathcode`-}%
begingrouplccode`~=`- lowercase{endgroupdef~}{\mathcharoriginalminusmathcode&}%
mathcode`+ "8000
mathcode`- "8000
begin{array}[#1]{@{}r@{;}r@{}}
& #2 \
hline
& thenumexpr#2relax
end{array}%
$%
}

begin{document}
Original function(don't need anymore)showsum{123+456}
\
\
Replacement needed opadd{123}{456}

end{document}









share|improve this question



























    4














    I am using a function for summing numbers like in paper and my input at arguments is like this:
    showsum{123+456}



    I need to replace the custom function with other from package xlop - opadd.
    I want the same function name but there are 2 separated arguments in opadd and I want to use {123+456} for opadd arguments. How to make this delimiter?



    documentclass{article}
    usepackage{xlop}
    usepackage{amsmath}
    usepackage{setspace}
    newcommand{showsum}[2][c]{%
    $edeforiginalplusmathcode{themathcode`+}%
    begingrouplccode`~=`+ lowercase{endgroupdef~}{\mathcharoriginalplusmathcode&}%
    edeforiginalminusmathcode{themathcode`-}%
    begingrouplccode`~=`- lowercase{endgroupdef~}{\mathcharoriginalminusmathcode&}%
    mathcode`+ "8000
    mathcode`- "8000
    begin{array}[#1]{@{}r@{;}r@{}}
    & #2 \
    hline
    & thenumexpr#2relax
    end{array}%
    $%
    }

    begin{document}
    Original function(don't need anymore)showsum{123+456}
    \
    \
    Replacement needed opadd{123}{456}

    end{document}









    share|improve this question

























      4












      4








      4







      I am using a function for summing numbers like in paper and my input at arguments is like this:
      showsum{123+456}



      I need to replace the custom function with other from package xlop - opadd.
      I want the same function name but there are 2 separated arguments in opadd and I want to use {123+456} for opadd arguments. How to make this delimiter?



      documentclass{article}
      usepackage{xlop}
      usepackage{amsmath}
      usepackage{setspace}
      newcommand{showsum}[2][c]{%
      $edeforiginalplusmathcode{themathcode`+}%
      begingrouplccode`~=`+ lowercase{endgroupdef~}{\mathcharoriginalplusmathcode&}%
      edeforiginalminusmathcode{themathcode`-}%
      begingrouplccode`~=`- lowercase{endgroupdef~}{\mathcharoriginalminusmathcode&}%
      mathcode`+ "8000
      mathcode`- "8000
      begin{array}[#1]{@{}r@{;}r@{}}
      & #2 \
      hline
      & thenumexpr#2relax
      end{array}%
      $%
      }

      begin{document}
      Original function(don't need anymore)showsum{123+456}
      \
      \
      Replacement needed opadd{123}{456}

      end{document}









      share|improve this question













      I am using a function for summing numbers like in paper and my input at arguments is like this:
      showsum{123+456}



      I need to replace the custom function with other from package xlop - opadd.
      I want the same function name but there are 2 separated arguments in opadd and I want to use {123+456} for opadd arguments. How to make this delimiter?



      documentclass{article}
      usepackage{xlop}
      usepackage{amsmath}
      usepackage{setspace}
      newcommand{showsum}[2][c]{%
      $edeforiginalplusmathcode{themathcode`+}%
      begingrouplccode`~=`+ lowercase{endgroupdef~}{\mathcharoriginalplusmathcode&}%
      edeforiginalminusmathcode{themathcode`-}%
      begingrouplccode`~=`- lowercase{endgroupdef~}{\mathcharoriginalminusmathcode&}%
      mathcode`+ "8000
      mathcode`- "8000
      begin{array}[#1]{@{}r@{;}r@{}}
      & #2 \
      hline
      & thenumexpr#2relax
      end{array}%
      $%
      }

      begin{document}
      Original function(don't need anymore)showsum{123+456}
      \
      \
      Replacement needed opadd{123}{456}

      end{document}






      delimiters






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Simeon SimeonovSimeon Simeonov

      3306




      3306






















          1 Answer
          1






          active

          oldest

          votes


















          7














          You can use a macro with delimited arguments:



          documentclass{article}
          usepackage{xlop}

          newcommand{showsum}[1]{doshowsum#1doshowsum}
          defdoshowsum#1+#2doshowsum{opadd{#1}{#2}}

          begin{document}

          showsum{123+456} qquad opadd{123}{456}

          end{document}


          enter image description here



          You can also support subtraction:



          documentclass{article}
          usepackage{xparse}
          usepackage{xlop}

          ExplSyntaxOn
          NewDocumentCommand{showsum}{m}
          {
          regex_match:nnTF { + } { #1 }
          {
          simeon_showsum:nnn { #1 } { + } { opadd }
          }
          {
          simeon_showsum:nnn { #1 } { - } { opsub }
          }
          }
          cs_new_protected:Nn simeon_showsum:nnn
          {
          tl_set:Nn l_tmpa_tl { #1 }
          % remove all spaces
          regex_replace_all:nnN { s } { } l_tmpa_tl
          % replace <number>+<number> with opadd{<number>}{<number>} or
          % replace <number>-<number> with opsub{<number>}{<number>}
          regex_replace_once:nnN
          { A ([^#2]*) #2 (.*) Z }
          { c{#3}cB{1cE}cB{2cE} }
          l_tmpa_tl
          % deliver the result
          tl_use:N l_tmpa_tl
          }
          ExplSyntaxOff

          begin{document}

          showsum{123+456} qquad showsum{456-123}

          end{document}


          enter image description here






          share|improve this answer























          • Great! I needed subtraction aswell. I have new problem. My functions are showsum{123 + 456} with spaces between +/- and numbers. Is there any fast solution?
            – Simeon Simeonov
            2 days ago






          • 1




            @SimeonSimeonov I added removal of spaces
            – egreg
            2 days ago











          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%2f468819%2freplacing-function-how-to-use-as-delimiter%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 can use a macro with delimited arguments:



          documentclass{article}
          usepackage{xlop}

          newcommand{showsum}[1]{doshowsum#1doshowsum}
          defdoshowsum#1+#2doshowsum{opadd{#1}{#2}}

          begin{document}

          showsum{123+456} qquad opadd{123}{456}

          end{document}


          enter image description here



          You can also support subtraction:



          documentclass{article}
          usepackage{xparse}
          usepackage{xlop}

          ExplSyntaxOn
          NewDocumentCommand{showsum}{m}
          {
          regex_match:nnTF { + } { #1 }
          {
          simeon_showsum:nnn { #1 } { + } { opadd }
          }
          {
          simeon_showsum:nnn { #1 } { - } { opsub }
          }
          }
          cs_new_protected:Nn simeon_showsum:nnn
          {
          tl_set:Nn l_tmpa_tl { #1 }
          % remove all spaces
          regex_replace_all:nnN { s } { } l_tmpa_tl
          % replace <number>+<number> with opadd{<number>}{<number>} or
          % replace <number>-<number> with opsub{<number>}{<number>}
          regex_replace_once:nnN
          { A ([^#2]*) #2 (.*) Z }
          { c{#3}cB{1cE}cB{2cE} }
          l_tmpa_tl
          % deliver the result
          tl_use:N l_tmpa_tl
          }
          ExplSyntaxOff

          begin{document}

          showsum{123+456} qquad showsum{456-123}

          end{document}


          enter image description here






          share|improve this answer























          • Great! I needed subtraction aswell. I have new problem. My functions are showsum{123 + 456} with spaces between +/- and numbers. Is there any fast solution?
            – Simeon Simeonov
            2 days ago






          • 1




            @SimeonSimeonov I added removal of spaces
            – egreg
            2 days ago
















          7














          You can use a macro with delimited arguments:



          documentclass{article}
          usepackage{xlop}

          newcommand{showsum}[1]{doshowsum#1doshowsum}
          defdoshowsum#1+#2doshowsum{opadd{#1}{#2}}

          begin{document}

          showsum{123+456} qquad opadd{123}{456}

          end{document}


          enter image description here



          You can also support subtraction:



          documentclass{article}
          usepackage{xparse}
          usepackage{xlop}

          ExplSyntaxOn
          NewDocumentCommand{showsum}{m}
          {
          regex_match:nnTF { + } { #1 }
          {
          simeon_showsum:nnn { #1 } { + } { opadd }
          }
          {
          simeon_showsum:nnn { #1 } { - } { opsub }
          }
          }
          cs_new_protected:Nn simeon_showsum:nnn
          {
          tl_set:Nn l_tmpa_tl { #1 }
          % remove all spaces
          regex_replace_all:nnN { s } { } l_tmpa_tl
          % replace <number>+<number> with opadd{<number>}{<number>} or
          % replace <number>-<number> with opsub{<number>}{<number>}
          regex_replace_once:nnN
          { A ([^#2]*) #2 (.*) Z }
          { c{#3}cB{1cE}cB{2cE} }
          l_tmpa_tl
          % deliver the result
          tl_use:N l_tmpa_tl
          }
          ExplSyntaxOff

          begin{document}

          showsum{123+456} qquad showsum{456-123}

          end{document}


          enter image description here






          share|improve this answer























          • Great! I needed subtraction aswell. I have new problem. My functions are showsum{123 + 456} with spaces between +/- and numbers. Is there any fast solution?
            – Simeon Simeonov
            2 days ago






          • 1




            @SimeonSimeonov I added removal of spaces
            – egreg
            2 days ago














          7












          7








          7






          You can use a macro with delimited arguments:



          documentclass{article}
          usepackage{xlop}

          newcommand{showsum}[1]{doshowsum#1doshowsum}
          defdoshowsum#1+#2doshowsum{opadd{#1}{#2}}

          begin{document}

          showsum{123+456} qquad opadd{123}{456}

          end{document}


          enter image description here



          You can also support subtraction:



          documentclass{article}
          usepackage{xparse}
          usepackage{xlop}

          ExplSyntaxOn
          NewDocumentCommand{showsum}{m}
          {
          regex_match:nnTF { + } { #1 }
          {
          simeon_showsum:nnn { #1 } { + } { opadd }
          }
          {
          simeon_showsum:nnn { #1 } { - } { opsub }
          }
          }
          cs_new_protected:Nn simeon_showsum:nnn
          {
          tl_set:Nn l_tmpa_tl { #1 }
          % remove all spaces
          regex_replace_all:nnN { s } { } l_tmpa_tl
          % replace <number>+<number> with opadd{<number>}{<number>} or
          % replace <number>-<number> with opsub{<number>}{<number>}
          regex_replace_once:nnN
          { A ([^#2]*) #2 (.*) Z }
          { c{#3}cB{1cE}cB{2cE} }
          l_tmpa_tl
          % deliver the result
          tl_use:N l_tmpa_tl
          }
          ExplSyntaxOff

          begin{document}

          showsum{123+456} qquad showsum{456-123}

          end{document}


          enter image description here






          share|improve this answer














          You can use a macro with delimited arguments:



          documentclass{article}
          usepackage{xlop}

          newcommand{showsum}[1]{doshowsum#1doshowsum}
          defdoshowsum#1+#2doshowsum{opadd{#1}{#2}}

          begin{document}

          showsum{123+456} qquad opadd{123}{456}

          end{document}


          enter image description here



          You can also support subtraction:



          documentclass{article}
          usepackage{xparse}
          usepackage{xlop}

          ExplSyntaxOn
          NewDocumentCommand{showsum}{m}
          {
          regex_match:nnTF { + } { #1 }
          {
          simeon_showsum:nnn { #1 } { + } { opadd }
          }
          {
          simeon_showsum:nnn { #1 } { - } { opsub }
          }
          }
          cs_new_protected:Nn simeon_showsum:nnn
          {
          tl_set:Nn l_tmpa_tl { #1 }
          % remove all spaces
          regex_replace_all:nnN { s } { } l_tmpa_tl
          % replace <number>+<number> with opadd{<number>}{<number>} or
          % replace <number>-<number> with opsub{<number>}{<number>}
          regex_replace_once:nnN
          { A ([^#2]*) #2 (.*) Z }
          { c{#3}cB{1cE}cB{2cE} }
          l_tmpa_tl
          % deliver the result
          tl_use:N l_tmpa_tl
          }
          ExplSyntaxOff

          begin{document}

          showsum{123+456} qquad showsum{456-123}

          end{document}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          egregegreg

          710k8618893173




          710k8618893173












          • Great! I needed subtraction aswell. I have new problem. My functions are showsum{123 + 456} with spaces between +/- and numbers. Is there any fast solution?
            – Simeon Simeonov
            2 days ago






          • 1




            @SimeonSimeonov I added removal of spaces
            – egreg
            2 days ago


















          • Great! I needed subtraction aswell. I have new problem. My functions are showsum{123 + 456} with spaces between +/- and numbers. Is there any fast solution?
            – Simeon Simeonov
            2 days ago






          • 1




            @SimeonSimeonov I added removal of spaces
            – egreg
            2 days ago
















          Great! I needed subtraction aswell. I have new problem. My functions are showsum{123 + 456} with spaces between +/- and numbers. Is there any fast solution?
          – Simeon Simeonov
          2 days ago




          Great! I needed subtraction aswell. I have new problem. My functions are showsum{123 + 456} with spaces between +/- and numbers. Is there any fast solution?
          – Simeon Simeonov
          2 days ago




          1




          1




          @SimeonSimeonov I added removal of spaces
          – egreg
          2 days ago




          @SimeonSimeonov I added removal of spaces
          – egreg
          2 days ago


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f468819%2freplacing-function-how-to-use-as-delimiter%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

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар