I plan to write a package to adapt a document for visually impaired persons. My wish is that all works out of the box, independently of of the user habits or class, just with \usepackage{my-package}, without adaptation of the latex code of the document.
One of the adaptation needed for some visually impaired persons is to flush left all content, including equations.
For display math equations created with amsmath environments, I plan to use the fleqn and leqno options
\PassOptionsToPackage{fleqn, leqno}{amsmath}
\RequirePackage{amsmath}
and since I'm not sure if amsmath was already loaded before my package, I'm going to force some settings:
\tagsleft@true
\@fleqntrue
\let\mathindent=\@mathmargin
\@mathmargin\leftmargini minus\leftmargini
I tested many display environments: \[...\], displaymath, equation, align and gather; this works.
The problem arises with $$...$$ formulas. I know that \[...\] is preferable to $$...$$ but some users still use double dollars to write formulas. Worse, maybe some of them mix amsmath environments and $$.
I managed to flush left $$...$$ equations, with
\def\leftdisplay#1$${\leftline{\indent$\displaystyle{#1}$}$$}
\everydisplay{\leftdisplay}
taken in the TeXbook (answer to the exercise 19.4). But it's incompatible with amsmath display environments, and generate errors:
Paragraph ended before \leftdisplay was complete.
Missing $ inserted.
Display math should end with $$.
The best I did is to add \noexpand before \leftdisplay. This suppresses the errors, but $$...$$ are no more flushed left.
So is it possible to flush left all display equations, whether they are created with $$...$$ or amsmath environments?
Here where I am:
\documentclass{article}
\usepackage[fleqn, leqno]{amsmath}
\def\leftdisplay#1$${\leftline{\indent$\displaystyle{#1}$}$$}
\everydisplay{\noexpand\leftdisplay}
\begin{document}
$$ double~dollars $$
[
brackets
]
\begin{displaymath}
displaymath~env
\end{displaymath}
\begin{equation}
\label{eq:equation}
equation~env
\end{equation}
\begin{align}
\label{eq:align}
align
\end{align}
\begin{gather}
\label{eq:gather}
gather
\end{gather}
\end{document}
EDIT
From David Carlisle's comment I understand that it's not possible without risking to break something else. I will then abandon my request and implement an option for evil users that still use $$ (with an exhortation in the doc to use \[...\] instead - but who reads the doc?).

$$to initiate and terminate display math mode. Use\[and\]instead. – Mico Mar 14 '24 at 12:25$$isn't officially supported in LaTeX. – campa Mar 14 '24 at 12:25$$should not be used and is not supported in LaTex. But some users still use it. Can I handle it in my package? – jlab Mar 14 '24 at 12:27$$in a LaTeX document anyway, even if you don't need to place displayed equations flush-left. Period. No way, no how. – Mico Mar 14 '24 at 12:31$$that is exactly why it has never been supported in latex. Almost anything you do to change that will break some package somewhere (we have looked hard at that over the years) just document that it should not be used. Users should not even know it exists, the latex book doesn't mention it at all. – David Carlisle Mar 14 '24 at 12:51$$but how to handle$$. In fact, I know peoples that still use$$. Anyway I understand it's not without hazard, and then not possible for a package which would work with any user code. – jlab Mar 14 '24 at 13:05pandoc). I try to do that directly with LaTeX. – jlab Mar 14 '24 at 13:25$$...$$to\[...\]but we can probably show something that possibly works in some cases – David Carlisle Mar 14 '24 at 13:33$$to\[with one line of sed or perl or python or whatever language of choice seems far more reasonable approach. As Joseph mentioned in his answer if you are dealing with 2 million arxiv documents in place edits are less attractive but for a current document there is absolutely no reason to use$$– David Carlisle Mar 14 '24 at 13:52