Is it more common to type period inside dollars or outside?

Which one is more common way to type LaTeX or are there any standards?

Thus $x=2$.


Thus $x=2.$

Solutions Collecting From Web of "Is it more common to type period inside dollars or outside?"

The case of displayed formulas is a matter of opinion, I’ll tell about it later. For punctuation after an inline formula, there is no doubt: it doesn’t belong to the formula, so it should be typed outside it.

Here’s the relevant excerpt from the TeXbook

\subsection Punctuation.  When a formula is followed by a ^{period}, ^{comma},
^{semicolon}, ^{colon}, ^{question mark}, ^{exclamation point}, etc., put the
^{punctuation} {\sl after\/} the |$|, when the formula is in the text; but
put the punctuation {\sl before\/} the |$$| when the formula is displayed.
For example,
If $x<0$, we have shown that $$y=f(x).$$
\TeX's spacing rules within paragraphs work best when the
^{punctuation marks} are not considered to be part of the formulas.

with a scanning of the output

enter image description here

Of course one shouldn’t use $$ in LaTeX, but the idea is the same.

The difference between

If $x<0$, we have shown that $y=f(x)$. Therefore …


If $x<0,$ we have shown that $y=f(x).$ Therefore …

is actually seen only when “British” spacing is used, because in the former case the period is considered as sentence ending, while in the latter it isn’t. Here’s the output, with \nonfrenchspacing in force:

enter image description here

If \frenchspacing is in force, instead, the result is exactly the same

enter image description here

but this doesn’t mean one is allowed to put punctuation in the formula: it’s logically wrong.

When displayed formulas are concerned, there are various schools of thought; but there’s no doubt that, if punctuation is used, it must be inside the displayed formula:

  1. put punctuation at the end of the formula, with no added space;

  2. put punctuation at the end of the formula, with some added space;

  3. no punctuation at the end of the formula, the context will make readers able to add it by themselves.

I adhere to current number 1, following Knuth’s advice. I find that following current 2 leaves punctuation hanging from nowhere, particularly if the added space is a quad. A thin (\,) or medium (\:) space might help to clear away from ambiguities in some cases, but where ambiguity is possible, rewording is usually the best strategy.

Of course one must adhere to only one of those conventions across a document.

Assuming that we are talking about inline mathematics, it would seem strange to me (and judging by the comments, to others as well) to put the full stop inside the math environment. This is because it is not part of the mathematics. The mathematics is the last “part of the sentence”, and the sentence ends afterwards, so that is where the full stop should go. So I say the following version is correct:

Thus $x = 2$.

However, when I have punctuation at the end of a quotation I always put it outside the quotation marks, for the same reason.

``I think it will rain this afternoon'', she said.

There are some writers who regard this as wrong (they think the comma should go inside the quotes). Maybe they would see my opinion about putting the full stop “inside the dollar signs” as wrong, too. 🙂

In the case of displayed mathematics, however, you will want the full stop (or comma, or semicolon) to be displayed along with the mathematics, not hanging out by itself at the start of the next line of text. So there you have no choice but to put the punctuation within the math environment:

Thus \[x = 2.\]