New command Long division help











up vote
2
down vote

favorite












I posted before this thread.



I'm trying to automate this process - long division by Bulgarian(and many other countries) method. The desired one is the left, the right is from longdiv package.
Here is the comparison.
enter image description here



I have tried xlop, longdiv(on the pic) but there is not package for the left equation which I need. I tried to edit longdiv.tex but i got some errors and I dont have good understanding of Latex. I hope someone will make function for that(I don't need fractions). Many people may need it.
The from the pic is there.










share|improve this question









New contributor




Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    2
    down vote

    favorite












    I posted before this thread.



    I'm trying to automate this process - long division by Bulgarian(and many other countries) method. The desired one is the left, the right is from longdiv package.
    Here is the comparison.
    enter image description here



    I have tried xlop, longdiv(on the pic) but there is not package for the left equation which I need. I tried to edit longdiv.tex but i got some errors and I dont have good understanding of Latex. I hope someone will make function for that(I don't need fractions). Many people may need it.
    The from the pic is there.










    share|improve this question









    New contributor




    Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I posted before this thread.



      I'm trying to automate this process - long division by Bulgarian(and many other countries) method. The desired one is the left, the right is from longdiv package.
      Here is the comparison.
      enter image description here



      I have tried xlop, longdiv(on the pic) but there is not package for the left equation which I need. I tried to edit longdiv.tex but i got some errors and I dont have good understanding of Latex. I hope someone will make function for that(I don't need fractions). Many people may need it.
      The from the pic is there.










      share|improve this question









      New contributor




      Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I posted before this thread.



      I'm trying to automate this process - long division by Bulgarian(and many other countries) method. The desired one is the left, the right is from longdiv package.
      Here is the comparison.
      enter image description here



      I have tried xlop, longdiv(on the pic) but there is not package for the left equation which I need. I tried to edit longdiv.tex but i got some errors and I dont have good understanding of Latex. I hope someone will make function for that(I don't need fractions). Many people may need it.
      The from the pic is there.







      math-mode






      share|improve this question









      New contributor




      Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 18 at 17:24









      David Carlisle

      477k3811061841




      477k3811061841






      New contributor




      Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 18 at 14:06









      Simeon Simeonov

      714




      714




      New contributor




      Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Simeon Simeonov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          The following does produce the output you want. The minus signs in the output are not contributing to the overall size of the output, so they might stick into the margin. As you said you don't need fractions, the following doesn't cover that. It is only working for integer division and always truncates the result. Some portions of the horizontal rules might get drawn twice, that can lead to rendering issues in some PDF viewers, but if you zoom in those should be gone and the print should look fine.



          documentclass{article}

          usepackage{xparse,expl3}
          usepackage{mathtools}
          ExplSyntaxOn
          int_new:N l_Simeon_divisor_int
          int_new:N l_Simeon_tmpa_int
          int_new:N l_Simeon_next_dividend_int
          int_new:N l_Simeon_pops_int
          seq_new:N l_Simeon_dividend_seq
          seq_new:N l_Simeon_under_seq
          bool_new:N l_Simeon_first_bool
          tl_new:N l_Simeon_tmpa_tl
          msg_new:nnn { Simeon } { empty~arg }%>>>
          {
          It ~ seems ~ like ~ you ~ provided ~ an ~ empty ~ arg ~ for ~ the ~ #1, ~
          this ~ is ~ not ~ allowed.
          }%<<<
          cs_new:Npn Simeon_shift_aux:n #1%>>>
          {
          exp_not:n { phantom { 0 } }
          }%<<<
          cs_new:Npn Simeon_shift:%>>>
          {
          int_step_function:nN { l_Simeon_pops_int } Simeon_shift_aux:n
          }%<<<
          cs_new_protected:Npn Simeon_array:n #1%>>>
          {
          mathllap { begin { array } { @{} r @{} } #1 end { array } }
          }%<<<
          cs_new_protected:Npn Simeon_add_to_under:n #1%>>>
          {
          seq_put_right:Nx l_Simeon_under_seq
          {
          Simeon_shift:
          Simeon_array:n { #1 }
          }
          }%<<<
          cs_new_protected:Npn Simeon_pop_and_calc:nn #1 #2%>>>
          {
          seq_pop_left:NN l_Simeon_dividend_seq l_Simeon_tmpa_tl
          int_incr:N l_Simeon_pops_int
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int * 10 + l_Simeon_tmpa_tl }
          int_set:Nn l_Simeon_tmpa_int
          {
          fp_eval:n
          { trunc ( l_Simeon_next_dividend_int / l_Simeon_divisor_int ) }
          }
          int_compare:nNnF l_Simeon_tmpa_int = c_zero_int
          {
          #1
          int_set:Nn l_Simeon_tmpa_int
          { l_Simeon_tmpa_int * l_Simeon_divisor_int }
          Simeon_add_to_under:n { #2 }
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int - l_Simeon_tmpa_int }
          }
          }%<<<
          cs_new:Npn Simeon_continue_hline:%>>>
          {
          noalign { vskip -arrayrulewidth }
          hline
          }%<<<
          NewDocumentCommand longintdiv { m m }%>>>
          {
          % initializing variables >>>
          tl_if_blank:nT { #1 }
          { msg_error:nnn { Simeon } { empty~arg } { dividend } }
          tl_if_blank:nT { #2 }
          { msg_error:nnn { Simeon } { empty~arg } { divisor } }
          seq_set_split:Nnn l_Simeon_dividend_seq {} { #1 }
          seq_clear:N l_Simeon_under_seq
          int_set:Nn l_Simeon_divisor_int { #2 }
          int_zero:N l_Simeon_next_dividend_int
          int_zero:N l_Simeon_pops_int
          bool_set_true:N l_Simeon_first_bool
          % <<<
          % first division >>>
          bool_do_while:nn
          { l_Simeon_first_bool && !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn { bool_set_false:N l_Simeon_first_bool }
          {
          exp_not:N mathllap { {} - {} }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % other divisions >>>
          bool_while_do:nn { !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn {}
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          exp_not:n { \ mathllap { {} - {} } }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % rest >>>
          Simeon_add_to_under:n
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          }
          % <<<
          % output >>>
          $
          begin { array } [ t ] { @{} l @{} }
          #1 mathbin{:} #2 = int_eval:n { fp_eval:n { trunc ( #1 / #2 ) } }\
          seq_use:Nn l_Simeon_under_seq { \ }
          end { array }
          $
          % <<<
          }%<<<
          ExplSyntaxOff

          begin{document}
          longintdiv{1011}{11}
          qquad
          longintdiv{3516}{5}
          qquad
          longintdiv{5}{5}
          qquad
          longintdiv{4}{5}
          end{document}


          enter image description here






          share|improve this answer























          • That's really good! Thank you! Is it possible to make them all on one line?
            – Simeon Simeonov
            Nov 18 at 17:46






          • 1




            @SimeonSimeonov I've cleaned up the code a bit (ignore the %>>> thingies, those are just for me and my VIM). I've also changed the output to be in one line.
            – Skillmon
            Nov 18 at 18:13










          • REALLY good! Thank you! You saved me hours and many nerves! Great!
            – Simeon Simeonov
            Nov 18 at 18:19










          • @SimeonSimeonov can you give me the numbers which produce that?
            – Skillmon
            Nov 18 at 18:33










          • Ahhh sorry. It's working without problems. I had just begin{spacing}{1.5}. I will close this construction when I am working with it. It was obvious.
            – Simeon Simeonov
            Nov 18 at 18:41











          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: 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
          });


          }
          });






          Simeon Simeonov is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460598%2fnew-command-long-division-help%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








          up vote
          2
          down vote



          accepted










          The following does produce the output you want. The minus signs in the output are not contributing to the overall size of the output, so they might stick into the margin. As you said you don't need fractions, the following doesn't cover that. It is only working for integer division and always truncates the result. Some portions of the horizontal rules might get drawn twice, that can lead to rendering issues in some PDF viewers, but if you zoom in those should be gone and the print should look fine.



          documentclass{article}

          usepackage{xparse,expl3}
          usepackage{mathtools}
          ExplSyntaxOn
          int_new:N l_Simeon_divisor_int
          int_new:N l_Simeon_tmpa_int
          int_new:N l_Simeon_next_dividend_int
          int_new:N l_Simeon_pops_int
          seq_new:N l_Simeon_dividend_seq
          seq_new:N l_Simeon_under_seq
          bool_new:N l_Simeon_first_bool
          tl_new:N l_Simeon_tmpa_tl
          msg_new:nnn { Simeon } { empty~arg }%>>>
          {
          It ~ seems ~ like ~ you ~ provided ~ an ~ empty ~ arg ~ for ~ the ~ #1, ~
          this ~ is ~ not ~ allowed.
          }%<<<
          cs_new:Npn Simeon_shift_aux:n #1%>>>
          {
          exp_not:n { phantom { 0 } }
          }%<<<
          cs_new:Npn Simeon_shift:%>>>
          {
          int_step_function:nN { l_Simeon_pops_int } Simeon_shift_aux:n
          }%<<<
          cs_new_protected:Npn Simeon_array:n #1%>>>
          {
          mathllap { begin { array } { @{} r @{} } #1 end { array } }
          }%<<<
          cs_new_protected:Npn Simeon_add_to_under:n #1%>>>
          {
          seq_put_right:Nx l_Simeon_under_seq
          {
          Simeon_shift:
          Simeon_array:n { #1 }
          }
          }%<<<
          cs_new_protected:Npn Simeon_pop_and_calc:nn #1 #2%>>>
          {
          seq_pop_left:NN l_Simeon_dividend_seq l_Simeon_tmpa_tl
          int_incr:N l_Simeon_pops_int
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int * 10 + l_Simeon_tmpa_tl }
          int_set:Nn l_Simeon_tmpa_int
          {
          fp_eval:n
          { trunc ( l_Simeon_next_dividend_int / l_Simeon_divisor_int ) }
          }
          int_compare:nNnF l_Simeon_tmpa_int = c_zero_int
          {
          #1
          int_set:Nn l_Simeon_tmpa_int
          { l_Simeon_tmpa_int * l_Simeon_divisor_int }
          Simeon_add_to_under:n { #2 }
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int - l_Simeon_tmpa_int }
          }
          }%<<<
          cs_new:Npn Simeon_continue_hline:%>>>
          {
          noalign { vskip -arrayrulewidth }
          hline
          }%<<<
          NewDocumentCommand longintdiv { m m }%>>>
          {
          % initializing variables >>>
          tl_if_blank:nT { #1 }
          { msg_error:nnn { Simeon } { empty~arg } { dividend } }
          tl_if_blank:nT { #2 }
          { msg_error:nnn { Simeon } { empty~arg } { divisor } }
          seq_set_split:Nnn l_Simeon_dividend_seq {} { #1 }
          seq_clear:N l_Simeon_under_seq
          int_set:Nn l_Simeon_divisor_int { #2 }
          int_zero:N l_Simeon_next_dividend_int
          int_zero:N l_Simeon_pops_int
          bool_set_true:N l_Simeon_first_bool
          % <<<
          % first division >>>
          bool_do_while:nn
          { l_Simeon_first_bool && !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn { bool_set_false:N l_Simeon_first_bool }
          {
          exp_not:N mathllap { {} - {} }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % other divisions >>>
          bool_while_do:nn { !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn {}
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          exp_not:n { \ mathllap { {} - {} } }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % rest >>>
          Simeon_add_to_under:n
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          }
          % <<<
          % output >>>
          $
          begin { array } [ t ] { @{} l @{} }
          #1 mathbin{:} #2 = int_eval:n { fp_eval:n { trunc ( #1 / #2 ) } }\
          seq_use:Nn l_Simeon_under_seq { \ }
          end { array }
          $
          % <<<
          }%<<<
          ExplSyntaxOff

          begin{document}
          longintdiv{1011}{11}
          qquad
          longintdiv{3516}{5}
          qquad
          longintdiv{5}{5}
          qquad
          longintdiv{4}{5}
          end{document}


          enter image description here






          share|improve this answer























          • That's really good! Thank you! Is it possible to make them all on one line?
            – Simeon Simeonov
            Nov 18 at 17:46






          • 1




            @SimeonSimeonov I've cleaned up the code a bit (ignore the %>>> thingies, those are just for me and my VIM). I've also changed the output to be in one line.
            – Skillmon
            Nov 18 at 18:13










          • REALLY good! Thank you! You saved me hours and many nerves! Great!
            – Simeon Simeonov
            Nov 18 at 18:19










          • @SimeonSimeonov can you give me the numbers which produce that?
            – Skillmon
            Nov 18 at 18:33










          • Ahhh sorry. It's working without problems. I had just begin{spacing}{1.5}. I will close this construction when I am working with it. It was obvious.
            – Simeon Simeonov
            Nov 18 at 18:41















          up vote
          2
          down vote



          accepted










          The following does produce the output you want. The minus signs in the output are not contributing to the overall size of the output, so they might stick into the margin. As you said you don't need fractions, the following doesn't cover that. It is only working for integer division and always truncates the result. Some portions of the horizontal rules might get drawn twice, that can lead to rendering issues in some PDF viewers, but if you zoom in those should be gone and the print should look fine.



          documentclass{article}

          usepackage{xparse,expl3}
          usepackage{mathtools}
          ExplSyntaxOn
          int_new:N l_Simeon_divisor_int
          int_new:N l_Simeon_tmpa_int
          int_new:N l_Simeon_next_dividend_int
          int_new:N l_Simeon_pops_int
          seq_new:N l_Simeon_dividend_seq
          seq_new:N l_Simeon_under_seq
          bool_new:N l_Simeon_first_bool
          tl_new:N l_Simeon_tmpa_tl
          msg_new:nnn { Simeon } { empty~arg }%>>>
          {
          It ~ seems ~ like ~ you ~ provided ~ an ~ empty ~ arg ~ for ~ the ~ #1, ~
          this ~ is ~ not ~ allowed.
          }%<<<
          cs_new:Npn Simeon_shift_aux:n #1%>>>
          {
          exp_not:n { phantom { 0 } }
          }%<<<
          cs_new:Npn Simeon_shift:%>>>
          {
          int_step_function:nN { l_Simeon_pops_int } Simeon_shift_aux:n
          }%<<<
          cs_new_protected:Npn Simeon_array:n #1%>>>
          {
          mathllap { begin { array } { @{} r @{} } #1 end { array } }
          }%<<<
          cs_new_protected:Npn Simeon_add_to_under:n #1%>>>
          {
          seq_put_right:Nx l_Simeon_under_seq
          {
          Simeon_shift:
          Simeon_array:n { #1 }
          }
          }%<<<
          cs_new_protected:Npn Simeon_pop_and_calc:nn #1 #2%>>>
          {
          seq_pop_left:NN l_Simeon_dividend_seq l_Simeon_tmpa_tl
          int_incr:N l_Simeon_pops_int
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int * 10 + l_Simeon_tmpa_tl }
          int_set:Nn l_Simeon_tmpa_int
          {
          fp_eval:n
          { trunc ( l_Simeon_next_dividend_int / l_Simeon_divisor_int ) }
          }
          int_compare:nNnF l_Simeon_tmpa_int = c_zero_int
          {
          #1
          int_set:Nn l_Simeon_tmpa_int
          { l_Simeon_tmpa_int * l_Simeon_divisor_int }
          Simeon_add_to_under:n { #2 }
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int - l_Simeon_tmpa_int }
          }
          }%<<<
          cs_new:Npn Simeon_continue_hline:%>>>
          {
          noalign { vskip -arrayrulewidth }
          hline
          }%<<<
          NewDocumentCommand longintdiv { m m }%>>>
          {
          % initializing variables >>>
          tl_if_blank:nT { #1 }
          { msg_error:nnn { Simeon } { empty~arg } { dividend } }
          tl_if_blank:nT { #2 }
          { msg_error:nnn { Simeon } { empty~arg } { divisor } }
          seq_set_split:Nnn l_Simeon_dividend_seq {} { #1 }
          seq_clear:N l_Simeon_under_seq
          int_set:Nn l_Simeon_divisor_int { #2 }
          int_zero:N l_Simeon_next_dividend_int
          int_zero:N l_Simeon_pops_int
          bool_set_true:N l_Simeon_first_bool
          % <<<
          % first division >>>
          bool_do_while:nn
          { l_Simeon_first_bool && !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn { bool_set_false:N l_Simeon_first_bool }
          {
          exp_not:N mathllap { {} - {} }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % other divisions >>>
          bool_while_do:nn { !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn {}
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          exp_not:n { \ mathllap { {} - {} } }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % rest >>>
          Simeon_add_to_under:n
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          }
          % <<<
          % output >>>
          $
          begin { array } [ t ] { @{} l @{} }
          #1 mathbin{:} #2 = int_eval:n { fp_eval:n { trunc ( #1 / #2 ) } }\
          seq_use:Nn l_Simeon_under_seq { \ }
          end { array }
          $
          % <<<
          }%<<<
          ExplSyntaxOff

          begin{document}
          longintdiv{1011}{11}
          qquad
          longintdiv{3516}{5}
          qquad
          longintdiv{5}{5}
          qquad
          longintdiv{4}{5}
          end{document}


          enter image description here






          share|improve this answer























          • That's really good! Thank you! Is it possible to make them all on one line?
            – Simeon Simeonov
            Nov 18 at 17:46






          • 1




            @SimeonSimeonov I've cleaned up the code a bit (ignore the %>>> thingies, those are just for me and my VIM). I've also changed the output to be in one line.
            – Skillmon
            Nov 18 at 18:13










          • REALLY good! Thank you! You saved me hours and many nerves! Great!
            – Simeon Simeonov
            Nov 18 at 18:19










          • @SimeonSimeonov can you give me the numbers which produce that?
            – Skillmon
            Nov 18 at 18:33










          • Ahhh sorry. It's working without problems. I had just begin{spacing}{1.5}. I will close this construction when I am working with it. It was obvious.
            – Simeon Simeonov
            Nov 18 at 18:41













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          The following does produce the output you want. The minus signs in the output are not contributing to the overall size of the output, so they might stick into the margin. As you said you don't need fractions, the following doesn't cover that. It is only working for integer division and always truncates the result. Some portions of the horizontal rules might get drawn twice, that can lead to rendering issues in some PDF viewers, but if you zoom in those should be gone and the print should look fine.



          documentclass{article}

          usepackage{xparse,expl3}
          usepackage{mathtools}
          ExplSyntaxOn
          int_new:N l_Simeon_divisor_int
          int_new:N l_Simeon_tmpa_int
          int_new:N l_Simeon_next_dividend_int
          int_new:N l_Simeon_pops_int
          seq_new:N l_Simeon_dividend_seq
          seq_new:N l_Simeon_under_seq
          bool_new:N l_Simeon_first_bool
          tl_new:N l_Simeon_tmpa_tl
          msg_new:nnn { Simeon } { empty~arg }%>>>
          {
          It ~ seems ~ like ~ you ~ provided ~ an ~ empty ~ arg ~ for ~ the ~ #1, ~
          this ~ is ~ not ~ allowed.
          }%<<<
          cs_new:Npn Simeon_shift_aux:n #1%>>>
          {
          exp_not:n { phantom { 0 } }
          }%<<<
          cs_new:Npn Simeon_shift:%>>>
          {
          int_step_function:nN { l_Simeon_pops_int } Simeon_shift_aux:n
          }%<<<
          cs_new_protected:Npn Simeon_array:n #1%>>>
          {
          mathllap { begin { array } { @{} r @{} } #1 end { array } }
          }%<<<
          cs_new_protected:Npn Simeon_add_to_under:n #1%>>>
          {
          seq_put_right:Nx l_Simeon_under_seq
          {
          Simeon_shift:
          Simeon_array:n { #1 }
          }
          }%<<<
          cs_new_protected:Npn Simeon_pop_and_calc:nn #1 #2%>>>
          {
          seq_pop_left:NN l_Simeon_dividend_seq l_Simeon_tmpa_tl
          int_incr:N l_Simeon_pops_int
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int * 10 + l_Simeon_tmpa_tl }
          int_set:Nn l_Simeon_tmpa_int
          {
          fp_eval:n
          { trunc ( l_Simeon_next_dividend_int / l_Simeon_divisor_int ) }
          }
          int_compare:nNnF l_Simeon_tmpa_int = c_zero_int
          {
          #1
          int_set:Nn l_Simeon_tmpa_int
          { l_Simeon_tmpa_int * l_Simeon_divisor_int }
          Simeon_add_to_under:n { #2 }
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int - l_Simeon_tmpa_int }
          }
          }%<<<
          cs_new:Npn Simeon_continue_hline:%>>>
          {
          noalign { vskip -arrayrulewidth }
          hline
          }%<<<
          NewDocumentCommand longintdiv { m m }%>>>
          {
          % initializing variables >>>
          tl_if_blank:nT { #1 }
          { msg_error:nnn { Simeon } { empty~arg } { dividend } }
          tl_if_blank:nT { #2 }
          { msg_error:nnn { Simeon } { empty~arg } { divisor } }
          seq_set_split:Nnn l_Simeon_dividend_seq {} { #1 }
          seq_clear:N l_Simeon_under_seq
          int_set:Nn l_Simeon_divisor_int { #2 }
          int_zero:N l_Simeon_next_dividend_int
          int_zero:N l_Simeon_pops_int
          bool_set_true:N l_Simeon_first_bool
          % <<<
          % first division >>>
          bool_do_while:nn
          { l_Simeon_first_bool && !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn { bool_set_false:N l_Simeon_first_bool }
          {
          exp_not:N mathllap { {} - {} }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % other divisions >>>
          bool_while_do:nn { !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn {}
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          exp_not:n { \ mathllap { {} - {} } }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % rest >>>
          Simeon_add_to_under:n
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          }
          % <<<
          % output >>>
          $
          begin { array } [ t ] { @{} l @{} }
          #1 mathbin{:} #2 = int_eval:n { fp_eval:n { trunc ( #1 / #2 ) } }\
          seq_use:Nn l_Simeon_under_seq { \ }
          end { array }
          $
          % <<<
          }%<<<
          ExplSyntaxOff

          begin{document}
          longintdiv{1011}{11}
          qquad
          longintdiv{3516}{5}
          qquad
          longintdiv{5}{5}
          qquad
          longintdiv{4}{5}
          end{document}


          enter image description here






          share|improve this answer














          The following does produce the output you want. The minus signs in the output are not contributing to the overall size of the output, so they might stick into the margin. As you said you don't need fractions, the following doesn't cover that. It is only working for integer division and always truncates the result. Some portions of the horizontal rules might get drawn twice, that can lead to rendering issues in some PDF viewers, but if you zoom in those should be gone and the print should look fine.



          documentclass{article}

          usepackage{xparse,expl3}
          usepackage{mathtools}
          ExplSyntaxOn
          int_new:N l_Simeon_divisor_int
          int_new:N l_Simeon_tmpa_int
          int_new:N l_Simeon_next_dividend_int
          int_new:N l_Simeon_pops_int
          seq_new:N l_Simeon_dividend_seq
          seq_new:N l_Simeon_under_seq
          bool_new:N l_Simeon_first_bool
          tl_new:N l_Simeon_tmpa_tl
          msg_new:nnn { Simeon } { empty~arg }%>>>
          {
          It ~ seems ~ like ~ you ~ provided ~ an ~ empty ~ arg ~ for ~ the ~ #1, ~
          this ~ is ~ not ~ allowed.
          }%<<<
          cs_new:Npn Simeon_shift_aux:n #1%>>>
          {
          exp_not:n { phantom { 0 } }
          }%<<<
          cs_new:Npn Simeon_shift:%>>>
          {
          int_step_function:nN { l_Simeon_pops_int } Simeon_shift_aux:n
          }%<<<
          cs_new_protected:Npn Simeon_array:n #1%>>>
          {
          mathllap { begin { array } { @{} r @{} } #1 end { array } }
          }%<<<
          cs_new_protected:Npn Simeon_add_to_under:n #1%>>>
          {
          seq_put_right:Nx l_Simeon_under_seq
          {
          Simeon_shift:
          Simeon_array:n { #1 }
          }
          }%<<<
          cs_new_protected:Npn Simeon_pop_and_calc:nn #1 #2%>>>
          {
          seq_pop_left:NN l_Simeon_dividend_seq l_Simeon_tmpa_tl
          int_incr:N l_Simeon_pops_int
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int * 10 + l_Simeon_tmpa_tl }
          int_set:Nn l_Simeon_tmpa_int
          {
          fp_eval:n
          { trunc ( l_Simeon_next_dividend_int / l_Simeon_divisor_int ) }
          }
          int_compare:nNnF l_Simeon_tmpa_int = c_zero_int
          {
          #1
          int_set:Nn l_Simeon_tmpa_int
          { l_Simeon_tmpa_int * l_Simeon_divisor_int }
          Simeon_add_to_under:n { #2 }
          int_set:Nn l_Simeon_next_dividend_int
          { l_Simeon_next_dividend_int - l_Simeon_tmpa_int }
          }
          }%<<<
          cs_new:Npn Simeon_continue_hline:%>>>
          {
          noalign { vskip -arrayrulewidth }
          hline
          }%<<<
          NewDocumentCommand longintdiv { m m }%>>>
          {
          % initializing variables >>>
          tl_if_blank:nT { #1 }
          { msg_error:nnn { Simeon } { empty~arg } { dividend } }
          tl_if_blank:nT { #2 }
          { msg_error:nnn { Simeon } { empty~arg } { divisor } }
          seq_set_split:Nnn l_Simeon_dividend_seq {} { #1 }
          seq_clear:N l_Simeon_under_seq
          int_set:Nn l_Simeon_divisor_int { #2 }
          int_zero:N l_Simeon_next_dividend_int
          int_zero:N l_Simeon_pops_int
          bool_set_true:N l_Simeon_first_bool
          % <<<
          % first division >>>
          bool_do_while:nn
          { l_Simeon_first_bool && !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn { bool_set_false:N l_Simeon_first_bool }
          {
          exp_not:N mathllap { {} - {} }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % other divisions >>>
          bool_while_do:nn { !seq_if_empty_p:N l_Simeon_dividend_seq }
          {
          Simeon_pop_and_calc:nn {}
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          exp_not:n { \ mathllap { {} - {} } }
          int_use:N l_Simeon_tmpa_int
          exp_not:n { \ hline }
          }
          }
          % <<<
          % rest >>>
          Simeon_add_to_under:n
          {
          exp_not:N Simeon_continue_hline:
          int_use:N l_Simeon_next_dividend_int
          }
          % <<<
          % output >>>
          $
          begin { array } [ t ] { @{} l @{} }
          #1 mathbin{:} #2 = int_eval:n { fp_eval:n { trunc ( #1 / #2 ) } }\
          seq_use:Nn l_Simeon_under_seq { \ }
          end { array }
          $
          % <<<
          }%<<<
          ExplSyntaxOff

          begin{document}
          longintdiv{1011}{11}
          qquad
          longintdiv{3516}{5}
          qquad
          longintdiv{5}{5}
          qquad
          longintdiv{4}{5}
          end{document}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 18 at 18:12

























          answered Nov 18 at 17:03









          Skillmon

          20.4k11840




          20.4k11840












          • That's really good! Thank you! Is it possible to make them all on one line?
            – Simeon Simeonov
            Nov 18 at 17:46






          • 1




            @SimeonSimeonov I've cleaned up the code a bit (ignore the %>>> thingies, those are just for me and my VIM). I've also changed the output to be in one line.
            – Skillmon
            Nov 18 at 18:13










          • REALLY good! Thank you! You saved me hours and many nerves! Great!
            – Simeon Simeonov
            Nov 18 at 18:19










          • @SimeonSimeonov can you give me the numbers which produce that?
            – Skillmon
            Nov 18 at 18:33










          • Ahhh sorry. It's working without problems. I had just begin{spacing}{1.5}. I will close this construction when I am working with it. It was obvious.
            – Simeon Simeonov
            Nov 18 at 18:41


















          • That's really good! Thank you! Is it possible to make them all on one line?
            – Simeon Simeonov
            Nov 18 at 17:46






          • 1




            @SimeonSimeonov I've cleaned up the code a bit (ignore the %>>> thingies, those are just for me and my VIM). I've also changed the output to be in one line.
            – Skillmon
            Nov 18 at 18:13










          • REALLY good! Thank you! You saved me hours and many nerves! Great!
            – Simeon Simeonov
            Nov 18 at 18:19










          • @SimeonSimeonov can you give me the numbers which produce that?
            – Skillmon
            Nov 18 at 18:33










          • Ahhh sorry. It's working without problems. I had just begin{spacing}{1.5}. I will close this construction when I am working with it. It was obvious.
            – Simeon Simeonov
            Nov 18 at 18:41
















          That's really good! Thank you! Is it possible to make them all on one line?
          – Simeon Simeonov
          Nov 18 at 17:46




          That's really good! Thank you! Is it possible to make them all on one line?
          – Simeon Simeonov
          Nov 18 at 17:46




          1




          1




          @SimeonSimeonov I've cleaned up the code a bit (ignore the %>>> thingies, those are just for me and my VIM). I've also changed the output to be in one line.
          – Skillmon
          Nov 18 at 18:13




          @SimeonSimeonov I've cleaned up the code a bit (ignore the %>>> thingies, those are just for me and my VIM). I've also changed the output to be in one line.
          – Skillmon
          Nov 18 at 18:13












          REALLY good! Thank you! You saved me hours and many nerves! Great!
          – Simeon Simeonov
          Nov 18 at 18:19




          REALLY good! Thank you! You saved me hours and many nerves! Great!
          – Simeon Simeonov
          Nov 18 at 18:19












          @SimeonSimeonov can you give me the numbers which produce that?
          – Skillmon
          Nov 18 at 18:33




          @SimeonSimeonov can you give me the numbers which produce that?
          – Skillmon
          Nov 18 at 18:33












          Ahhh sorry. It's working without problems. I had just begin{spacing}{1.5}. I will close this construction when I am working with it. It was obvious.
          – Simeon Simeonov
          Nov 18 at 18:41




          Ahhh sorry. It's working without problems. I had just begin{spacing}{1.5}. I will close this construction when I am working with it. It was obvious.
          – Simeon Simeonov
          Nov 18 at 18:41










          Simeon Simeonov is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          Simeon Simeonov is a new contributor. Be nice, and check out our Code of Conduct.













          Simeon Simeonov is a new contributor. Be nice, and check out our Code of Conduct.












          Simeon Simeonov is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460598%2fnew-command-long-division-help%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

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?