Auto Detect Last Paragraph and Pass to Macro
Clash Royale CLAN TAG#URR8PPP
The MWE below produces the desired results:
via the ProcessLastPara
which applies a desired parshape
to the given (last) paragraph.
Questions:
The MWE below required me to manually identify both the start and end of the last paragraph so it could be passed on to the ProcessLastPara
macro.
Is it possible to achieve the effect of
ProcessLastPara<text>
by simply identifying the beginning of the last paragraph. That is, can I change the call toSetMyText
to be of the form:SetMyText%
Other Text...
LastParaBeginsHere
Last Para Text%
%so that
LastParaBeginsHere
invokesProcessLastParaLast Para Text
.This would need some error checking to make sure that
LastParaBeginsHere
really was indeed the last paragraph defined bySetMyText
.Is it possible to auto detect where the last paragraph begins and ends so that I do not need to manually invoke
ProcessLastPara
and identify the text of the last paragraph?
Notes:
- This needs to work for the case where the text is defined in a macro before it is typeset.
- The solution of
defLastParaBeginsHereLastParShape
won't work as I need to process the last paragraph text to determine the appropriateparshape
to apply. That is, this is a 2 step process, the details of which are not included here to simplify the test case.
Code:
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
newcommand*ProcessLastPara[1]%
LastParShape
#1%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
ProcessLastPara%
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
macros line-breaking paragraphs
add a comment |
The MWE below produces the desired results:
via the ProcessLastPara
which applies a desired parshape
to the given (last) paragraph.
Questions:
The MWE below required me to manually identify both the start and end of the last paragraph so it could be passed on to the ProcessLastPara
macro.
Is it possible to achieve the effect of
ProcessLastPara<text>
by simply identifying the beginning of the last paragraph. That is, can I change the call toSetMyText
to be of the form:SetMyText%
Other Text...
LastParaBeginsHere
Last Para Text%
%so that
LastParaBeginsHere
invokesProcessLastParaLast Para Text
.This would need some error checking to make sure that
LastParaBeginsHere
really was indeed the last paragraph defined bySetMyText
.Is it possible to auto detect where the last paragraph begins and ends so that I do not need to manually invoke
ProcessLastPara
and identify the text of the last paragraph?
Notes:
- This needs to work for the case where the text is defined in a macro before it is typeset.
- The solution of
defLastParaBeginsHereLastParShape
won't work as I need to process the last paragraph text to determine the appropriateparshape
to apply. That is, this is a 2 step process, the details of which are not included here to simplify the test case.
Code:
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
newcommand*ProcessLastPara[1]%
LastParShape
#1%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
ProcessLastPara%
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
macros line-breaking paragraphs
do you want the para indent on the first line of your triangle, I cancelled it out (not quite correctly) in my answer but I could remove it to get the same shape that you and egreg show...
– David Carlisle
Dec 12 at 9:15
@DavidCarlisle: Removing indentation of the last para is preferrable.
– Peter Grill
Dec 12 at 17:59
add a comment |
The MWE below produces the desired results:
via the ProcessLastPara
which applies a desired parshape
to the given (last) paragraph.
Questions:
The MWE below required me to manually identify both the start and end of the last paragraph so it could be passed on to the ProcessLastPara
macro.
Is it possible to achieve the effect of
ProcessLastPara<text>
by simply identifying the beginning of the last paragraph. That is, can I change the call toSetMyText
to be of the form:SetMyText%
Other Text...
LastParaBeginsHere
Last Para Text%
%so that
LastParaBeginsHere
invokesProcessLastParaLast Para Text
.This would need some error checking to make sure that
LastParaBeginsHere
really was indeed the last paragraph defined bySetMyText
.Is it possible to auto detect where the last paragraph begins and ends so that I do not need to manually invoke
ProcessLastPara
and identify the text of the last paragraph?
Notes:
- This needs to work for the case where the text is defined in a macro before it is typeset.
- The solution of
defLastParaBeginsHereLastParShape
won't work as I need to process the last paragraph text to determine the appropriateparshape
to apply. That is, this is a 2 step process, the details of which are not included here to simplify the test case.
Code:
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
newcommand*ProcessLastPara[1]%
LastParShape
#1%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
ProcessLastPara%
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
macros line-breaking paragraphs
The MWE below produces the desired results:
via the ProcessLastPara
which applies a desired parshape
to the given (last) paragraph.
Questions:
The MWE below required me to manually identify both the start and end of the last paragraph so it could be passed on to the ProcessLastPara
macro.
Is it possible to achieve the effect of
ProcessLastPara<text>
by simply identifying the beginning of the last paragraph. That is, can I change the call toSetMyText
to be of the form:SetMyText%
Other Text...
LastParaBeginsHere
Last Para Text%
%so that
LastParaBeginsHere
invokesProcessLastParaLast Para Text
.This would need some error checking to make sure that
LastParaBeginsHere
really was indeed the last paragraph defined bySetMyText
.Is it possible to auto detect where the last paragraph begins and ends so that I do not need to manually invoke
ProcessLastPara
and identify the text of the last paragraph?
Notes:
- This needs to work for the case where the text is defined in a macro before it is typeset.
- The solution of
defLastParaBeginsHereLastParShape
won't work as I need to process the last paragraph text to determine the appropriateparshape
to apply. That is, this is a 2 step process, the details of which are not included here to simplify the test case.
Code:
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
newcommand*ProcessLastPara[1]%
LastParShape
#1%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
ProcessLastPara%
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
macros line-breaking paragraphs
macros line-breaking paragraphs
asked Dec 12 at 7:43
Peter Grill
163k25434745
163k25434745
do you want the para indent on the first line of your triangle, I cancelled it out (not quite correctly) in my answer but I could remove it to get the same shape that you and egreg show...
– David Carlisle
Dec 12 at 9:15
@DavidCarlisle: Removing indentation of the last para is preferrable.
– Peter Grill
Dec 12 at 17:59
add a comment |
do you want the para indent on the first line of your triangle, I cancelled it out (not quite correctly) in my answer but I could remove it to get the same shape that you and egreg show...
– David Carlisle
Dec 12 at 9:15
@DavidCarlisle: Removing indentation of the last para is preferrable.
– Peter Grill
Dec 12 at 17:59
do you want the para indent on the first line of your triangle, I cancelled it out (not quite correctly) in my answer but I could remove it to get the same shape that you and egreg show...
– David Carlisle
Dec 12 at 9:15
do you want the para indent on the first line of your triangle, I cancelled it out (not quite correctly) in my answer but I could remove it to get the same shape that you and egreg show...
– David Carlisle
Dec 12 at 9:15
@DavidCarlisle: Removing indentation of the last para is preferrable.
– Peter Grill
Dec 12 at 17:59
@DavidCarlisle: Removing indentation of the last para is preferrable.
– Peter Grill
Dec 12 at 17:59
add a comment |
2 Answers
2
active
oldest
votes
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1LastParShapepar%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
dimexpr0.10hsize-parindentrelax dimexpr0.80hsize+parindentrelax
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
1
I didn't even need egreg's hat.
– David Carlisle
Dec 12 at 9:10
What kind of sorcery is this? You can specify theparhsape
after the paragraph (ie, after the#1
inSetMyText
)? However, this won't work as per second point in the Notes. I need the content of the last paragraph to be passed toProcessLastPara
as a parameter so that I can determine the correctparshape
to apply.
– Peter Grill
Dec 12 at 17:58
@PeterGrill I saw that note but decided just to answer the question as asked, as I wanted to demonstrate this (which uses a few orders of magnitude fewer macro expansions than egreg's:-) (you could of course add anoindent
to the code in your question and egreg's answer to get the full length top row.
– David Carlisle
Dec 12 at 18:45
1
@DavidCarlisle Very nice and concise answer, but I'm really confused by putting theLastParShape
after#1
. I wish you would have time to explain more about it.
– javadr
Dec 12 at 19:12
2
@javadr paragraph settings, whetherparshape
orcentering
etc use the settings in force at the end of the paragraph, which is why you often see on this site warnings thatcentering hello
does not center as the settings are discarded butcentering hellopar
does center, as doesnoindent hellocenteringpar
setting the parshape is the same, it sets the linebreaking but is not consulted until tex starts linebreaking which is at the end of the paragraph.
– David Carlisle
Dec 12 at 19:44
|
show 5 more comments
It's quite easy with expl3
: collect the text, split it at par
, then detach the last paragraph and typeset it separately.
documentclassarticle
usepackage[paperwidth=15cm]geometry
usepackagexparse
ExplSyntaxOn
NewDocumentCommandSetMyTexts+m
IfBooleanTF#1
seq_set_split:NnV l_peter_mytext_seq par #2
seq_set_split:Nnn l_peter_mytext_seq par #2
cs_generate_variant:Nn seq_set_split:Nnn NnV
seq_new:N l_peter_mytext_seq
tl_new:N l_peter_mytext_tl
NewDocumentCommandOutputMyText
seq_pop_right:NN l_peter_mytext_seq l_peter_mytext_tl
seq_use:Nn l_peter_mytext_seq par par
LastParShape l_peter_mytext_tl
ExplSyntaxOff
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
begindocument
SetMyText
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
OutputMyText
enddocument
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464468%2fauto-detect-last-paragraph-and-pass-to-macro%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1LastParShapepar%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
dimexpr0.10hsize-parindentrelax dimexpr0.80hsize+parindentrelax
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
1
I didn't even need egreg's hat.
– David Carlisle
Dec 12 at 9:10
What kind of sorcery is this? You can specify theparhsape
after the paragraph (ie, after the#1
inSetMyText
)? However, this won't work as per second point in the Notes. I need the content of the last paragraph to be passed toProcessLastPara
as a parameter so that I can determine the correctparshape
to apply.
– Peter Grill
Dec 12 at 17:58
@PeterGrill I saw that note but decided just to answer the question as asked, as I wanted to demonstrate this (which uses a few orders of magnitude fewer macro expansions than egreg's:-) (you could of course add anoindent
to the code in your question and egreg's answer to get the full length top row.
– David Carlisle
Dec 12 at 18:45
1
@DavidCarlisle Very nice and concise answer, but I'm really confused by putting theLastParShape
after#1
. I wish you would have time to explain more about it.
– javadr
Dec 12 at 19:12
2
@javadr paragraph settings, whetherparshape
orcentering
etc use the settings in force at the end of the paragraph, which is why you often see on this site warnings thatcentering hello
does not center as the settings are discarded butcentering hellopar
does center, as doesnoindent hellocenteringpar
setting the parshape is the same, it sets the linebreaking but is not consulted until tex starts linebreaking which is at the end of the paragraph.
– David Carlisle
Dec 12 at 19:44
|
show 5 more comments
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1LastParShapepar%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
dimexpr0.10hsize-parindentrelax dimexpr0.80hsize+parindentrelax
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
1
I didn't even need egreg's hat.
– David Carlisle
Dec 12 at 9:10
What kind of sorcery is this? You can specify theparhsape
after the paragraph (ie, after the#1
inSetMyText
)? However, this won't work as per second point in the Notes. I need the content of the last paragraph to be passed toProcessLastPara
as a parameter so that I can determine the correctparshape
to apply.
– Peter Grill
Dec 12 at 17:58
@PeterGrill I saw that note but decided just to answer the question as asked, as I wanted to demonstrate this (which uses a few orders of magnitude fewer macro expansions than egreg's:-) (you could of course add anoindent
to the code in your question and egreg's answer to get the full length top row.
– David Carlisle
Dec 12 at 18:45
1
@DavidCarlisle Very nice and concise answer, but I'm really confused by putting theLastParShape
after#1
. I wish you would have time to explain more about it.
– javadr
Dec 12 at 19:12
2
@javadr paragraph settings, whetherparshape
orcentering
etc use the settings in force at the end of the paragraph, which is why you often see on this site warnings thatcentering hello
does not center as the settings are discarded butcentering hellopar
does center, as doesnoindent hellocenteringpar
setting the parshape is the same, it sets the linebreaking but is not consulted until tex starts linebreaking which is at the end of the paragraph.
– David Carlisle
Dec 12 at 19:44
|
show 5 more comments
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1LastParShapepar%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
dimexpr0.10hsize-parindentrelax dimexpr0.80hsize+parindentrelax
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
documentclassarticle
usepackage[paperwidth=15cm]geometry
makeatletter
newcommand@MyText
newcommandSetMyText[1]def@MyText#1LastParShapepar%
newcommand*OutputMyText@MyText%
makeatother
newcommand*LastParShape%
parshape 5
dimexpr0.10hsize-parindentrelax dimexpr0.80hsize+parindentrelax
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
%
begindocument
SetMyText%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.%
%
%% ----------------
OutputMyText%
enddocument
edited Dec 12 at 18:49
answered Dec 12 at 9:10
David Carlisle
481k3811121848
481k3811121848
1
I didn't even need egreg's hat.
– David Carlisle
Dec 12 at 9:10
What kind of sorcery is this? You can specify theparhsape
after the paragraph (ie, after the#1
inSetMyText
)? However, this won't work as per second point in the Notes. I need the content of the last paragraph to be passed toProcessLastPara
as a parameter so that I can determine the correctparshape
to apply.
– Peter Grill
Dec 12 at 17:58
@PeterGrill I saw that note but decided just to answer the question as asked, as I wanted to demonstrate this (which uses a few orders of magnitude fewer macro expansions than egreg's:-) (you could of course add anoindent
to the code in your question and egreg's answer to get the full length top row.
– David Carlisle
Dec 12 at 18:45
1
@DavidCarlisle Very nice and concise answer, but I'm really confused by putting theLastParShape
after#1
. I wish you would have time to explain more about it.
– javadr
Dec 12 at 19:12
2
@javadr paragraph settings, whetherparshape
orcentering
etc use the settings in force at the end of the paragraph, which is why you often see on this site warnings thatcentering hello
does not center as the settings are discarded butcentering hellopar
does center, as doesnoindent hellocenteringpar
setting the parshape is the same, it sets the linebreaking but is not consulted until tex starts linebreaking which is at the end of the paragraph.
– David Carlisle
Dec 12 at 19:44
|
show 5 more comments
1
I didn't even need egreg's hat.
– David Carlisle
Dec 12 at 9:10
What kind of sorcery is this? You can specify theparhsape
after the paragraph (ie, after the#1
inSetMyText
)? However, this won't work as per second point in the Notes. I need the content of the last paragraph to be passed toProcessLastPara
as a parameter so that I can determine the correctparshape
to apply.
– Peter Grill
Dec 12 at 17:58
@PeterGrill I saw that note but decided just to answer the question as asked, as I wanted to demonstrate this (which uses a few orders of magnitude fewer macro expansions than egreg's:-) (you could of course add anoindent
to the code in your question and egreg's answer to get the full length top row.
– David Carlisle
Dec 12 at 18:45
1
@DavidCarlisle Very nice and concise answer, but I'm really confused by putting theLastParShape
after#1
. I wish you would have time to explain more about it.
– javadr
Dec 12 at 19:12
2
@javadr paragraph settings, whetherparshape
orcentering
etc use the settings in force at the end of the paragraph, which is why you often see on this site warnings thatcentering hello
does not center as the settings are discarded butcentering hellopar
does center, as doesnoindent hellocenteringpar
setting the parshape is the same, it sets the linebreaking but is not consulted until tex starts linebreaking which is at the end of the paragraph.
– David Carlisle
Dec 12 at 19:44
1
1
I didn't even need egreg's hat.
– David Carlisle
Dec 12 at 9:10
I didn't even need egreg's hat.
– David Carlisle
Dec 12 at 9:10
What kind of sorcery is this? You can specify the
parhsape
after the paragraph (ie, after the #1
in SetMyText
)? However, this won't work as per second point in the Notes. I need the content of the last paragraph to be passed to ProcessLastPara
as a parameter so that I can determine the correct parshape
to apply.– Peter Grill
Dec 12 at 17:58
What kind of sorcery is this? You can specify the
parhsape
after the paragraph (ie, after the #1
in SetMyText
)? However, this won't work as per second point in the Notes. I need the content of the last paragraph to be passed to ProcessLastPara
as a parameter so that I can determine the correct parshape
to apply.– Peter Grill
Dec 12 at 17:58
@PeterGrill I saw that note but decided just to answer the question as asked, as I wanted to demonstrate this (which uses a few orders of magnitude fewer macro expansions than egreg's:-) (you could of course add a
noindent
to the code in your question and egreg's answer to get the full length top row.– David Carlisle
Dec 12 at 18:45
@PeterGrill I saw that note but decided just to answer the question as asked, as I wanted to demonstrate this (which uses a few orders of magnitude fewer macro expansions than egreg's:-) (you could of course add a
noindent
to the code in your question and egreg's answer to get the full length top row.– David Carlisle
Dec 12 at 18:45
1
1
@DavidCarlisle Very nice and concise answer, but I'm really confused by putting the
LastParShape
after #1
. I wish you would have time to explain more about it.– javadr
Dec 12 at 19:12
@DavidCarlisle Very nice and concise answer, but I'm really confused by putting the
LastParShape
after #1
. I wish you would have time to explain more about it.– javadr
Dec 12 at 19:12
2
2
@javadr paragraph settings, whether
parshape
or centering
etc use the settings in force at the end of the paragraph, which is why you often see on this site warnings that centering hello
does not center as the settings are discarded but centering hellopar
does center, as does noindent hellocenteringpar
setting the parshape is the same, it sets the linebreaking but is not consulted until tex starts linebreaking which is at the end of the paragraph.– David Carlisle
Dec 12 at 19:44
@javadr paragraph settings, whether
parshape
or centering
etc use the settings in force at the end of the paragraph, which is why you often see on this site warnings that centering hello
does not center as the settings are discarded but centering hellopar
does center, as does noindent hellocenteringpar
setting the parshape is the same, it sets the linebreaking but is not consulted until tex starts linebreaking which is at the end of the paragraph.– David Carlisle
Dec 12 at 19:44
|
show 5 more comments
It's quite easy with expl3
: collect the text, split it at par
, then detach the last paragraph and typeset it separately.
documentclassarticle
usepackage[paperwidth=15cm]geometry
usepackagexparse
ExplSyntaxOn
NewDocumentCommandSetMyTexts+m
IfBooleanTF#1
seq_set_split:NnV l_peter_mytext_seq par #2
seq_set_split:Nnn l_peter_mytext_seq par #2
cs_generate_variant:Nn seq_set_split:Nnn NnV
seq_new:N l_peter_mytext_seq
tl_new:N l_peter_mytext_tl
NewDocumentCommandOutputMyText
seq_pop_right:NN l_peter_mytext_seq l_peter_mytext_tl
seq_use:Nn l_peter_mytext_seq par par
LastParShape l_peter_mytext_tl
ExplSyntaxOff
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
begindocument
SetMyText
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
OutputMyText
enddocument
add a comment |
It's quite easy with expl3
: collect the text, split it at par
, then detach the last paragraph and typeset it separately.
documentclassarticle
usepackage[paperwidth=15cm]geometry
usepackagexparse
ExplSyntaxOn
NewDocumentCommandSetMyTexts+m
IfBooleanTF#1
seq_set_split:NnV l_peter_mytext_seq par #2
seq_set_split:Nnn l_peter_mytext_seq par #2
cs_generate_variant:Nn seq_set_split:Nnn NnV
seq_new:N l_peter_mytext_seq
tl_new:N l_peter_mytext_tl
NewDocumentCommandOutputMyText
seq_pop_right:NN l_peter_mytext_seq l_peter_mytext_tl
seq_use:Nn l_peter_mytext_seq par par
LastParShape l_peter_mytext_tl
ExplSyntaxOff
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
begindocument
SetMyText
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
OutputMyText
enddocument
add a comment |
It's quite easy with expl3
: collect the text, split it at par
, then detach the last paragraph and typeset it separately.
documentclassarticle
usepackage[paperwidth=15cm]geometry
usepackagexparse
ExplSyntaxOn
NewDocumentCommandSetMyTexts+m
IfBooleanTF#1
seq_set_split:NnV l_peter_mytext_seq par #2
seq_set_split:Nnn l_peter_mytext_seq par #2
cs_generate_variant:Nn seq_set_split:Nnn NnV
seq_new:N l_peter_mytext_seq
tl_new:N l_peter_mytext_tl
NewDocumentCommandOutputMyText
seq_pop_right:NN l_peter_mytext_seq l_peter_mytext_tl
seq_use:Nn l_peter_mytext_seq par par
LastParShape l_peter_mytext_tl
ExplSyntaxOff
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
begindocument
SetMyText
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
OutputMyText
enddocument
It's quite easy with expl3
: collect the text, split it at par
, then detach the last paragraph and typeset it separately.
documentclassarticle
usepackage[paperwidth=15cm]geometry
usepackagexparse
ExplSyntaxOn
NewDocumentCommandSetMyTexts+m
IfBooleanTF#1
seq_set_split:NnV l_peter_mytext_seq par #2
seq_set_split:Nnn l_peter_mytext_seq par #2
cs_generate_variant:Nn seq_set_split:Nnn NnV
seq_new:N l_peter_mytext_seq
tl_new:N l_peter_mytext_tl
NewDocumentCommandOutputMyText
seq_pop_right:NN l_peter_mytext_seq l_peter_mytext_tl
seq_use:Nn l_peter_mytext_seq par par
LastParShape l_peter_mytext_tl
ExplSyntaxOff
newcommand*LastParShape%
parshape 5
0.10hsize 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
begindocument
SetMyText
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
OutputMyText
enddocument
answered Dec 12 at 8:49
egreg
706k8618783160
706k8618783160
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464468%2fauto-detect-last-paragraph-and-pass-to-macro%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do you want the para indent on the first line of your triangle, I cancelled it out (not quite correctly) in my answer but I could remove it to get the same shape that you and egreg show...
– David Carlisle
Dec 12 at 9:15
@DavidCarlisle: Removing indentation of the last para is preferrable.
– Peter Grill
Dec 12 at 17:59