6

Normally, when you write text right after math mode, it prints with no indentation (that's the desired look), but with the following MWE, a small indentation appears

enter image description here

\documentclass{article}

\usepackage{mathtext}
\usepackage[ukrainian]{babel}

\usepackage{amsmath,amsfonts}
\usepackage{mathabx}
\usepackage{euscript}
\usepackage{hyperref}

\begin{document}

$\EuScript{F}$

$$
123
$$
test
\\
test

test

\end{document}

Note that basically commenting out any of the present packages solves the issue, as well as removing $\EuScript{F}$ in front of the math mode 123 formula.

What does cause such an unexpected indentation after math mode?

How can I fix the issue without eliminating any of the loaded packages and without adding \noindent or comment sign (%) after each math mode block?

1

2 Answers 2

5

As identified by David, the issue is due to localmathalphabets handling. It puts code after the display (via \aftergroup) and that prevents $$from seeing any following spaces and dropping them. Therefore they show up.

This is not the case if LaTeX math displays are used (like \[...\], \begin{equation}, etc.

To answer the comments in the remarks: not all TeX primitives are officially supported in LaTeX, even if in internal code they are used (but with special precaution, for example, the $$...$$ constructs are followed by \ignorespaces in LaTeX code when necessary).

  • $$...$$ is not offically supported LaTeX
  • It can lead to issues, for a simple example, apply fleqn class option
  • We do understand, that people use them though, so LaTeX tries hard to make a raw $$...$$ work as far as possible
  • But the recommentation is: don't use it

As a quick workaround until the problem is fixed in LaTeX, you can use

\setcounter{localmathalphabets}{0}

(or not use $$...$$ as recommended). For a final solution I have opened an issue in our bug tracker: https://github.com/latex3/latex2e/issues/886

11

The space isn't an indent it is a word-space from the end of line after $$. Normally spaces are ignored after $$ but aftergrouped tokens interfere.

This is an issue with new code added to avoid running out of math groups. An aftergrouped token restoring the math fonts is preventing the usual implicit \igorespaces after $$. We will probably fix this in the format, but note it is not a bug: $$ has never been supported syntax in LaTeX, and any LaTeX display math form, such as \[...\] or \begin{equation}..\end{equation} will not show this behaviour.

An earlier version of this answer fixed the example shown by adding \igorespaces at one point in internal LaTeX code. That wasn't quite right as it needs to be conditional on display math, so you don't lose space in $x$ and... . Making that conditional is a bit tricky: requiring changes elsewhere, so is not shown here.

If you choose to keep using $$ you can avoid the problem by disabling the new math alphabet feature by declaring:

\setcounter{localmathalphabets}{0}

until the underlying problem gets fixed, but note that you will then (as in earlier LaTeX releases) get an error if your document uses more than 16 math fonts (and it must already have used at least 14 to trigger this issue).


One reason your document uses so many math fonts is that mathtext interacts badly with hyperref. Your example (if you add \showoutput debug information) shows the math is set using PU encoding which is only intended for PDF bookmarks.

.....\PU/pdf/m/n/10 1
.....\PU/pdf/m/n/10 2
.....\PU/pdf/m/n/10 3

Probably you should report an issue to the mathtext package maintainer, and not use it in combination with hyperref unless that is fixed.

10
  • I tried to understand the code, but it seems like you added some technical stuff to it as well as error messages. Could you add the smallest (shortest) version of the fix and write down some comments on how it works?
    – antshar
    Jul 3 at 13:41
  • @antshar I added \ignorespaces in one place all the rest is just the original code copied from latex.ltx But not quite right place, i'm going to delete and update later. Jul 3 at 14:49
  • @antshar don't use that code as shown, it would also remove a space after $123$ where it would be wrong. For now simply do \setcounter{localmathalphabets}{0} until the underlying problem got fixed (which should be soon). Jul 3 at 15:29
  • @FrankMittelbach wow, such a simple and elegant solution. Consider posting it as an answer and add some details.
    – antshar
    Jul 3 at 16:22
  • @antshar note the problem would also not occur if you used latex syntax for the math. the issue is just with $$ not \[. or \begin{equation} or an amsmath environment Jul 3 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.