2

I have a lot of documents witch all have to share the same last text.

But this text have to follow the last sentence immediately — without line break —.

I try to modify the document environment but it doesn’t work because I have a line-break.

So, this is an example of the code I want to compile with xelatex:

\documentclass{article}

\thelasttext{\textbf{(this the last text)}}

\begin{document}

Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et,
tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna,
vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse
ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et
magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt urna.
Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris.
Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at,
tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy
pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa
ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Mae-
cenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum.
Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia
nulla vitae enim. Pellentesque tincidunt purus vel magna. Integer non enim.
Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cur-
sus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum
pellentesque felis eu massa.
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus
tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In
hac habitasse platea dictumst. Integer tempus convallis augue. Etiam facilisis.
Nunc elementum fermentum wisi. Aenean placerat. Ut imperdiet, enim sed
gravida sollicitudin, felis odio placerat quam, ac pulvinar elit purus eget enim.
Nunc vitae tortor. Proin tempus nibh sit amet nisl. Vivamus quis tortor vitae 

\end{document}

And this is the rendering I expect:enter image description here

As you see, I wonder the text I set on \thelasttext variable follow immediately and in the same line the last sentence. That’s why the redefinition of document environment isn’t exactly the solution.

So, is it possible to that with xelatex? and how?

Edit: Expliciting the need of xelatex.

  • 2
    If you can live with no white space between the last sentence and \end{document}, then \AtEndDocument{\textbf{(this the last text)}} in the preamble should do it. – Mike Renfro Jun 25 '16 at 2:24
  • 1
    Yes… but that’s exactly the point, I can’t every-time be sure that no white space will be between the last sentence and \end{document}. – fauve Jun 25 '16 at 3:44
  • This discussion may help (to clarify, not to solve) : [stackoverflow.com/questions/1311991/latex-avoid-new-paragraph] – Christoph Frings Jun 25 '16 at 9:30
  • 2
    the previous paragraph has already been broken into lines if you have blank line before the end, adding additional text would change the linebreaking of the whole paragraph, there is no way to do this in TeX. – David Carlisle Jun 25 '16 at 9:48
  • So, @DavidCarlisle there is no way to del the suppress the last broken lines? A command like \delprevious witch I’ll can put before \end{document}, by modifying the document environment? – fauve Jun 25 '16 at 15:17
1

You can try to experiment with this:

\newwrite\tmpfile  \newcount\numpar  \newcount\numpars

\openin10=\jobname.num
\ifeof10 \numpars=-1 \else \closein10 \numpars=\input\jobname.num \relax \fi
\immediate\openout\tmpfile=\jobname.num

\def\thelasttext{{\bf (The last blaf.)}}

\def\par{\ifhmode 
     \global\advance\numpar by1 
     \ifnum\numpar=\numpars \thelasttext \fi 
     \endgraf 
  \fi
}
\def\bye{\par \immediate\write\tmpfile{\the\numpar}\penalty0\end}

First paragraph. Ruerrhv lnss ks.

Second. Mfffkl kjd s sf.

Last. Nsf sjkvf jkf fffbfd.

\bye

The external file \jobname.num is used. The number of paragraphs in the document is saved here. Of course, you must to process the document twice if you need to see the effect.

The \bye macro (or \end{document} in your case, where \AtEndDocument is declared as \par\immediate\write\tmpfile{\the\numpar}) can have empty line immediately before it but this is not explicitly needed.

0

Another alternative that might work if the document is simple, and if packages and kernel does the right job when saving/restoring the definition of \par. Which is not probable.

\def\thelasttext{\textbf{(this the last text)}}
\let\savedpar\par
\protected\def\par{\futurelet\tmp\editedpar}
\protected\def\editedpar
  {\ifx\tmp\end\expandafter\editedparcheckend\else\expandafter\savedpar\fi}
\protected\def\editedparcheckend\end#1%
  {\def\tmpa{#1}\def\tmpb{document}\ifx\tmpa\tmpb
   \thelasttext\let\thelasttext\relax\fi\savedpar\end{#1}}
\AtEndDocument{\thelasttext}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.