How can I determine whether a custom environment is followed by a new paragraph?
up vote
11
down vote
favorite
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
add a comment |
up vote
11
down vote
favorite
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
add a comment |
up vote
11
down vote
favorite
up vote
11
down vote
favorite
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
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
spacing
asked Nov 5 at 6:56
Clément
1,7161530
1,7161530
add a comment |
add a comment |
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}
I believe this just inhibits paragraph indents, but not skips. If you enterwordbegin{center}centred wordsend{center}word, thenparskipis still inserted twice.
– Circumscribe
Nov 5 at 12:04
@Circumscribe it usespartopsepasparskipin theparcase andtopsepasparskipin the no-parcase, 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 likeparskipwhich 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 settingpartopsep=parskipandtopsep=-parskipworks. I think bothparskipandtopsepare always inserted (so this way they cancel out) andpartopsepis 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
|
show 2 more comments
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}

add a comment |
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}
I believe this just inhibits paragraph indents, but not skips. If you enterwordbegin{center}centred wordsend{center}word, thenparskipis still inserted twice.
– Circumscribe
Nov 5 at 12:04
@Circumscribe it usespartopsepasparskipin theparcase andtopsepasparskipin the no-parcase, 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 likeparskipwhich 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 settingpartopsep=parskipandtopsep=-parskipworks. I think bothparskipandtopsepare always inserted (so this way they cancel out) andpartopsepis 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
|
show 2 more comments
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}
I believe this just inhibits paragraph indents, but not skips. If you enterwordbegin{center}centred wordsend{center}word, thenparskipis still inserted twice.
– Circumscribe
Nov 5 at 12:04
@Circumscribe it usespartopsepasparskipin theparcase andtopsepasparskipin the no-parcase, 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 likeparskipwhich 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 settingpartopsep=parskipandtopsep=-parskipworks. I think bothparskipandtopsepare always inserted (so this way they cancel out) andpartopsepis 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
|
show 2 more comments
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}
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}
answered Nov 5 at 7:42
David Carlisle
475k3811061840
475k3811061840
I believe this just inhibits paragraph indents, but not skips. If you enterwordbegin{center}centred wordsend{center}word, thenparskipis still inserted twice.
– Circumscribe
Nov 5 at 12:04
@Circumscribe it usespartopsepasparskipin theparcase andtopsepasparskipin the no-parcase, 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 likeparskipwhich 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 settingpartopsep=parskipandtopsep=-parskipworks. I think bothparskipandtopsepare always inserted (so this way they cancel out) andpartopsepis 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
|
show 2 more comments
I believe this just inhibits paragraph indents, but not skips. If you enterwordbegin{center}centred wordsend{center}word, thenparskipis still inserted twice.
– Circumscribe
Nov 5 at 12:04
@Circumscribe it usespartopsepasparskipin theparcase andtopsepasparskipin the no-parcase, 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 likeparskipwhich 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 settingpartopsep=parskipandtopsep=-parskipworks. I think bothparskipandtopsepare always inserted (so this way they cancel out) andpartopsepis 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
|
show 2 more comments
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}

add a comment |
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}

add a comment |
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}

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}

edited Nov 5 at 11:51
answered Nov 5 at 11:31
Circumscribe
2,4481324
2,4481324
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password