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"


"This is some text.This is some text"

should be

"This is some text. This is some text"

I'm from Europe.

  • 14
    It would be easier to perform that search/replace in your editor, rather than asking LaTeX to do it. I should add that doing your proposed fix automatically would screw up all kinds of things, like decimal numbers, web addresses, etc. – Steven B. Segletes Dec 6 '13 at 14:40
  • @StevenB.Segletes How can you do that with search and replace? I think that if you set an exception to ​​not automatically put the space on the punctuation followed and preceded by a number you deal with most of the cases in Which you do not need a space. Url are normally inside \ url {} not so difficult to deal with. – G M Dec 22 '13 at 8:37
  • 1
    Searching and replacing can be done various ways, your standard LaTeX editor can do it, but placing exceptions might be difficult there. Don't replace all instances at ones, but confirm each match. With sed, awk or perl it could be done easier, but one has to know how to use them. – Johannes_B Dec 22 '13 at 9:20
  • @Johannes_B thanks I'm aware of search and replace but what find command can you use? Is there an unknown character in search and replace for searching something like this *.*? – G M Dec 22 '13 at 9:45
  • 1
    @GM Would be horrible if one couldn't find a simple dot using a script. Try escaping with a backslash \. What needs to be done depends on the environment, as said before. – Johannes_B Dec 22 '13 at 19:01

Ok, let's try a slacky trick.


For our next trick we will need:

  1. Sublime Text 2 editor installed (don't worry is multiplatform),
  2. A package (for this editor) called LaTeX Tools installed in turn by
  3. Package Control (A plugin or package that eases the installation of another packages).


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:

  1. Press Ctrl + F
  2. In the bottom of the screen will appear a bar with the following options (from left to right):

    • Regular expressions (Alt+R)
    • Case sensitive (Alt+C)
    • Whole word (Alt+W)
    • Reverse direction
    • Wrap
    • In selection
    • Highlight matches

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:

  • Regular expresions (can be useful for this task),
  • Whole word (avoid to select ... by example if you have instead of \ldots) ,
  • Reverse direction (to review until the end of the document and return to the beginning, if you start seeking half of it) and highlight matches (the reason for select Monokai bright instead of Monokai).

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 now Ctrl+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.


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.

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.