views:

387

answers:

3

It seems to be common practice, when writing mathematics, to add punctuation to displayed formulas.

Is there any trick to avoid putting the punctuation mark inside the formula?

I want to avoid

Consider the function
\[ \sin(x).\]

I'd rather have something like:

Consider the function
\[ \sin(x)\].

But of course the full stop is displayed below the formula.

Is there a clever way to separate formulas and punctuation in LaTeX?

+2  A: 

Putting the punctuation inside a display environment is the usual way. The problem is that when Latex processes the \], it ends the mathbox, so anything following will be part of a new vertical box.

You could try something like:

\hbox{\[My formula\]}.

This is not tested, and probably has spacing issues, but if you are interested in this kind of solution, I could try and get something working.

FWIW, you might be interested in http://mathoverflow.net/questions/6675/periods-and-commas-in-mathematical-writing

Charles Stewart
Thanks for the link! Reading the answers there, I am relieved to see that I am not the only one to think that punctuation should not be part of the formulas.
Olivier
+5  A: 
\catcode`\@=11 
\let\seveendformula\]
\def\]{\@ifnextchar.\PointAndEndFormula\seveendformula}
\def \PointAndEndFormula #1{.\seveendformula}
\catcode`\@=12 

Add

More complex solution works with .,?!;: :

\catcode`\@=11 
\def\addtopunct#1{\expandafter\let\csname punct@\meaning#1\endcsname\let}
\addtopunct{.}    \addtopunct{,}    \addtopunct{?}
\addtopunct{!}    \addtopunct{;}    \addtopunct{:}

\let\seveendformula\]
\def\PunctAndEndFormula #1{#1\seveendformula}
\def\]{\futurelet\punctlet\checkpunct@i}
\def\checkpunct@i{\expandafter\ifx\csname punct@\meaning\punctlet\endcsname\let  
       \expandafter\PunctAndEndFormula 
       \else \expandafter\seveendformula\fi}
\catcode`\@=12 
Alexey Malistov
Yes, indeed. I thought of this, but an issue is that there is quite a bit of possible punctuation that you might want to follow a displaymath: probably not '!' or ':', but besides '.' each of ',', ';' and '?' are quite common. +1 for answering the question without petty qualms.
Charles Stewart
@Charles. I added new solution with `!` `:` `;` `?` ...
Alexey Malistov
Very stylish. I don't think I could have written this new code: this is pretty deep stuff.
Charles Stewart
This is *brilliant*! It is so useful that it should maybe be put together as a LaTeX package?
Olivier
Here is an improvement: I will put the punctuation after the displayed equations, use your trick, and if I change my mind it is easy to disable the display of the punctuation by replacing your `\def\PunctAndEndFormula #1{#1\seveendformula}` by `\def\PunctAndEndFormula #1{\seveendformula}`. Magic! Thanks again!
Olivier
+5  A: 

There's also the issue of which font the punctuation should be in. You won't see a problem until you try a different math font such as Euler. Then commas and periods are clearly different in text mode and in math mode. I've written text-mode punctuation in displayed formulas as \mbox{,} or lazily as \mbox, just before $$.

lhf