3

How do I add a line break after each sentence in the text? Preferably without altering the text too much because I have to be able to reuse the text in other cases where I don't want this behavior.

I've tried using inserting a line break in the source after each sentence and then turning on \obeylines but this makes each sentence into its own paragraph. I only want a new line (something like \\) not a new paragraph. This got me looking for the definition of \obeylines (which I got from share) so that I could define an alternative version which made use of \\ instead of \par. However, that doesn't seem to change its behavior at all. Any hints as to what I'm doing wrong (or if there is a better approach)?

\documentclass[12pt]{report}

\usepackage{fullpage}

\def\myobeylines{\catcode\endlinechar\active \let \endlinechar\\ }

\newenvironment{speech}%
    {%begin
        \Large
        \setlength{\parskip}{\baselineskip}
        \setlength{\parindent}{-1cm}
        \setlength{\leftmargin}{1cm}
        \myobeylines
    }
    {%end
    }

\begin{document}

\begin{speech}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed faucibus, sem vel suscipit eleifend, ipsum dolor tempus nunc, ut iaculis nibh arcu vitae tortor.
Pellentesque a efficitur lectus, eget sagittis lorem.
Fusce vestibulum feugiat nibh, pulvinar convallis eros sagittis ac.
Pellentesque aliquam arcu a augue malesuada, sit amet eleifend orci vulputate.
Sed nibh dolor, commodo vel risus quis, elementum consequat dui.
Pellentesque eu neque eleifend, tincidunt mauris id, ultricies odio.
Aenean ac nisi congue, mollis leo a, cursus dolor.
Aenean non justo felis.
Cras interdum quam eu metus imperdiet ultricies.
Fusce finibus pellentesque volutpat.
Praesent id lacus eget dui ullamcorper finibus nec nec urna.
Quisque vel vestibulum quam.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Mauris vel nisl eros.
\end{speech}

\end{document}
5
  • I'm a bit confused. Doesn't setting \parskip to 0pt in your environment do what you want? – Alan Munn Sep 27 '18 at 2:34
  • I need the extra space between paragraphs inside the environment. I simply didn't include a second paragraph in the sample in order to keep it shorter. – rpspringuel Sep 27 '18 at 2:49
  • An alternative then might be to keep it at 0pt, use \obeylines and then use a custom \par, e.g., \def\mypar{\vspace{\baselineskip}}. – Alan Munn Sep 27 '18 at 2:54
  • That might work. I would need to add a definition for \mypar (as a simple alias for \par) for those instances where I'm reusing the text in a context where a more continuous text is needed, but that shouldn't be too hard. – rpspringuel Sep 27 '18 at 20:45
  • @AlanMunn, Can you post your comments as an answer. Thus far I'm inclined to go with it as less invasive and would like to give you credit. – rpspringuel Sep 28 '18 at 17:11
3

I believe this will achieve what you want provided the sentences end in only a period. If they end in any other sentence ending punctuation mark, then you'll need to follow my lead for each such punctuation mark in question. Your question is essentially asking something I asked way back when: An environment which parses periods differently to redefine their behavior

I've added a bit more formatting than you requested to help you see more of an effect.

\documentclass{article}

\begingroup
  \catcode`\.=\active
  \gdef.{\normalperiod\formattingcommand}%
\endgroup
\newcommand\formattingcommand{\newline\makebox[0pt][r]{$\rightarrow$}\ignorespaces}
\newenvironment{speech}
  { \vspace{2ex}\par
    \let\normalperiod=.
    \catcode`\.=\active
    \sffamily\small
  }{\vspace{2ex}\par}

\begin{document}

GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes lingua,
institutis, legibus inter se differunt.  Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit.  Horum omnium fortissimi sunt Belgae, propterea quod a
cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt
\begin{speech}
This is the beginning of paragraph 1.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed faucibus, sem vel suscipit eleifend, ipsum dolor tempus nunc, ut iaculis nibh arcu vitae tortor.
Pellentesque a efficitur lectus, eget sagittis lorem.
Fusce vestibulum feugiat nibh, pulvinar convallis eros sagittis ac.
Pellentesque aliquam arcu a augue malesuada, sit amet eleifend orci vulputate.
Sed nibh dolor, commodo vel risus quis, elementum consequat dui.

This is the beginning of paragraph 2.
Pellentesque eu neque eleifend, tincidunt mauris id, ultricies odio.
Aenean ac nisi congue, mollis leo a, cursus dolor.
Aenean non justo felis.
Cras interdum quam eu metus imperdiet ultricies.
Fusce finibus pellentesque volutpat.
Praesent id lacus eget dui ullamcorper finibus nec nec urna.
Quisque vel vestibulum quam.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Mauris vel nisl eros.
\end{speech}
Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt. Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis
cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.

\end{document}

enter image description here

For the case of handling non-sentence ending periods, you can use something like the following:

\chardef\periodcatcode=\catcode`\.
\newcommand\aeprotect[1]{%%
  \begingroup
  \catcode`\.=\periodcatcode
  \scantokens{#1\ignorespaces}%%
  \endgroup
  }

Here's the result of using this:

enter image description here

Here's the snippet of code

\begin{speech}
This is the beginning of paragraph 1.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\aeprotect{S.P.Q.R.}
That will cost you \aeprotect{\$3.25}.
This is the content INTERRUPTION \aeprotect{$3.25\cdot7.14=23.205$} following the protected periods.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\end{speech}

In case you want to do something like,

\begin{speech}
  blah blah blah
  \input{file.tex}
  yada yada yada
\end{speech}

you'll need special processing since \input won't understand how to handle . under the new catcode.

The following code works

\makeatletter
\newcommand\aeinput[1]{%%
  \begingroup
  \catcode`\.=\periodcatcode
  \everyeof={\noexpand}%%
  \endlinechar=-1
  \xdef\ae@filehandle{\scantokens{#1}}%%
  \endgroup
  \input{\ae@filehandle}%%
  }%%
\makeatother

The idea of everyeof{\noexpand}\endlinechar=-1 comes from and is explained here

Why it must be defined in this particular way and not \scantokens{\xdef\ae@filehandle{#1}} I'm hoping to have answered here

12
  • Unfortunately I can neither guarantee that sentences will end with a period (other punctuation is possible), nor that periods will always appear at the end of sentences (in some cases they may appear in the middle, say as part of an abbreviation). You've already indicated that the first can be dealt with, but what about the second? – rpspringuel Sep 27 '18 at 9:14
  • @rpspringuel I've updated the answer to show an approach to handle non-sentence ending periods. – A.Ellett Sep 27 '18 at 14:28
  • I hate to move the goal posts, but how would you deal with closing delimiters (quotes, parentheses, braces, etc.) which might appear after a period (or other full stop)? – rpspringuel Sep 28 '18 at 17:09
  • @rpspringuel No problem. But I think it would be best to post that as another, separate question. – A.Ellett Sep 28 '18 at 17:10
  • @rpspringuel And that is a great question by the way. I'd have to majorly rewrite my answer to take that into account. So, I think a new question is indeed really the best idea. – A.Ellett Sep 28 '18 at 17:11
1

A simple option which might serve your purpose would be to use a redefined explicit \par command, and then set the parskip to 0pt and use \obeylines. Then copying the text to another document would simply require setting the redefined \par to its original value:

\documentclass[12pt]{report}

\usepackage{fullpage}


\newenvironment{speech}%
    {%begin
        \def\mypar{\vspace{\baselineskip}}
        \Large
        \setlength{\parskip}{0pt}
        \setlength{\parindent}{-1cm}
        \setlength{\leftmargin}{1cm}
        \obeylines
    }
    {%end
    }

\begin{document}

\begin{speech}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed faucibus, sem vel suscipit eleifend, ipsum dolor tempus nunc, ut iaculis nibh arcu vitae tortor.
Pellentesque a efficitur lectus, eget sagittis lorem.
Fusce vestibulum feugiat nibh, pulvinar convallis eros sagittis ac.
Pellentesque aliquam arcu a augue malesuada, sit amet eleifend orci vulputate.
\mypar
Sed nibh dolor, commodo vel risus quis, elementum consequat dui.
Pellentesque eu neque eleifend, tincidunt mauris id, ultricies odio.
Aenean ac nisi congue, mollis leo a, cursus dolor.
Aenean non justo felis.
Cras interdum quam eu metus imperdiet ultricies.
Fusce finibus pellentesque volutpat.
\mypar
Praesent id lacus eget dui ullamcorper finibus nec nec urna.
Quisque vel vestibulum quam.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Mauris vel nisl eros.
\end{speech}

\end{document}

enter image description here

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.