0

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}

Attempt to flush left all display math

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?).

jlab
  • 1,834
  • 1
  • 13
  • 2
    If you want all displayed equations to be typeset flush-left, you need to stop using $$ to initiate and terminate display math mode. Use \[ and \] instead. – Mico Mar 14 '24 at 12:25
  • 1
    I don't know whether this is possible with lua but I wouldn't spend time on it. I understand your concern but IMO users should get used to the fact that $$ isn't officially supported in LaTeX. – campa Mar 14 '24 at 12:25
  • 1
    @Mico I agree the $$ 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
  • @campa I don't look at a lua solution, since all users don't use it. But thanks for the suggestion. – jlab Mar 14 '24 at 12:30
  • 1
    You shouldn't use $$ 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
  • 6
    No it is really hard to change the behaviour of $$ 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
  • 1
    I think this is a duplicate of https://tex.stackexchange.com/questions/503/why-is-preferable-to/69854#69854 (but I didn't vote to close as that would auto-close it, let others vote) – David Carlisle Mar 14 '24 at 12:54
  • 4
    why do left aligned equations improve a document for visually impaired persons? – Ulrike Fischer Mar 14 '24 at 13:02
  • @DavidCarlisle It's not a duplicate since my question is not about using $$ 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:05
  • 1
    @UlrikeFischer I have a student with a very narrow filed of view. He uses a screen with a very big zoom factor. He cannot find his way in a document and always returns to the left side at line break. – jlab Mar 14 '24 at 13:11
  • 1
    wouldn't it then make sense to reduce the general text width? – Ulrike Fischer Mar 14 '24 at 13:15
  • @UlrikeFischer Yes, I'll also do that. I'm not an expert. He has a transcriber who adapts manually its documents (with MS Word, after using pandoc). I try to do that directly with LaTeX. – jlab Mar 14 '24 at 13:25
  • personally I'd do a one off edit changing $$...$$ to \[...\] but we can probably show something that possibly works in some cases – David Carlisle Mar 14 '24 at 13:33
  • @UlrikeFischer The transcriber's requests are: a larger font (36pt), no color, no bold, no it, and all contents aligned at left. I managed to do that for my own documents. I would like to provide a package to help other users with the same problem. – jlab Mar 14 '24 at 13:34
  • @DavidCarlisle If it's only works in some cases, maybe it's better that I give up. – jlab Mar 14 '24 at 13:38
  • @jlab Joseph's posted the code, see how it goes, but if you have access to the tex file just changing $$ 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

1 Answers1

1

Whilst I strongly recommend not doing this, the code being developed for tagging needs to handle 'raw' $$ (because there are millions of documents on arXiv and a good percentage will use it, even though it's never been supported in LaTeX). As such, we can use an internal of the tagging code to make the adjustment

\DocumentMetadata{testphase = {math}}
\documentclass{article}

\usepackage[fleqn, leqno]{amsmath} \ExplSyntaxOn \cs_gset_protected:Npn __math_grab_dollardollar:w % $$ #1 $$ { \tl_if_blank:nF {#1} { __math_process:nn { equation* } {#1} \socket_use:n {tagsupport/math/display/begin} \socket_use:nn{tagsupport/math/display/formula/begin} { \leftline{$\indent\displaystyle{#1}$} } $$ } } \ExplSyntaxOff

\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}

Note that this is very much not supported: the internal might change, we might revise how we do grabbing, etc. Use at your own risk!

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • it activating tagging required? Doesn't it work simply with the math module? – Ulrike Fischer Mar 14 '24 at 13:50
  • @UlrikeFischer Ah, yes: I was forgetting that you could load the math mode code without the tagging – Joseph Wright Mar 14 '24 at 13:51
  • Many thanks for the effort and the reply, even if I don't know, given the multiple warnings, if I'll implement it. Anyway I've just installed TeX Live 2024, just released, and I get an error: Erroneous variable \l__socket_tagsupport/math/display/begin_plug_str used!. I tried your code as it, with pdflatex and lualatex. – jlab Mar 14 '24 at 15:07
  • @jlab I suspect you have a stray older file: I have an up-to-date TL'24 – Joseph Wright Mar 14 '24 at 15:08
  • 2
    @jlab try using pdflatex-dev rather than pdflatex – David Carlisle Mar 14 '24 at 15:45
  • @DavidCarlisle Yes, it works with pdflatex-dev. Thanks. – jlab Mar 14 '24 at 17:54