Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Punctuation in LaTeX formulas

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?

like image 887
Olivier Verdier Avatar asked Feb 10 '10 08:02

Olivier Verdier


1 Answers

\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 
like image 144
Alexey Malistov Avatar answered Nov 21 '22 05:11

Alexey Malistov