# Punctuation after $$math mode Latex I would like to know how to put punctuation after a $$ without line break and without putting this punctuation inside.

For example : We have $$1+1=2$$, so $$1+1\neq 3$$. returns

while the result I would like to get is (no line break before the punctuation)

made with the command We have $$1+1=2,$$ so $$1+1\neq 3.$$.

But I don't want to place the punctuation characters inside the math environments (it looks wrong to me) and so I would like to have the second result but with the command We have $$1+1=2$$, so $$1+1\neq 3$$..

Have you got any solution ?

Thomas

• Unrelated but don't use $$in LaTeX. Displaymath is done with $ and $. Mar 21 '20 at 10:52 • You should not use $$; and yes, the punctuation goes inside. Mar 21 '20 at 10:53
• Why it's bad to use $$ ? And why the punctuation goes inside, it's not a math , but a regular text , that I want (for example if I change my fonts)... @egreg @Ulrike Fischer Mar 21 '20 at 10:55 • See Why is $…$ preferable to $$?. As for the punctuation, it needs to go inside, because there is no “look ahead” for it. You can use \text{,}, but this would mean you're using incompatible text and math fonts. Mar 21 '20 at 10:59
• See tex.stackexchange.com/questions/503/why-is-preferable-to. And you can use \mbox{,} or (with amsmath) \text{,} to switch to text mode inside math if you want. Mar 21 '20 at 10:59

As Ulrike and Enrico have already pointed out in comments, (a) the punctuation characters do go inside the display math group and (b) it's much better to write $...$ rather than $$...$$ in a LaTeX document.

If, however, you can't break either habit, and if you're able to use LuaLaTeX, the following solution may be what you're looking for. The solution, as shown below, currently works for only two punctuation characters, viz., , (comma) and . (period, aka "full stop"); however, it's straightforward to extend it to handle additional punctuation characters, such as ; and :. Furthermore, do observe that the code (a) automatically inserts a thinspace before the punctuation characters, (b) places the punctuation character in text mode -- just in case the text-mode and math-mode punctuation characters aren't the same -- and (c) allows whitespace (but not a line break) between the closing $$ character pair and the punctuation character. % !TEX TS-program = lualatex \documentclass{article} \usepackage{luacode} \begin{luacode}  function switch_punctuation ( s ) return ( s:gsub ( "%%%s-([%.%,])" , "\\,\\mbox{%1}$$" ) )
end

\end{luacode}
We have $$1+1=2$$, so $$1+1\neq 3$$ .