How can I determine whether a custom environment is followed by a new paragraph?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite












I'm writing a custom command that uses minipages to display its contents:



newcommandexample[1]noindentbeginminipagelinewidth#1endminipage


The spacing around this command should be similar to that of the align environment: abovedisplayskip above, and belowdisplayskip after, so I add parvspace… before and after:



newcommandexample[1]%
parvspaceabovedisplayskip
noindentbeginminipagelinewidth#1endminipage
paraddvspacebelowdisplayskip


This isn't perfect, though: it adds an extra parskip before and after the contents, even if there are no blank lines around the command:



AAA % too much space (extra parskip) after this
examplelipsum[1]
BBB % too much space (extra parskip) before that


I can remove the first one by changing the definition to this:



newcommandexample[1]%
ifvmodeelseparvspace-parskipfivspaceabovedisplayskip
noindentbeginminipagelinewidth#1endminipage
paraddvspacebelowdisplayskip


But what's the equivalent fix for the bottom of the command? If I use a negative space the parskip will always be suppressed. Ideally, I'd like text immediately following the command to not be indented, just like with [].



Here's a minimal example:



documentclassminimal

usepackagelipsum
setlengthparskip50pt

newcommandexample[1]%
ifvmodeelseparvspace-parskipfivspaceabovedisplayskip
noindentbeginminipagelinewidth#1endminipage
paraddvspacebelowdisplayskip

begindocument

% There should be small spaces after AAA and before BBB
AAA
examplelipsum[1]
BBB

% There should be a large space after AAA and a small one before BBB
% And BBB shouldn't be indented
AAA

examplelipsum[1]
BBB

% There should be a small space after AAA and a large one before BBB
AAA
examplelipsum[1]

BBB
enddocument









share|improve this question

























    up vote
    5
    down vote

    favorite












    I'm writing a custom command that uses minipages to display its contents:



    newcommandexample[1]noindentbeginminipagelinewidth#1endminipage


    The spacing around this command should be similar to that of the align environment: abovedisplayskip above, and belowdisplayskip after, so I add parvspace… before and after:



    newcommandexample[1]%
    parvspaceabovedisplayskip
    noindentbeginminipagelinewidth#1endminipage
    paraddvspacebelowdisplayskip


    This isn't perfect, though: it adds an extra parskip before and after the contents, even if there are no blank lines around the command:



    AAA % too much space (extra parskip) after this
    examplelipsum[1]
    BBB % too much space (extra parskip) before that


    I can remove the first one by changing the definition to this:



    newcommandexample[1]%
    ifvmodeelseparvspace-parskipfivspaceabovedisplayskip
    noindentbeginminipagelinewidth#1endminipage
    paraddvspacebelowdisplayskip


    But what's the equivalent fix for the bottom of the command? If I use a negative space the parskip will always be suppressed. Ideally, I'd like text immediately following the command to not be indented, just like with [].



    Here's a minimal example:



    documentclassminimal

    usepackagelipsum
    setlengthparskip50pt

    newcommandexample[1]%
    ifvmodeelseparvspace-parskipfivspaceabovedisplayskip
    noindentbeginminipagelinewidth#1endminipage
    paraddvspacebelowdisplayskip

    begindocument

    % There should be small spaces after AAA and before BBB
    AAA
    examplelipsum[1]
    BBB

    % There should be a large space after AAA and a small one before BBB
    % And BBB shouldn't be indented
    AAA

    examplelipsum[1]
    BBB

    % There should be a small space after AAA and a large one before BBB
    AAA
    examplelipsum[1]

    BBB
    enddocument









    share|improve this question























      up vote
      5
      down vote

      favorite









      up vote
      5
      down vote

      favorite











      I'm writing a custom command that uses minipages to display its contents:



      newcommandexample[1]noindentbeginminipagelinewidth#1endminipage


      The spacing around this command should be similar to that of the align environment: abovedisplayskip above, and belowdisplayskip after, so I add parvspace… before and after:



      newcommandexample[1]%
      parvspaceabovedisplayskip
      noindentbeginminipagelinewidth#1endminipage
      paraddvspacebelowdisplayskip


      This isn't perfect, though: it adds an extra parskip before and after the contents, even if there are no blank lines around the command:



      AAA % too much space (extra parskip) after this
      examplelipsum[1]
      BBB % too much space (extra parskip) before that


      I can remove the first one by changing the definition to this:



      newcommandexample[1]%
      ifvmodeelseparvspace-parskipfivspaceabovedisplayskip
      noindentbeginminipagelinewidth#1endminipage
      paraddvspacebelowdisplayskip


      But what's the equivalent fix for the bottom of the command? If I use a negative space the parskip will always be suppressed. Ideally, I'd like text immediately following the command to not be indented, just like with [].



      Here's a minimal example:



      documentclassminimal

      usepackagelipsum
      setlengthparskip50pt

      newcommandexample[1]%
      ifvmodeelseparvspace-parskipfivspaceabovedisplayskip
      noindentbeginminipagelinewidth#1endminipage
      paraddvspacebelowdisplayskip

      begindocument

      % There should be small spaces after AAA and before BBB
      AAA
      examplelipsum[1]
      BBB

      % There should be a large space after AAA and a small one before BBB
      % And BBB shouldn't be indented
      AAA

      examplelipsum[1]
      BBB

      % There should be a small space after AAA and a large one before BBB
      AAA
      examplelipsum[1]

      BBB
      enddocument









      share|improve this question













      I'm writing a custom command that uses minipages to display its contents:



      newcommandexample[1]noindentbeginminipagelinewidth#1endminipage


      The spacing around this command should be similar to that of the align environment: abovedisplayskip above, and belowdisplayskip after, so I add parvspace… before and after:



      newcommandexample[1]%
      parvspaceabovedisplayskip
      noindentbeginminipagelinewidth#1endminipage
      paraddvspacebelowdisplayskip


      This isn't perfect, though: it adds an extra parskip before and after the contents, even if there are no blank lines around the command:



      AAA % too much space (extra parskip) after this
      examplelipsum[1]
      BBB % too much space (extra parskip) before that


      I can remove the first one by changing the definition to this:



      newcommandexample[1]%
      ifvmodeelseparvspace-parskipfivspaceabovedisplayskip
      noindentbeginminipagelinewidth#1endminipage
      paraddvspacebelowdisplayskip


      But what's the equivalent fix for the bottom of the command? If I use a negative space the parskip will always be suppressed. Ideally, I'd like text immediately following the command to not be indented, just like with [].



      Here's a minimal example:



      documentclassminimal

      usepackagelipsum
      setlengthparskip50pt

      newcommandexample[1]%
      ifvmodeelseparvspace-parskipfivspaceabovedisplayskip
      noindentbeginminipagelinewidth#1endminipage
      paraddvspacebelowdisplayskip

      begindocument

      % There should be small spaces after AAA and before BBB
      AAA
      examplelipsum[1]
      BBB

      % There should be a large space after AAA and a small one before BBB
      % And BBB shouldn't be indented
      AAA

      examplelipsum[1]
      BBB

      % There should be a small space after AAA and a large one before BBB
      AAA
      examplelipsum[1]

      BBB
      enddocument






      spacing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      Clément

      1,6861529




      1,6861529




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          The standard way to do this would be to define your environment as a trivlist, almost all latex display environments (verbatim, center, quote,..) are defined as trivlists (special one-item version of list) exactly for this reason.



          The trivlist code detects whether there is a paragraph break before the list and if so has paragraph spacing before and after, but if there is no paragraph break before the list then the internal par after the list is hidden and paragraph indentation of the following text is suppressed.



          begincenterendcenter for example is defined by



          defcentertrivlist centeringitemrelax
          defendcenterendtrivlist





          share|improve this answer



























            up vote
            0
            down vote













            Here is a possible solution.
            I'm defining the macro tentativepar which inserts par and sets both parskip and parindent to 0pt.
            It moreover temporarily redefines par and everypar (which is inserted at the start of every paragraph) to reset the original values.



            The net effect is that tentativepar will insert a paragraph break without any skip or indentation unless it is followed by another par.



            Here is an example:



            documentclassarticle

            setlengthparskip50pt

            %% vv We need to store a couple of values
            newskipsavedparskip
            newskipsavedparindent
            newtokssavedeverypar

            makeatletter
            newcommand*tentativepar%
            par
            savedparskipparskip %% <- store original parskip
            savedparindentparindent %% <- store original parindent
            expandaftersavedeveryparexpandaftertheeverypar
            %% ^^ store original everypar
            parskip0pt %% <- set parskip to 0pt
            parindent0pt %% <- set parindent to 0pt
            %% vv restore everything that was saved after the first par
            defpar%
            @restorepar %% <- restore original par
            expandaftereveryparexpandafterthesavedeverypar%
            parskipsavedparskip %% <- reset parskip
            parindentsavedparindent %% <- reset parindent
            par %% still insert a paragraph break
            %
            %% vv or at the stat of the next paragraph
            expandaftereveryparexpandafter%
            thesavedeverypar
            @restorepar %% <- restore original par
            expandaftereveryparexpandafterthesavedeverypar%
            parskipsavedparskip %% <- reset parskip
            parindentsavedparindent %% <- reset parindent


            makeatother

            newcommandexample[1]%
            ifvmodeelsetentativeparfi
            vspaceabovedisplayskip
            noindentbeginminipage.5linewidth#1endminipage%
            vspacebelowdisplayskip
            tentativepar


            begindocument

            AAA
            exampleThere should be small spaces after AAA and before BBB
            BBB

            AAA

            exampleThere should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.
            BBB

            AAA
            exampleThere should be a small space after AAA and a large one before BBB

            BBB

            CCC

            enddocument


            Output





            share




















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



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f458433%2fhow-can-i-determine-whether-a-custom-environment-is-followed-by-a-new-paragraph%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote













              The standard way to do this would be to define your environment as a trivlist, almost all latex display environments (verbatim, center, quote,..) are defined as trivlists (special one-item version of list) exactly for this reason.



              The trivlist code detects whether there is a paragraph break before the list and if so has paragraph spacing before and after, but if there is no paragraph break before the list then the internal par after the list is hidden and paragraph indentation of the following text is suppressed.



              begincenterendcenter for example is defined by



              defcentertrivlist centeringitemrelax
              defendcenterendtrivlist





              share|improve this answer
























                up vote
                2
                down vote













                The standard way to do this would be to define your environment as a trivlist, almost all latex display environments (verbatim, center, quote,..) are defined as trivlists (special one-item version of list) exactly for this reason.



                The trivlist code detects whether there is a paragraph break before the list and if so has paragraph spacing before and after, but if there is no paragraph break before the list then the internal par after the list is hidden and paragraph indentation of the following text is suppressed.



                begincenterendcenter for example is defined by



                defcentertrivlist centeringitemrelax
                defendcenterendtrivlist





                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  The standard way to do this would be to define your environment as a trivlist, almost all latex display environments (verbatim, center, quote,..) are defined as trivlists (special one-item version of list) exactly for this reason.



                  The trivlist code detects whether there is a paragraph break before the list and if so has paragraph spacing before and after, but if there is no paragraph break before the list then the internal par after the list is hidden and paragraph indentation of the following text is suppressed.



                  begincenterendcenter for example is defined by



                  defcentertrivlist centeringitemrelax
                  defendcenterendtrivlist





                  share|improve this answer












                  The standard way to do this would be to define your environment as a trivlist, almost all latex display environments (verbatim, center, quote,..) are defined as trivlists (special one-item version of list) exactly for this reason.



                  The trivlist code detects whether there is a paragraph break before the list and if so has paragraph spacing before and after, but if there is no paragraph break before the list then the internal par after the list is hidden and paragraph indentation of the following text is suppressed.



                  begincenterendcenter for example is defined by



                  defcentertrivlist centeringitemrelax
                  defendcenterendtrivlist






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  David Carlisle

                  474k3811031837




                  474k3811031837




















                      up vote
                      0
                      down vote













                      Here is a possible solution.
                      I'm defining the macro tentativepar which inserts par and sets both parskip and parindent to 0pt.
                      It moreover temporarily redefines par and everypar (which is inserted at the start of every paragraph) to reset the original values.



                      The net effect is that tentativepar will insert a paragraph break without any skip or indentation unless it is followed by another par.



                      Here is an example:



                      documentclassarticle

                      setlengthparskip50pt

                      %% vv We need to store a couple of values
                      newskipsavedparskip
                      newskipsavedparindent
                      newtokssavedeverypar

                      makeatletter
                      newcommand*tentativepar%
                      par
                      savedparskipparskip %% <- store original parskip
                      savedparindentparindent %% <- store original parindent
                      expandaftersavedeveryparexpandaftertheeverypar
                      %% ^^ store original everypar
                      parskip0pt %% <- set parskip to 0pt
                      parindent0pt %% <- set parindent to 0pt
                      %% vv restore everything that was saved after the first par
                      defpar%
                      @restorepar %% <- restore original par
                      expandaftereveryparexpandafterthesavedeverypar%
                      parskipsavedparskip %% <- reset parskip
                      parindentsavedparindent %% <- reset parindent
                      par %% still insert a paragraph break
                      %
                      %% vv or at the stat of the next paragraph
                      expandaftereveryparexpandafter%
                      thesavedeverypar
                      @restorepar %% <- restore original par
                      expandaftereveryparexpandafterthesavedeverypar%
                      parskipsavedparskip %% <- reset parskip
                      parindentsavedparindent %% <- reset parindent


                      makeatother

                      newcommandexample[1]%
                      ifvmodeelsetentativeparfi
                      vspaceabovedisplayskip
                      noindentbeginminipage.5linewidth#1endminipage%
                      vspacebelowdisplayskip
                      tentativepar


                      begindocument

                      AAA
                      exampleThere should be small spaces after AAA and before BBB
                      BBB

                      AAA

                      exampleThere should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.
                      BBB

                      AAA
                      exampleThere should be a small space after AAA and a large one before BBB

                      BBB

                      CCC

                      enddocument


                      Output





                      share
























                        up vote
                        0
                        down vote













                        Here is a possible solution.
                        I'm defining the macro tentativepar which inserts par and sets both parskip and parindent to 0pt.
                        It moreover temporarily redefines par and everypar (which is inserted at the start of every paragraph) to reset the original values.



                        The net effect is that tentativepar will insert a paragraph break without any skip or indentation unless it is followed by another par.



                        Here is an example:



                        documentclassarticle

                        setlengthparskip50pt

                        %% vv We need to store a couple of values
                        newskipsavedparskip
                        newskipsavedparindent
                        newtokssavedeverypar

                        makeatletter
                        newcommand*tentativepar%
                        par
                        savedparskipparskip %% <- store original parskip
                        savedparindentparindent %% <- store original parindent
                        expandaftersavedeveryparexpandaftertheeverypar
                        %% ^^ store original everypar
                        parskip0pt %% <- set parskip to 0pt
                        parindent0pt %% <- set parindent to 0pt
                        %% vv restore everything that was saved after the first par
                        defpar%
                        @restorepar %% <- restore original par
                        expandaftereveryparexpandafterthesavedeverypar%
                        parskipsavedparskip %% <- reset parskip
                        parindentsavedparindent %% <- reset parindent
                        par %% still insert a paragraph break
                        %
                        %% vv or at the stat of the next paragraph
                        expandaftereveryparexpandafter%
                        thesavedeverypar
                        @restorepar %% <- restore original par
                        expandaftereveryparexpandafterthesavedeverypar%
                        parskipsavedparskip %% <- reset parskip
                        parindentsavedparindent %% <- reset parindent


                        makeatother

                        newcommandexample[1]%
                        ifvmodeelsetentativeparfi
                        vspaceabovedisplayskip
                        noindentbeginminipage.5linewidth#1endminipage%
                        vspacebelowdisplayskip
                        tentativepar


                        begindocument

                        AAA
                        exampleThere should be small spaces after AAA and before BBB
                        BBB

                        AAA

                        exampleThere should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.
                        BBB

                        AAA
                        exampleThere should be a small space after AAA and a large one before BBB

                        BBB

                        CCC

                        enddocument


                        Output





                        share






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Here is a possible solution.
                          I'm defining the macro tentativepar which inserts par and sets both parskip and parindent to 0pt.
                          It moreover temporarily redefines par and everypar (which is inserted at the start of every paragraph) to reset the original values.



                          The net effect is that tentativepar will insert a paragraph break without any skip or indentation unless it is followed by another par.



                          Here is an example:



                          documentclassarticle

                          setlengthparskip50pt

                          %% vv We need to store a couple of values
                          newskipsavedparskip
                          newskipsavedparindent
                          newtokssavedeverypar

                          makeatletter
                          newcommand*tentativepar%
                          par
                          savedparskipparskip %% <- store original parskip
                          savedparindentparindent %% <- store original parindent
                          expandaftersavedeveryparexpandaftertheeverypar
                          %% ^^ store original everypar
                          parskip0pt %% <- set parskip to 0pt
                          parindent0pt %% <- set parindent to 0pt
                          %% vv restore everything that was saved after the first par
                          defpar%
                          @restorepar %% <- restore original par
                          expandaftereveryparexpandafterthesavedeverypar%
                          parskipsavedparskip %% <- reset parskip
                          parindentsavedparindent %% <- reset parindent
                          par %% still insert a paragraph break
                          %
                          %% vv or at the stat of the next paragraph
                          expandaftereveryparexpandafter%
                          thesavedeverypar
                          @restorepar %% <- restore original par
                          expandaftereveryparexpandafterthesavedeverypar%
                          parskipsavedparskip %% <- reset parskip
                          parindentsavedparindent %% <- reset parindent


                          makeatother

                          newcommandexample[1]%
                          ifvmodeelsetentativeparfi
                          vspaceabovedisplayskip
                          noindentbeginminipage.5linewidth#1endminipage%
                          vspacebelowdisplayskip
                          tentativepar


                          begindocument

                          AAA
                          exampleThere should be small spaces after AAA and before BBB
                          BBB

                          AAA

                          exampleThere should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.
                          BBB

                          AAA
                          exampleThere should be a small space after AAA and a large one before BBB

                          BBB

                          CCC

                          enddocument


                          Output





                          share












                          Here is a possible solution.
                          I'm defining the macro tentativepar which inserts par and sets both parskip and parindent to 0pt.
                          It moreover temporarily redefines par and everypar (which is inserted at the start of every paragraph) to reset the original values.



                          The net effect is that tentativepar will insert a paragraph break without any skip or indentation unless it is followed by another par.



                          Here is an example:



                          documentclassarticle

                          setlengthparskip50pt

                          %% vv We need to store a couple of values
                          newskipsavedparskip
                          newskipsavedparindent
                          newtokssavedeverypar

                          makeatletter
                          newcommand*tentativepar%
                          par
                          savedparskipparskip %% <- store original parskip
                          savedparindentparindent %% <- store original parindent
                          expandaftersavedeveryparexpandaftertheeverypar
                          %% ^^ store original everypar
                          parskip0pt %% <- set parskip to 0pt
                          parindent0pt %% <- set parindent to 0pt
                          %% vv restore everything that was saved after the first par
                          defpar%
                          @restorepar %% <- restore original par
                          expandaftereveryparexpandafterthesavedeverypar%
                          parskipsavedparskip %% <- reset parskip
                          parindentsavedparindent %% <- reset parindent
                          par %% still insert a paragraph break
                          %
                          %% vv or at the stat of the next paragraph
                          expandaftereveryparexpandafter%
                          thesavedeverypar
                          @restorepar %% <- restore original par
                          expandaftereveryparexpandafterthesavedeverypar%
                          parskipsavedparskip %% <- reset parskip
                          parindentsavedparindent %% <- reset parindent


                          makeatother

                          newcommandexample[1]%
                          ifvmodeelsetentativeparfi
                          vspaceabovedisplayskip
                          noindentbeginminipage.5linewidth#1endminipage%
                          vspacebelowdisplayskip
                          tentativepar


                          begindocument

                          AAA
                          exampleThere should be small spaces after AAA and before BBB
                          BBB

                          AAA

                          exampleThere should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.
                          BBB

                          AAA
                          exampleThere should be a small space after AAA and a large one before BBB

                          BBB

                          CCC

                          enddocument


                          Output






                          share











                          share


                          share










                          answered 7 mins ago









                          Circumscribe

                          2,268322




                          2,268322



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f458433%2fhow-can-i-determine-whether-a-custom-environment-is-followed-by-a-new-paragraph%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              List of Gilmore Girls characters

                              What does second last employer means? [closed]

                              One-line joke