Dirac-delta-functions as eigenbasis of the position operator - pure nonsense? Or can more be said? I remember overthinking equations like
\begin{equation}
\mathbf{1}=\int dx\ |x\rangle\langle x|\tag{1}
\end{equation}
and
\begin{equation}
X=\int dx\ |x\rangle\langle x|x\tag{2}
\end{equation}
when I had my introductory QM lecture ($\mathbf{1}$ is the identity on $L^2(\mathbf{R})$ and $|x\rangle$ is "defined" as the Dirac-delta function that vanishes everywhere except in $x\in\mathbb{R}$).
Surprisingly, this formalism is self-consistent if one uses the "axiom" $\langle a|x\rangle=\delta(x-a)$ and "linearity", e.g.
\begin{equation}
\langle a|X|\psi\rangle=\langle a|X|\int dx\ |x\rangle\langle x|\psi\rangle=\int dx\ \langle a|X|x\rangle\langle x|\psi\rangle
\\ =\int dx\ x\langle a|x\rangle\langle x|\psi\rangle=\int dx\ x~\delta(x-a)\psi(x)=a\psi(a).
\end{equation}
I am now wondering why the nonsense above is commonly presented in introductory QM courses. Is there more to the story? Here are some ideas:

*

*Equations $(1)$ and $(2)$ remind me a bit of the spectral theorem - is there a connection?

*I've had a very brief introduction to rigorous distribution theory (I've learned how to solve inhomogeneous ODEs using distributions) and I'd say $\langle x|$ can be regarded as a distribution/linear map $\mathcal{L}^2(\mathbf{R})\ni f\mapsto f(x)\in\mathbf{R}$.$^1$ But apart from that, I don't see how distribution theory helps to make $(1)$ and $(2)$ meaningful...maybe someone who knows more about distributions does. :)


$^1$ $\mathcal{L}^2$ is the set of square-integrable functions, $L^2$ is the set of equivalence classes.
 A: I have asked you to search phys.SE for the "rigged Hilbert space" words. There should be a lot of returns, the most recent which addresses your second point is the one linked here on this page (right side): Conceptual question on eigenvectors in quantum mechanics. It is pretty good, apart from a technical detail that is not so important to you.
As to point 1. They are "Dirac formal expressions" (completeness of a system of generalized eigenvectors and expansion of an operator in a basis formed by its generalized eigenvectors) which can be derived, under certain simplifying assumptions, from the spectral theorem in a rigged Hilbert space (Gelfand-Kostyuchenko-Maurin or Gelfand-Maurin, depending on the source). This is a very involved result, which needs more than "rigorous distribution theory" (which can be seen as an application of general rigged Hilbert spaces to only particular examples, such as $\mathcal D\subset L^2 \subset \mathcal D'$ and $\mathcal S\subset L^2 \subset \mathcal S'$, see the first four volumes of Gelfand and coworkers).
A good textbook of QM which goes at length in rigor including a part of RHS is Galindo and Pascual (2 vols, 2nd Ed. in Spanish or its translation into English by Springer Verlag). If this is out of reach, then Capri "Nonrelativistic QM" and Manoukian "QM" also have sections on it.
A: I just want to add my 2¢ and provide an alternative formalization of the equations in question. Since understanding QM through the lens of rigged Hilbert spaces is in my opinion a minority view and most mathematical physicists formulate the theory simply on (unequipped) Hilbert spaces, this might be a more accessible view.
Let $M$ be a self-adjoint operator and $E_M$ its spectral measure. Then the notation
$$
  A = \int_{\sigma(M)} f(m) \;\; \left| m \right>\!\left< m \right| \, \mathrm{d}m
$$
means precisely
$$
  A = \int_{\sigma(M)} f(m) \;\; \mathrm{d}E_M(m) \: .
$$
In other words, the whole symbol “$\left|m\right>\!\left<m\right| \mathrm{d}m$” can be understood as the spectral measure of $M$.
Then $(2)$ follows trivially from the Spectral theorem and $(1)$ is a consequence of $E_M(\sigma(M)) = \mathcal{H}$.
