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?
\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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With