Sometimes when I write some text, I mistakingly put space before dot/comma or I forget to put space after dot/comma. I would like LaTeX to remove all space before dots and add space after punctuation.
For example:
"This is some text . This is some text"
should be
"This is some text. This is some text"
and
"This is some text.This is some text"
should be
"This is some text. This is some text"
I'm from Europe.
Best Answer
Ok, let's try a slacky trick.
Ingredients
For our next trick we will need:
Preparation
Once you have all installed following the instructions in each case, then you can use
Sublime Text 2
as a LaTeX editor. I recommend, for convenience, use the color scheme called Monokai Bright (but you can experiment and use your favourite).Open a single
.tex
file with Sublime Text 2 or load the directory of whole project (as you prefer). Once you have open your file, is easy search and replace what you need. Let's test:Ctrl + F
In the bottom of the screen will appear a bar with the following options (from left to right):
Alt+R
)Alt+C
)Alt+W
)And a filed where you can input what are searching for. In our case will be
.
it means a dot with space before. Up here you can use the editor that you like for what I am suggesting. However Sublime Text 2 (and maybe emacs if you use AucTeX) has a very interesting feature that, in my opinion, deserves their use for this task.Well, from the above list, I suggest enable the options:
...
by example if you have instead of\ldots
) ,Now press
[Esc]
before activate the options. Search by ona incidence of.
and with the cursor of the mouse select carefully both, the space before and the dot. The final trick is to make multiple selections from the selected effect, press for that nowCtrl+D
holding the keys.If the selection was well done, then you can at the same time highlight the issues, even better, you'll have a real-time cursor in each and every one of the incidences detected.
This is important because it allows you to simultaneously edit all incidences, and correct all by removing the extra space at once (Use the arrow keys left and right direction to move the cursor to the beginning or end of the selection. Use it in this case left arrow key and press
[Del]
).Is not exactly automatic, is not an script, but it works very well.
Remarks
Although there are programs and plugins to translate documents from Word to LaTeX and vice versa, I have not used any (almost all have licences and you must pay for them). Instead of that before I copied the text directly from Word and paste in Sublime Text 2 where I format it. Sometimes I prefer to open in AbiWord and export to LaTeX with a plugin included. But this plugin is almost experimental, and generates a lot of unnecessary code and not well placed some labels such as hierarchy ones (
\part
,\chapter
,\section
, etc.). To correct these imbalances do use tricks like that tricks like that just explained, that allow me to debug the code with relative ease.I hope this long and overdetailed explanation will be helpful.