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











up vote
11
down vote

favorite
1












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



newcommand{example}[1]{noindentbegin{minipage}{linewidth}#1end{minipage}}


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:



newcommand{example}[1]{%
parvspace{abovedisplayskip}
noindentbegin{minipage}{linewidth}#1end{minipage}
paraddvspace{belowdisplayskip}}


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
example{lipsum[1]}
BBB % too much space (extra parskip) before that


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



newcommand{example}[1]{%
ifvmodeelseparvspace{-parskip}fivspace{abovedisplayskip}
noindentbegin{minipage}{linewidth}#1end{minipage}
paraddvspace{belowdisplayskip}}


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:



documentclass{minimal}

usepackage{lipsum}
setlength{parskip}{50pt}

newcommand{example}[1]{%
ifvmodeelseparvspace{-parskip}fivspace{abovedisplayskip}
noindentbegin{minipage}{linewidth}#1end{minipage}
paraddvspace{belowdisplayskip}}

begin{document}

% There should be small spaces after AAA and before BBB
AAA
example{lipsum[1]}
BBB

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

example{lipsum[1]}
BBB

% There should be a small space after AAA and a large one before BBB
AAA
example{lipsum[1]}

BBB
end{document}









share|improve this question


























    up vote
    11
    down vote

    favorite
    1












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



    newcommand{example}[1]{noindentbegin{minipage}{linewidth}#1end{minipage}}


    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:



    newcommand{example}[1]{%
    parvspace{abovedisplayskip}
    noindentbegin{minipage}{linewidth}#1end{minipage}
    paraddvspace{belowdisplayskip}}


    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
    example{lipsum[1]}
    BBB % too much space (extra parskip) before that


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



    newcommand{example}[1]{%
    ifvmodeelseparvspace{-parskip}fivspace{abovedisplayskip}
    noindentbegin{minipage}{linewidth}#1end{minipage}
    paraddvspace{belowdisplayskip}}


    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:



    documentclass{minimal}

    usepackage{lipsum}
    setlength{parskip}{50pt}

    newcommand{example}[1]{%
    ifvmodeelseparvspace{-parskip}fivspace{abovedisplayskip}
    noindentbegin{minipage}{linewidth}#1end{minipage}
    paraddvspace{belowdisplayskip}}

    begin{document}

    % There should be small spaces after AAA and before BBB
    AAA
    example{lipsum[1]}
    BBB

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

    example{lipsum[1]}
    BBB

    % There should be a small space after AAA and a large one before BBB
    AAA
    example{lipsum[1]}

    BBB
    end{document}









    share|improve this question
























      up vote
      11
      down vote

      favorite
      1









      up vote
      11
      down vote

      favorite
      1






      1





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



      newcommand{example}[1]{noindentbegin{minipage}{linewidth}#1end{minipage}}


      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:



      newcommand{example}[1]{%
      parvspace{abovedisplayskip}
      noindentbegin{minipage}{linewidth}#1end{minipage}
      paraddvspace{belowdisplayskip}}


      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
      example{lipsum[1]}
      BBB % too much space (extra parskip) before that


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



      newcommand{example}[1]{%
      ifvmodeelseparvspace{-parskip}fivspace{abovedisplayskip}
      noindentbegin{minipage}{linewidth}#1end{minipage}
      paraddvspace{belowdisplayskip}}


      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:



      documentclass{minimal}

      usepackage{lipsum}
      setlength{parskip}{50pt}

      newcommand{example}[1]{%
      ifvmodeelseparvspace{-parskip}fivspace{abovedisplayskip}
      noindentbegin{minipage}{linewidth}#1end{minipage}
      paraddvspace{belowdisplayskip}}

      begin{document}

      % There should be small spaces after AAA and before BBB
      AAA
      example{lipsum[1]}
      BBB

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

      example{lipsum[1]}
      BBB

      % There should be a small space after AAA and a large one before BBB
      AAA
      example{lipsum[1]}

      BBB
      end{document}









      share|improve this question













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



      newcommand{example}[1]{noindentbegin{minipage}{linewidth}#1end{minipage}}


      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:



      newcommand{example}[1]{%
      parvspace{abovedisplayskip}
      noindentbegin{minipage}{linewidth}#1end{minipage}
      paraddvspace{belowdisplayskip}}


      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
      example{lipsum[1]}
      BBB % too much space (extra parskip) before that


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



      newcommand{example}[1]{%
      ifvmodeelseparvspace{-parskip}fivspace{abovedisplayskip}
      noindentbegin{minipage}{linewidth}#1end{minipage}
      paraddvspace{belowdisplayskip}}


      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:



      documentclass{minimal}

      usepackage{lipsum}
      setlength{parskip}{50pt}

      newcommand{example}[1]{%
      ifvmodeelseparvspace{-parskip}fivspace{abovedisplayskip}
      noindentbegin{minipage}{linewidth}#1end{minipage}
      paraddvspace{belowdisplayskip}}

      begin{document}

      % There should be small spaces after AAA and before BBB
      AAA
      example{lipsum[1]}
      BBB

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

      example{lipsum[1]}
      BBB

      % There should be a small space after AAA and a large one before BBB
      AAA
      example{lipsum[1]}

      BBB
      end{document}






      spacing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 5 at 6:56









      Clément

      1,7161530




      1,7161530






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          9
          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.



          begin{center}end{center} for example is defined by



          defcenter{trivlist centeringitemrelax}
          defendcenter{endtrivlist}





          share|improve this answer





















          • I believe this just inhibits paragraph indents, but not skips. If you enter wordbegin{center}centred wordsend{center}word, then parskip is still inserted twice.
            – Circumscribe
            Nov 5 at 12:04










          • @Circumscribe it uses partopsep as parskip in the par case and topsep as parskip in the no-par case, so by setting up those list parameters you can achieve (some) control over that
            – David Carlisle
            Nov 5 at 12:15












          • @Circumscribe topsep=0pt isn't it? but something like that, yes, this is consistent with all other latex displays so hopefully packages like parskip which set things up for non zero parskip would automatically do the right thing here.
            – David Carlisle
            Nov 5 at 12:47






          • 2




            Sorry, I had deleted my comment (before you had replied, I thought) because I wasn't sure about it anymore. For me setting partopsep=parskip and topsep=-parskip works. I think both parskip and topsep are always inserted (so this way they cancel out) and partopsep is only inserted when there is a preceding paragraph break.
            – Circumscribe
            Nov 5 at 12:57










          • @Circumscribe er yes that sounds about right:-)
            – David Carlisle
            Nov 5 at 13:02


















          up vote
          4
          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 (and themselves).



          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:



          documentclass{article}

          setlength{parskip}{50pt}

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

          makeatletter
          newcommand*tentativepar{%
          par
          savedparskipparskip %% <- store original parskip
          savedparindentparindent %% <- store original parindent
          expandaftersavedeveryparexpandafter{theeverypar}
          %% ^^ 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
          expandaftereveryparexpandafter{thesavedeverypar}%
          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
          expandaftereveryparexpandafter{thesavedeverypar}%
          parskipsavedparskip %% <- reset parskip
          parindentsavedparindent %% <- reset parindent
          }
          }
          makeatother

          newcommand{example}[1]{%
          ifvmodeelsetentativeparfi
          vspace{abovedisplayskip}
          noindentbegin{minipage}{.5linewidth}#1end{minipage}%
          vspace{belowdisplayskip}
          tentativepar
          }

          begin{document}

          AAA
          example{There should be small spaces after AAA and before BBB}
          BBB

          AAA

          example{There should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.}
          BBB

          AAA
          example{There should be a small space after AAA and a large one before BBB}

          BBB

          CCC

          end{document}


          Output






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "85"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            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
            9
            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.



            begin{center}end{center} for example is defined by



            defcenter{trivlist centeringitemrelax}
            defendcenter{endtrivlist}





            share|improve this answer





















            • I believe this just inhibits paragraph indents, but not skips. If you enter wordbegin{center}centred wordsend{center}word, then parskip is still inserted twice.
              – Circumscribe
              Nov 5 at 12:04










            • @Circumscribe it uses partopsep as parskip in the par case and topsep as parskip in the no-par case, so by setting up those list parameters you can achieve (some) control over that
              – David Carlisle
              Nov 5 at 12:15












            • @Circumscribe topsep=0pt isn't it? but something like that, yes, this is consistent with all other latex displays so hopefully packages like parskip which set things up for non zero parskip would automatically do the right thing here.
              – David Carlisle
              Nov 5 at 12:47






            • 2




              Sorry, I had deleted my comment (before you had replied, I thought) because I wasn't sure about it anymore. For me setting partopsep=parskip and topsep=-parskip works. I think both parskip and topsep are always inserted (so this way they cancel out) and partopsep is only inserted when there is a preceding paragraph break.
              – Circumscribe
              Nov 5 at 12:57










            • @Circumscribe er yes that sounds about right:-)
              – David Carlisle
              Nov 5 at 13:02















            up vote
            9
            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.



            begin{center}end{center} for example is defined by



            defcenter{trivlist centeringitemrelax}
            defendcenter{endtrivlist}





            share|improve this answer





















            • I believe this just inhibits paragraph indents, but not skips. If you enter wordbegin{center}centred wordsend{center}word, then parskip is still inserted twice.
              – Circumscribe
              Nov 5 at 12:04










            • @Circumscribe it uses partopsep as parskip in the par case and topsep as parskip in the no-par case, so by setting up those list parameters you can achieve (some) control over that
              – David Carlisle
              Nov 5 at 12:15












            • @Circumscribe topsep=0pt isn't it? but something like that, yes, this is consistent with all other latex displays so hopefully packages like parskip which set things up for non zero parskip would automatically do the right thing here.
              – David Carlisle
              Nov 5 at 12:47






            • 2




              Sorry, I had deleted my comment (before you had replied, I thought) because I wasn't sure about it anymore. For me setting partopsep=parskip and topsep=-parskip works. I think both parskip and topsep are always inserted (so this way they cancel out) and partopsep is only inserted when there is a preceding paragraph break.
              – Circumscribe
              Nov 5 at 12:57










            • @Circumscribe er yes that sounds about right:-)
              – David Carlisle
              Nov 5 at 13:02













            up vote
            9
            down vote










            up vote
            9
            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.



            begin{center}end{center} for example is defined by



            defcenter{trivlist centeringitemrelax}
            defendcenter{endtrivlist}





            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.



            begin{center}end{center} for example is defined by



            defcenter{trivlist centeringitemrelax}
            defendcenter{endtrivlist}






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 5 at 7:42









            David Carlisle

            475k3811061840




            475k3811061840












            • I believe this just inhibits paragraph indents, but not skips. If you enter wordbegin{center}centred wordsend{center}word, then parskip is still inserted twice.
              – Circumscribe
              Nov 5 at 12:04










            • @Circumscribe it uses partopsep as parskip in the par case and topsep as parskip in the no-par case, so by setting up those list parameters you can achieve (some) control over that
              – David Carlisle
              Nov 5 at 12:15












            • @Circumscribe topsep=0pt isn't it? but something like that, yes, this is consistent with all other latex displays so hopefully packages like parskip which set things up for non zero parskip would automatically do the right thing here.
              – David Carlisle
              Nov 5 at 12:47






            • 2




              Sorry, I had deleted my comment (before you had replied, I thought) because I wasn't sure about it anymore. For me setting partopsep=parskip and topsep=-parskip works. I think both parskip and topsep are always inserted (so this way they cancel out) and partopsep is only inserted when there is a preceding paragraph break.
              – Circumscribe
              Nov 5 at 12:57










            • @Circumscribe er yes that sounds about right:-)
              – David Carlisle
              Nov 5 at 13:02


















            • I believe this just inhibits paragraph indents, but not skips. If you enter wordbegin{center}centred wordsend{center}word, then parskip is still inserted twice.
              – Circumscribe
              Nov 5 at 12:04










            • @Circumscribe it uses partopsep as parskip in the par case and topsep as parskip in the no-par case, so by setting up those list parameters you can achieve (some) control over that
              – David Carlisle
              Nov 5 at 12:15












            • @Circumscribe topsep=0pt isn't it? but something like that, yes, this is consistent with all other latex displays so hopefully packages like parskip which set things up for non zero parskip would automatically do the right thing here.
              – David Carlisle
              Nov 5 at 12:47






            • 2




              Sorry, I had deleted my comment (before you had replied, I thought) because I wasn't sure about it anymore. For me setting partopsep=parskip and topsep=-parskip works. I think both parskip and topsep are always inserted (so this way they cancel out) and partopsep is only inserted when there is a preceding paragraph break.
              – Circumscribe
              Nov 5 at 12:57










            • @Circumscribe er yes that sounds about right:-)
              – David Carlisle
              Nov 5 at 13:02
















            I believe this just inhibits paragraph indents, but not skips. If you enter wordbegin{center}centred wordsend{center}word, then parskip is still inserted twice.
            – Circumscribe
            Nov 5 at 12:04




            I believe this just inhibits paragraph indents, but not skips. If you enter wordbegin{center}centred wordsend{center}word, then parskip is still inserted twice.
            – Circumscribe
            Nov 5 at 12:04












            @Circumscribe it uses partopsep as parskip in the par case and topsep as parskip in the no-par case, so by setting up those list parameters you can achieve (some) control over that
            – David Carlisle
            Nov 5 at 12:15






            @Circumscribe it uses partopsep as parskip in the par case and topsep as parskip in the no-par case, so by setting up those list parameters you can achieve (some) control over that
            – David Carlisle
            Nov 5 at 12:15














            @Circumscribe topsep=0pt isn't it? but something like that, yes, this is consistent with all other latex displays so hopefully packages like parskip which set things up for non zero parskip would automatically do the right thing here.
            – David Carlisle
            Nov 5 at 12:47




            @Circumscribe topsep=0pt isn't it? but something like that, yes, this is consistent with all other latex displays so hopefully packages like parskip which set things up for non zero parskip would automatically do the right thing here.
            – David Carlisle
            Nov 5 at 12:47




            2




            2




            Sorry, I had deleted my comment (before you had replied, I thought) because I wasn't sure about it anymore. For me setting partopsep=parskip and topsep=-parskip works. I think both parskip and topsep are always inserted (so this way they cancel out) and partopsep is only inserted when there is a preceding paragraph break.
            – Circumscribe
            Nov 5 at 12:57




            Sorry, I had deleted my comment (before you had replied, I thought) because I wasn't sure about it anymore. For me setting partopsep=parskip and topsep=-parskip works. I think both parskip and topsep are always inserted (so this way they cancel out) and partopsep is only inserted when there is a preceding paragraph break.
            – Circumscribe
            Nov 5 at 12:57












            @Circumscribe er yes that sounds about right:-)
            – David Carlisle
            Nov 5 at 13:02




            @Circumscribe er yes that sounds about right:-)
            – David Carlisle
            Nov 5 at 13:02










            up vote
            4
            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 (and themselves).



            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:



            documentclass{article}

            setlength{parskip}{50pt}

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

            makeatletter
            newcommand*tentativepar{%
            par
            savedparskipparskip %% <- store original parskip
            savedparindentparindent %% <- store original parindent
            expandaftersavedeveryparexpandafter{theeverypar}
            %% ^^ 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
            expandaftereveryparexpandafter{thesavedeverypar}%
            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
            expandaftereveryparexpandafter{thesavedeverypar}%
            parskipsavedparskip %% <- reset parskip
            parindentsavedparindent %% <- reset parindent
            }
            }
            makeatother

            newcommand{example}[1]{%
            ifvmodeelsetentativeparfi
            vspace{abovedisplayskip}
            noindentbegin{minipage}{.5linewidth}#1end{minipage}%
            vspace{belowdisplayskip}
            tentativepar
            }

            begin{document}

            AAA
            example{There should be small spaces after AAA and before BBB}
            BBB

            AAA

            example{There should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.}
            BBB

            AAA
            example{There should be a small space after AAA and a large one before BBB}

            BBB

            CCC

            end{document}


            Output






            share|improve this answer



























              up vote
              4
              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 (and themselves).



              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:



              documentclass{article}

              setlength{parskip}{50pt}

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

              makeatletter
              newcommand*tentativepar{%
              par
              savedparskipparskip %% <- store original parskip
              savedparindentparindent %% <- store original parindent
              expandaftersavedeveryparexpandafter{theeverypar}
              %% ^^ 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
              expandaftereveryparexpandafter{thesavedeverypar}%
              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
              expandaftereveryparexpandafter{thesavedeverypar}%
              parskipsavedparskip %% <- reset parskip
              parindentsavedparindent %% <- reset parindent
              }
              }
              makeatother

              newcommand{example}[1]{%
              ifvmodeelsetentativeparfi
              vspace{abovedisplayskip}
              noindentbegin{minipage}{.5linewidth}#1end{minipage}%
              vspace{belowdisplayskip}
              tentativepar
              }

              begin{document}

              AAA
              example{There should be small spaces after AAA and before BBB}
              BBB

              AAA

              example{There should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.}
              BBB

              AAA
              example{There should be a small space after AAA and a large one before BBB}

              BBB

              CCC

              end{document}


              Output






              share|improve this answer

























                up vote
                4
                down vote










                up vote
                4
                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 (and themselves).



                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:



                documentclass{article}

                setlength{parskip}{50pt}

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

                makeatletter
                newcommand*tentativepar{%
                par
                savedparskipparskip %% <- store original parskip
                savedparindentparindent %% <- store original parindent
                expandaftersavedeveryparexpandafter{theeverypar}
                %% ^^ 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
                expandaftereveryparexpandafter{thesavedeverypar}%
                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
                expandaftereveryparexpandafter{thesavedeverypar}%
                parskipsavedparskip %% <- reset parskip
                parindentsavedparindent %% <- reset parindent
                }
                }
                makeatother

                newcommand{example}[1]{%
                ifvmodeelsetentativeparfi
                vspace{abovedisplayskip}
                noindentbegin{minipage}{.5linewidth}#1end{minipage}%
                vspace{belowdisplayskip}
                tentativepar
                }

                begin{document}

                AAA
                example{There should be small spaces after AAA and before BBB}
                BBB

                AAA

                example{There should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.}
                BBB

                AAA
                example{There should be a small space after AAA and a large one before BBB}

                BBB

                CCC

                end{document}


                Output






                share|improve this answer














                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 (and themselves).



                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:



                documentclass{article}

                setlength{parskip}{50pt}

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

                makeatletter
                newcommand*tentativepar{%
                par
                savedparskipparskip %% <- store original parskip
                savedparindentparindent %% <- store original parindent
                expandaftersavedeveryparexpandafter{theeverypar}
                %% ^^ 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
                expandaftereveryparexpandafter{thesavedeverypar}%
                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
                expandaftereveryparexpandafter{thesavedeverypar}%
                parskipsavedparskip %% <- reset parskip
                parindentsavedparindent %% <- reset parindent
                }
                }
                makeatother

                newcommand{example}[1]{%
                ifvmodeelsetentativeparfi
                vspace{abovedisplayskip}
                noindentbegin{minipage}{.5linewidth}#1end{minipage}%
                vspace{belowdisplayskip}
                tentativepar
                }

                begin{document}

                AAA
                example{There should be small spaces after AAA and before BBB}
                BBB

                AAA

                example{There should be a large space after AAA and a small one before BBB. And BBB shouldn't be indented.}
                BBB

                AAA
                example{There should be a small space after AAA and a large one before BBB}

                BBB

                CCC

                end{document}


                Output







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 5 at 11:51

























                answered Nov 5 at 11:31









                Circumscribe

                2,4481324




                2,4481324






























                     

                    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




















































































                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini