[texhax] Smart periods

Michael Barr barr at math.mcgill.ca
Mon Nov 5 21:12:40 CET 2012


I guess I really did ask the question nearly three years ago.  My memory must be failing.  I think I didn't understand Donald Arsenault's suggestion of using \spacefactor.  The following code seems to work quite well, as far as I have tested it:

\def\smartperiod#1{#1\ifnum\the\spacefactor=1000 .\fi}

\smartperiod{This is a string}
\smartperiod{This is a string,}
\smartperiod{This is a string.}
\smartperiod{This is a string?}
\smartperiod{This is a string!}

Although the journal does not use \frenchspacing, the following redefinition of frenchspacing, as also suggested by Donald Arsenault, works well too:

\def\frenchspacing{\sfcode`\.=1001 \sfcode`\!=1001 \sfcode`\,=1001
   \sfcode`\;=1001 \sfcode`\:=1001 } 

Michael

----- Original Message -----
From: texhax-request at tug.org
To: texhax at tug.org
Sent: Monday, November 5, 2012 6:00:02 AM
Subject: texhax Digest, Vol 2012, Issue 287



Surely someone has solved this problem.  The online journal I do tex editing for uses \subsection and \subsubsection run in to the text.  The problem is that we want to add a period to the title unless there is already a punctuation mark.  But I have seen the following in authors' texts (even my own, I must admit).
\subsection{This is a subsection}
\subsection{This is a subsection.}
\subsection{Is this a subsection?}
\subsection{This is an amazing subsection!}
and I would want to automatically add a period to the first form and leave the remaining three unchanged.  This is also an issue for the starred version.  I have tried a couple of solutions, none of which quite worked.  Yet it seems like an obvious thing for someone to have dealt with.  

Michael



------------------------------

Message: 3
Date: Sun, 4 Nov 2012 21:21:51 +0100
From: Uwe L?ck <uwe.lueck at web.de>
To: Michael Barr <barr at math.mcgill.ca>
Cc: "<Unknown>" <texhax at tug.org>
Subject: Re: [texhax] Smart periods?
Message-ID: <1352060511.5786.10.camel at uwe-laptop>
Content-Type: text/plain; charset="UTF-8"

Am Sonntag, den 04.11.2012, 12:59 -0500 schrieb Michael Barr:
> \subsection{This is a subsection}
> \subsection{This is a subsection.}
> \subsection{Is this a subsection?}
> \subsection{This is an amazing subsection!}
> and I would want to automatically add a period to the first form
> and leave the remaining three unchanged.
> This is also an issue for the starred version.  
> I have tried a couple of solutions, none of which quite worked.  
> Yet it seems like an obvious thing for someone to have dealt with.  

Instead of presenting a perfect answer soon, 
I would like to recommend reading the answers 
to your similar question on 
"The last character of a string"
on

    http://tug.org/pipermail/texhax/2010-January/

Cheers, 

    Uwe.





More information about the texhax mailing list