# How can I insert a special character at the end of each sentence?

I tend to write very long sentences. To easily detect sentences that are too long, I would like to make individual sentences stand out more clearly in my compiled latex document. I know that latex has some way of detecting the end of sentences to adjust the spacing. So is it possible to modify latex's detect-end-of-sentence function so that a highly-visible special character, say a $\bullet$, is inserted at the end of each sentence?

(Any other ideas to highlight sentences are very welcome.)

To add bullets, you can make the period an active character and define a macro that adds the bullets:

\documentclass{article}
\begin{document}
\begingroup       % EDIT
\let\origdot=.
\catcode.=\active
\def.{\origdot\ensuremath{\bullet}}
Hello.  I am a sentence.  Mr.\@ Black knows too little.
\endgroup         % EDIT
\end{document}


This results in:

Note that the period after Mr also got a bullet. I do not know off-hand how to change that. (Someone who does, please feel free to edit!)

An easier way may be just to add lots of space after each sentence:

\documentclass{article}
\begin{document}
\nonfrenchspacing    % <--
\xspaceskip1cm       % <-- (or whatever amount of space you prefer)
Hello.  I am a sentence.  Mr.\@ Black knows too little.
\end{document}


gives

See this forum thread for explanation. This fixes the problem after Mr. (thanks to @ Gustavo Mezzetti).

• What do you mean by "make the period and active character"? – sieste Jul 24 '15 at 10:26
• This is a very short answer and just refers to a another forum, in my point of view. It does not show how to make . active! – user31729 Jul 24 '15 at 10:27
• @ChristianHupfer edited :) – cxw Jul 24 '15 at 10:48
• I think you mean Mr.~Black, not Mr\@. Black. Or Mr.\@ Black, if you want to allow a line break after “Mr.”, while suppressing the longer space. – GuM Jul 24 '15 at 11:05
• Thank you for that. Unfortunately the active character approach does not work for me. I have a few lines like \includegraphics[width=.7\textwidth]{fig}. The dot inside the square bracket gets replaced as well, which leads to a compile error. – sieste Jul 24 '15 at 11:43

The approach of the other answer is certainly better, but heres what I came up with: You want to replace periods, so do just that

\documentclass{article}

\usepackage{xstring}
\begin{document}
\section{original tex} %one paragraph from lipsum package
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, %cut that here

\section{with replacement}

\StrSubstitute{Lorem ipsum dolor s... }{.}{.\par~\par\noindent}

\end{document}


of course this has the same problem that not every period is the end of a sentence and more (foremost: this only works on plain text)

• I want to be able to quickly turn the modification on and off, because obviously in the final document I would not want any bullets between my sentences. So the only way this approach would be practical for me is to wrap the entire document body in the StrSubstitute. But this gives me an error ! Incomplete \iffalse; all text was ignored after line 438. It does work when I wrap individual paragraphs, but as I said this is impractical. – sieste Jul 24 '15 at 11:57
• which is what I anticipated. The thing is: You will always almost have to go through the text for all the non-"ending of a sentence" occurrences of a dot. The best way around from my perspective would be to change spacings, see cxw answer – Bort Jul 24 '15 at 11:59
• I think there should be some way to tell the latex compiler: If you detect end-of-sentence, then insert a bullet and then do whatever you would normally do. – sieste Jul 24 '15 at 12:03
• @sieste As far as I know, TeX doesn't have a "detect end-of-sentence" function similar to \everypar. Instead, TeX tracks the \spacefactor of individual characters and adds glue between words depending on the \spacefactor`. See pgs. 75-76 of the TeXbook with 1996 corrections (ISBN 0-201-13448-9). – cxw Jul 24 '15 at 13:20
• in principle you could change the \sfcode for . (say to 17835 or something unique) but that doesnt suffice, you would then have to include a switch in the space handling of tex. no idea how that works – Bort Jul 24 '15 at 13:50