latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.91k stars 264 forks source link

Empty bmatrix gives ] [ instead of [ ] in PDF #1219

Closed jfine2358 closed 10 months ago

jfine2358 commented 10 months ago

Brief outline of the bug

\[
  \begin{bmatrix}\end{bmatrix}
\]

visually produces ] [. However copy and paste from the PDF produces [ ].

By the way, I'm reporting this on behalf of a blind user. I believe a screen reader would give the correct audible output, even though the visual output is (in my opinion) wrong.

Minimal example showing the bug

\RequirePackage{latexbug}
\documentclass{article}
\usepackage{amsmath}

\begin{document}

Empty bmatrix gives nonsense.
\[
  \begin{bmatrix}\end{bmatrix}
\]

\end{document}

Log file (required) and possibly PDF file

bmatrix-error.log bmatrix-error.pdf

u-fischer commented 10 months ago

However copy and paste from the PDF produces [ ]

an empty bmatrix is like an empty tabular, it doesn't occupy space and that means that the negative space added around the matrix moves the right bracket to the left. In the PDF the glyphs are in the correct order.

though the visual output is (in my opinion) wrong.

Well the code doesn't expect the matrix to be empty. You would get the expected spacing if you add e.g. a \relax. But what is the purpose of this input? From a semantic point it looks like an odd way to produce brackets and a tagged PDF would quite probably create the wrong structure.

jfine2358 commented 10 months ago

MathJax and Latex give different results when applied to

  \begin{bmatrix}\end{bmatrix}

For the MathJax output, and also a speech equivalent, see: https://checkmyworking.com/misc/makebigmaths/?tex=%20%20\begin{bmatrix}\end{bmatrix}

In this case it is clear that Latex and MathJax code have different expectations (or more accurately algorithms).

FrankMittelbach commented 10 months ago

LaTeX makes the reasonable assumption that a bmatrix contains a matrix and not nothing. Under that assumption it takes care of typographical detail to give correct spacing. Obviously the assumption is well taken otherwise I'm sure that we would have seen requests or complaints in the last 30+ years that bmatrix is in existance.

Mathjax obviously doesn't do any spacing adjustments so for the incorrect input it comes out more reasonable than LaTeX.

jfine2358 commented 10 months ago

@FrankMittelbach : I find your closure of this issue to be rude and premature.

u-fischer commented 10 months ago

@jfine2358 I asked you about the purpose of this input and you gave no reason. You claim to care about accessibility, so why do you want us to support an input without semantic meaning?

FrankMittelbach commented 10 months ago

What else should I do? This is a bug tracker and we do not think this is a bug, it is wrong input with an admittedly strange output as a result. But complicating the code to cater for that is likely to cause issues in legitimate cases so we do not see any reason to change the current situation -- thus works as designed. If you come up with convincing arguments to do otherwise there is always the possibility to reopen an issue.

jfine2358 commented 10 months ago

I find the present response deeply unsatisfactory. To help all have a pleasant holiday break, and so we can approach it again refreshed, I'll say no more on this until the New Year.

jfine2358 commented 9 months ago

Happy New Year! Here I share some of my understanding of this matter.

@u-fischer @FrankMittelbach : I do not share your confidence that \begin{bmatrix}\end{bmatrix} is wrong input. Consider the statements:

  1. The number zero is part of arithmetic, even though not taught to beginners.
  2. Similarly, the empty set is part of set theory.
  3. Similarly, the empty matrix is part of linear algebra.

Statement 3 follows from:

  1. Every linear map between finite dimensional vector spaces can be represented by a matrix.
  2. There is a zero-dimensional vector space, call it X.
  3. The identity map from X to X is a linear map.

In some situations, such as solving simaltaneous linear equations, it is convenient to ignore the zero-dimensional case. In other situations, such as abstract algebra and matriods, it is convenient to include the zero-dimensional case. The classical zero-dimensional object is a point.

It's not clear to me why you say bmatrix works as defined. The bmatrix command was designed and implemented by Mike Spivak, based on Don Knuth's plain TeX. Spivak's bmatrix treats the empty matrix as valid input, and gives appropriate output. bmatrix.pdf bmatrix.txt

I learnt of the proof of statement 3 (from certain assumptions) in https://math.stackexchange.com/questions/1913141/is-the-0-times-0-matrix-zero-times-zero-matrix-a-well-defined-concept

u-fischer commented 9 months ago
  • The number zero is part of arithmetic, even though not taught to beginners.

And its symbol is 0

  • Similarly, the empty set is part of set theory.

And it has a specific symbol too.

  • Similarly, the empty matrix is part of linear algebra.

Sure. But the question is what is its symbol? Does it like the zero and empty set have an unicode code point? And if an empty bmatrix is used to denote this (why not a pmatrix (which by the way has the same problem)?) did the user on whose behalf you are reporting this actually meant to denote an empty matrix or did they meant some other mathematical object? I have no problems to add a \relax somewhere to correct the output, but after all this is the first report in around 30 years and so I think one can be a bit skeptical that you are promoting here a widely used syntax.