Question

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?

Was it helpful?

Solution

You can load the breqn package (compatible with amsmath) and have this behaviour inbuilt with its dmath environment:

Consider the function
\begin{dmath}\sin(x)\end{dmath}.

Will output the same as \[\sin(x).\], i.e., as if the dot was inside the expression.

As a bonus, you'll also get automatic line-breaking in your math equation.

OTHER TIPS

\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 

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 $$.

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 https://mathoverflow.net/questions/6675/periods-and-commas-in-mathematical-writing

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top