Auto Detect Last Paragraph and Pass to Macro











up vote
3
down vote

favorite












The MWE below produces the desired results:




enter image description here




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.





  1. 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 to SetMyText to be of the form:



    SetMyText{%
    Other Text...

    LastParaBeginsHere
    Last Para Text%
    }%


    so that LastParaBeginsHere invokesProcessLastPara{Last Para Text}.



    This would need some error checking to make sure that LastParaBeginsHere really was indeed the last paragraph defined by SetMyText.



  2. 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 defLastParaBeginsHere{LastParShape} won't work as I need to process the last paragraph text to determine the appropriate parshape to apply. That is, this is a 2 step process, the details of which are not included here to simplify the test case.


Code:



documentclass{article}

usepackage[paperwidth=15cm]{geometry}

makeatletter
newcommand{@MyText}{}
newcommand{SetMyText}[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}%

begin{document}
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%
end{document}









share|improve this question






















  • 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
    2 hours ago















up vote
3
down vote

favorite












The MWE below produces the desired results:




enter image description here




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.





  1. 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 to SetMyText to be of the form:



    SetMyText{%
    Other Text...

    LastParaBeginsHere
    Last Para Text%
    }%


    so that LastParaBeginsHere invokesProcessLastPara{Last Para Text}.



    This would need some error checking to make sure that LastParaBeginsHere really was indeed the last paragraph defined by SetMyText.



  2. 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 defLastParaBeginsHere{LastParShape} won't work as I need to process the last paragraph text to determine the appropriate parshape to apply. That is, this is a 2 step process, the details of which are not included here to simplify the test case.


Code:



documentclass{article}

usepackage[paperwidth=15cm]{geometry}

makeatletter
newcommand{@MyText}{}
newcommand{SetMyText}[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}%

begin{document}
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%
end{document}









share|improve this question






















  • 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
    2 hours ago













up vote
3
down vote

favorite









up vote
3
down vote

favorite











The MWE below produces the desired results:




enter image description here




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.





  1. 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 to SetMyText to be of the form:



    SetMyText{%
    Other Text...

    LastParaBeginsHere
    Last Para Text%
    }%


    so that LastParaBeginsHere invokesProcessLastPara{Last Para Text}.



    This would need some error checking to make sure that LastParaBeginsHere really was indeed the last paragraph defined by SetMyText.



  2. 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 defLastParaBeginsHere{LastParShape} won't work as I need to process the last paragraph text to determine the appropriate parshape to apply. That is, this is a 2 step process, the details of which are not included here to simplify the test case.


Code:



documentclass{article}

usepackage[paperwidth=15cm]{geometry}

makeatletter
newcommand{@MyText}{}
newcommand{SetMyText}[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}%

begin{document}
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%
end{document}









share|improve this question













The MWE below produces the desired results:




enter image description here




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.





  1. 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 to SetMyText to be of the form:



    SetMyText{%
    Other Text...

    LastParaBeginsHere
    Last Para Text%
    }%


    so that LastParaBeginsHere invokesProcessLastPara{Last Para Text}.



    This would need some error checking to make sure that LastParaBeginsHere really was indeed the last paragraph defined by SetMyText.



  2. 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 defLastParaBeginsHere{LastParShape} won't work as I need to process the last paragraph text to determine the appropriate parshape to apply. That is, this is a 2 step process, the details of which are not included here to simplify the test case.


Code:



documentclass{article}

usepackage[paperwidth=15cm]{geometry}

makeatletter
newcommand{@MyText}{}
newcommand{SetMyText}[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}%

begin{document}
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%
end{document}






macros line-breaking paragraphs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









Peter Grill

163k24432744




163k24432744












  • 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
    2 hours ago


















  • 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
    2 hours ago
















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
2 hours ago




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
2 hours ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote













documentclass{article}

usepackage[paperwidth=15cm]{geometry}

makeatletter
newcommand{@MyText}{}
newcommand{SetMyText}[1]{def@MyText{#1LastParShapepar}}%
newcommand*{OutputMyText}{@MyText}%
makeatother

newcommand*{LastParShape}{%
parshape 5
dimexpr0.10hsize-parindentrelax 0.80hsize
0.15hsize 0.70hsize
0.20hsize 0.60hsize
0.25hsize 0.50hsize
0.30hsize 0.40hsize
}%



begin{document}
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%
end{document}


enter image description here






share|improve this answer

















  • 1




    I didn't even need egreg's hat.
    – David Carlisle
    2 hours ago


















up vote
1
down vote













It's quite easy with expl3: collect the text, split it at par, then detach the last paragraph and typeset it separately.



documentclass{article}
usepackage[paperwidth=15cm]{geometry}
usepackage{xparse}

ExplSyntaxOn
NewDocumentCommand{SetMyText}{s+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

NewDocumentCommand{OutputMyText}{}
{
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
}

begin{document}

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

end{document}


enter image description here






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%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








    up vote
    2
    down vote













    documentclass{article}

    usepackage[paperwidth=15cm]{geometry}

    makeatletter
    newcommand{@MyText}{}
    newcommand{SetMyText}[1]{def@MyText{#1LastParShapepar}}%
    newcommand*{OutputMyText}{@MyText}%
    makeatother

    newcommand*{LastParShape}{%
    parshape 5
    dimexpr0.10hsize-parindentrelax 0.80hsize
    0.15hsize 0.70hsize
    0.20hsize 0.60hsize
    0.25hsize 0.50hsize
    0.30hsize 0.40hsize
    }%



    begin{document}
    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%
    end{document}


    enter image description here






    share|improve this answer

















    • 1




      I didn't even need egreg's hat.
      – David Carlisle
      2 hours ago















    up vote
    2
    down vote













    documentclass{article}

    usepackage[paperwidth=15cm]{geometry}

    makeatletter
    newcommand{@MyText}{}
    newcommand{SetMyText}[1]{def@MyText{#1LastParShapepar}}%
    newcommand*{OutputMyText}{@MyText}%
    makeatother

    newcommand*{LastParShape}{%
    parshape 5
    dimexpr0.10hsize-parindentrelax 0.80hsize
    0.15hsize 0.70hsize
    0.20hsize 0.60hsize
    0.25hsize 0.50hsize
    0.30hsize 0.40hsize
    }%



    begin{document}
    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%
    end{document}


    enter image description here






    share|improve this answer

















    • 1




      I didn't even need egreg's hat.
      – David Carlisle
      2 hours ago













    up vote
    2
    down vote










    up vote
    2
    down vote









    documentclass{article}

    usepackage[paperwidth=15cm]{geometry}

    makeatletter
    newcommand{@MyText}{}
    newcommand{SetMyText}[1]{def@MyText{#1LastParShapepar}}%
    newcommand*{OutputMyText}{@MyText}%
    makeatother

    newcommand*{LastParShape}{%
    parshape 5
    dimexpr0.10hsize-parindentrelax 0.80hsize
    0.15hsize 0.70hsize
    0.20hsize 0.60hsize
    0.25hsize 0.50hsize
    0.30hsize 0.40hsize
    }%



    begin{document}
    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%
    end{document}


    enter image description here






    share|improve this answer












    documentclass{article}

    usepackage[paperwidth=15cm]{geometry}

    makeatletter
    newcommand{@MyText}{}
    newcommand{SetMyText}[1]{def@MyText{#1LastParShapepar}}%
    newcommand*{OutputMyText}{@MyText}%
    makeatother

    newcommand*{LastParShape}{%
    parshape 5
    dimexpr0.10hsize-parindentrelax 0.80hsize
    0.15hsize 0.70hsize
    0.20hsize 0.60hsize
    0.25hsize 0.50hsize
    0.30hsize 0.40hsize
    }%



    begin{document}
    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%
    end{document}


    enter image description here







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 2 hours ago









    David Carlisle

    480k3811121848




    480k3811121848








    • 1




      I didn't even need egreg's hat.
      – David Carlisle
      2 hours ago














    • 1




      I didn't even need egreg's hat.
      – David Carlisle
      2 hours ago








    1




    1




    I didn't even need egreg's hat.
    – David Carlisle
    2 hours ago




    I didn't even need egreg's hat.
    – David Carlisle
    2 hours ago










    up vote
    1
    down vote













    It's quite easy with expl3: collect the text, split it at par, then detach the last paragraph and typeset it separately.



    documentclass{article}
    usepackage[paperwidth=15cm]{geometry}
    usepackage{xparse}

    ExplSyntaxOn
    NewDocumentCommand{SetMyText}{s+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

    NewDocumentCommand{OutputMyText}{}
    {
    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
    }

    begin{document}

    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

    end{document}


    enter image description here






    share|improve this answer

























      up vote
      1
      down vote













      It's quite easy with expl3: collect the text, split it at par, then detach the last paragraph and typeset it separately.



      documentclass{article}
      usepackage[paperwidth=15cm]{geometry}
      usepackage{xparse}

      ExplSyntaxOn
      NewDocumentCommand{SetMyText}{s+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

      NewDocumentCommand{OutputMyText}{}
      {
      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
      }

      begin{document}

      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

      end{document}


      enter image description here






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        It's quite easy with expl3: collect the text, split it at par, then detach the last paragraph and typeset it separately.



        documentclass{article}
        usepackage[paperwidth=15cm]{geometry}
        usepackage{xparse}

        ExplSyntaxOn
        NewDocumentCommand{SetMyText}{s+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

        NewDocumentCommand{OutputMyText}{}
        {
        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
        }

        begin{document}

        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

        end{document}


        enter image description here






        share|improve this answer












        It's quite easy with expl3: collect the text, split it at par, then detach the last paragraph and typeset it separately.



        documentclass{article}
        usepackage[paperwidth=15cm]{geometry}
        usepackage{xparse}

        ExplSyntaxOn
        NewDocumentCommand{SetMyText}{s+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

        NewDocumentCommand{OutputMyText}{}
        {
        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
        }

        begin{document}

        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

        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        egreg

        704k8618753154




        704k8618753154






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            How to ignore python UserWarning in pytest?

            Alexandru Averescu