Linux Format logo

It's only words

Freelance writers often
submit work as .txt files
that are broken up in the
middle of lines like this. It’s
never less than annoying,
but sometimes (for example
when writers use lots of
very short sentences or)
fragments it makes work
unintelligible, and generates
work for whoever puts the
text into Indesign.

I assume that there’s some setting in whatever text editor the writer uses that can be changed so that this doesn't happen any more. Does anyone out there know how to fix it? With my limited knowledge all I can tell writers is that it’s wrong, but not how to fix it, which isn’t very constructive.
Help me Obi-Wan!


Your comments

Nano

I've read the LXF article about nano yesterday, there they said something about wrapping lines together, you might wanna try that?:D

Gedit plugin can reformat

There is a wordwrap plugin for gedit that reformats while retaining original paragraphs (i.e. blank lines).

This is your problem with perfectly acceptable text - you might ask how to use a pencil sharpener, but you would not ask other people to sharpen your pencils (or would you?)

Best not to blame the writers

Best not to blame the writers for your limited knowledge. Especially if they might think that it was your job to format text for print...

Noob hint: The command fmt article.txt works quite well.

@Penguin Timo

Cheers! I knew I'd read something like that in the recent past. I'll pass it on.

Andrew

but words are all i have

tell effy for each paragraph he fixes, Mexico will get a goal in the world cup

Text conversions

I find that OpenOffice saves .txt files in this way; possibly other programs do. I normally open them in Kwrite and do a Save as which saves them without the hard carriage return - or whatever it is.

If I receive a file like this, I open them in KWord and select the second option. This works on the assumption that two carriage returns means end of paragraph which is normally true of .txt files. Otherwise, it runs everything together and it is quicker then to use the Kwrite option.

Search and replace

In any word processor or text editor you can replace newlines with spaces and double newlines with singles:

Select a double line, then search and replace with "****" (or some other string which you hope the text does not contain); mark a single return, then search and replace with a space; search and replace all "****" with \n. Selecting newlines avoids having to work out what end-of-line characters are used.

(Sometimes it is also useful to replace all double spaces with singles, and space-newline / newline-space with newline)

Text Processing in three lines...

I am sure this can be even done from the command line. But if this is a regular occurrence it can be also done simply by having a bit of Javascript that will use a regular expression to change the text, and use the API of a browser...

here is one...save this as an HTML file:

<html><body>
<textarea onchange='this.value=this.value.replace(/[\n\r\t]/g," ")' rows=40 cols=40>Enter text here</textarea>
</body></html>

Just copy and paste your text into the box which appears when you open the file in your browser...click elsewhere, and voila! Of course you can automate other actions as well such as double spaces etc...

If you want a very quick and easy way to fix these files

In ~/.vimrc (Vim configuration file), add these two lines:

set formatprg=fmt\ -72\ -u
nmap Q gqap

Now, in Vim's command mode, you can position the cursor on the first line of any paragraph and press Shift+Q to format that paragraph with textwidth 72, one space between words and two after sentences.

Leafpad does the job

Use Leafpad with the Options/Word Wrap clicked on. This eliminates any hard linefeeds except for new paragraphs.



Web hosting by UKFast