Unable to make each sentence to start at a new line in LaTex by AWK/Python
Question
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.
Solution
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.
OTHER TIPS
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))
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/