tags:

views:

395

answers:

3

I have a long document in LaTex, which contains paragraphs. The paragraphs contain sentences such that no subsequent sentence start at a new line.

How can you make each subsequent sentence to start at a new line in my .tex file?

My attempt to the problem

We need to put \n to the end of Sentence B where Sentence B has Sentence A before it.

We must not put \n to the situations where there are the mark \.

I see that the problem can be solved by AWK and Python.

+2  A: 

So you want every sentence in your .tex file to start on a new line, but without introducing extra paragraphs? Is that correct?

Possibly you could go through your file and, every time you see a '.' followed by whitespace and a capital letter, insert a newline.

e.g. in python:

import re
sentence_end = r'\.\s+([A-Z])'

source = open('myfile.tex')
dest = open('myfile-out.tex', 'w')
for line in source:
    dest.write(re.sub(sentence_end, '.\n\g<1>', line))
John Fouhy
+1  A: 

What's wrong with putting a newline after each period? Eg:

awk '{ gsub(/\. +/, ".\n"); print }'

$ echo "abc. 123. xyz." | awk '{ gsub(/\. +/, ".\n"); print }'
abc.
123.
xyz.
David Wolever
Dr. Jones, I presume.
S.Lott
@David: I do not understand the part "gsub(/\. +/, ".\n")". Could you please explain it
Masi
sub is an awk function which accepts a regular expression and a string and replaces text which matches the regular expression with the string. The 'g' in 'gsub' means "replace more than once per line". The regular expression means "match a literal period followed by one or more spaces". That help?
David Wolever
+2  A: 

If I read your question correctly, what you need is the \newline command. Put it after each sentence. \\ is a shortcut for this.

A regex to do this would be something like

s/\.  ([A-Z])/.\\newline\1/
Svante
Seems like a job for sed, when you put it that way
David Zaslavsky