GithubHelp home page GithubHelp logo

Comments (20)

FrankMittelbach avatar FrankMittelbach commented on May 14, 2024 2

nice example of the issue. The reason for the extra t is fairly clear (but also shows that there is a need to do something about it). What happens is that that the code does a simple test (assuming that the option argument is a single char), namely \if #1t\vtop \else \if #1b \vbox \else \vcenter \fi.

so if you have a single char inside the optional argument it will not be matched, so you get \vcenter
but with \mathbf{k} as #1 ends up being true as that gets expanded (followed by a t so the t prints. It could get worse :-)

So yes we need to address this but not in a rush during this week, that is too dangerous.

from latex2e.

davidcarlisle avatar davidcarlisle commented on May 14, 2024

from latex2e.

 avatar commented on May 14, 2024

Thanks for the reply.

I would certainly prefer the new macro, but the altering of existing documents is also a big issue. So maybe it is possible to change in a way that retains current behavior, but displays a warning if [ does not immediately follow.

And, if that would take too much work (I have no idea about its difficulty), displaying a warning when the received argument is not among t, c, & b will also help unexperienced users like me a lot. Practically this will cover most cases as well, only leaving out the unlucky ones whose formula start with [t] or so.

from latex2e.

muzimuzhi avatar muzimuzhi commented on May 14, 2024

(might be off topic)

A pair of package options named allowspaces and disallowspaces (default), provided by package mathtools, does the job @davidcarlisle suggests. Maybe it can be used as a workaround.

from latex2e.

davidcarlisle avatar davidcarlisle commented on May 14, 2024

@muzimuzhi yes thanks, more generally there are some vague plans to merge parts or all of mathtools in to amsmath perhaps, one day. certainly the parts of mathtools that are "fixes" to amsmath rather than clearly extensions.

from latex2e.

FrankMittelbach avatar FrankMittelbach commented on May 14, 2024

from latex2e.

davidcarlisle avatar davidcarlisle commented on May 14, 2024

Something like this, perhaps (@FrankMittelbach )?

 \documentclass{article}
\usepackage{amsmath} 


\makeatletter

\def\ams@t{t}\def\ams@b{b}\def\ams@c{c}
\renewcommand{\start@aligned}[2]{%
    \RIfM@\else
        \nonmatherr@{\begin{\@currenvir}}%
    \fi
    \savecolumn@ % Assumption: called inside a group
    \alignedspace@left
\def\ams@tmp{#1}%
\let\ams@tmpb\@empty
\ifx\ams@tmp\ams@t\vtop\else
\ifx\ams@tmp\ams@b\vbox\else
\ifx\ams@tmp\ams@c\else
    \def\ams@tmpb{[#1]}%
\fi
\vcenter
\fi\fi
        \bgroup
        \maxfields@#2\relax
        \ifnum\maxfields@>\m@ne
            \multiply\maxfields@\tw@
            \let\math@cr@@@\math@cr@@@alignedat
            \alignsep@\z@skip
        \else
            \let\math@cr@@@\math@cr@@@aligned
            \alignsep@\minalignsep
        \fi
        \Let@ \chardef\dspbrk@context\@ne
        \default@tag
        \spread@equation % no-op if already called
        \global\column@\z@
        \ialign\bgroup
           &\column@plus
            \hfil
            \strut@
            $\m@th\displaystyle{##}$%
            \tabskip\z@skip
           &\column@plus
            $\m@th\displaystyle{{}##}$%
            \hfil
            \tabskip\alignsep@
            \crcr
\ams@tmpb
}
\makeatother

\begin{document} 
\begin{equation}
1=\begin{aligned}
[p, q] = 1 - 1 = 0 \\
[q, p] = 1 - 1 = 0
\end{aligned}
\end{equation}
\begin{equation}
2=\begin{aligned}[t]
[p, q] = 1 - 1 = 0 \\
[q, p] = 1 - 1 = 0
\end{aligned}
\end{equation}
\begin{equation}
3=\begin{aligned}[b]
[p, q] = 1 - 1 = 0 \\
[q, p] = 1 - 1 = 0
\end{aligned}
\end{equation}
\begin{equation}
4=\begin{aligned}[c]
[p, q] = 1 - 1 = 0 \\
[q, p] = 1 - 1 = 0
\end{aligned}
\end{equation}

\end{document}

from latex2e.

eg9 avatar eg9 commented on May 14, 2024

from latex2e.

davidcarlisle avatar davidcarlisle commented on May 14, 2024

from latex2e.

davidcarlisle avatar davidcarlisle commented on May 14, 2024

note the version in the comment above treats [] as not an option so would typeset [] it may be better to treat it as a valid option, acting like [c] as many editors seem to generate empty options (not necessarily for aligned, but in general) you often see \begin{table}[] for example.

from latex2e.

car222222 avatar car222222 commented on May 14, 2024

Just a note on the use of: \ams@tmpb
At first I thought it looked very unsafe.
But on retreading (oops!) the code I now
see that it is β€˜very’ local!
Extra precaution (since the
escape of such temporary defs
is a common cause of bugs)
would be to make it empty again
after using it.

from latex2e.

car222222 avatar car222222 commented on May 14, 2024

I can see how empty optional May well happen due to smart editors not being clever enough to know that if a use does not actively edit the template then it should remove the delimiters.

So probably a good idea to interpret empty as c.

But this raises the question of what to do for all other empty optionals?? In all of latex.

from latex2e.

FrankMittelbach avatar FrankMittelbach commented on May 14, 2024

@davidcarlisle yes that is more or less what I was thinking of: doing something less surprising when the optional argument doesn't fit the spec. and yes, I think accepting an empty default in this case is probably a sensible idea too.

from latex2e.

FrankMittelbach avatar FrankMittelbach commented on May 14, 2024

@car222222 I may be mistakenbut most if not all of LaTeX actually already supports the use of "empty" meaning the default action whenever the optional value is a of a defined set, e.g. \begin[]{tabular} = \begin[c]{tabular} and the like. Probably needs some verification of that claim but I think it is largely true in core (there aren't that many)

from latex2e.

davidcarlisle avatar davidcarlisle commented on May 14, 2024

from latex2e.

blefloch avatar blefloch commented on May 14, 2024

from latex2e.

davidcarlisle avatar davidcarlisle commented on May 14, 2024

yes I had wondered about using edef but didn't dare. I suppose f expansion would be safer, either way I think there are too many issues (including coordination with mathtools) so I don't plan changing this this week so will miss the texlive 2018 initial release.

from latex2e.

FrankMittelbach avatar FrankMittelbach commented on May 14, 2024

sounds like a sensible plan. This isn't urgent

from latex2e.

Abacn avatar Abacn commented on May 14, 2024

Hi everyone, I also found the problem and the working example might provide some evidence. In a particular case a mysterious "t" will appear:

Minimal Working Example:
`
\RequirePackage{latexbug} % <--should be always the first line (see CONTRIBUTING)!
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\author{}
\title{}
\maketitle
\begin{equation}
[\mathbf{K}]=1
\end{equation}

\begin{equation}
\begin{aligned}
[\mathbf{K}]=1
\end{aligned}
\end{equation}

\end{document}
`

Interestingly, the second equation produces "\mathbf{K}t=1" with a redundant "t". If the first equation is absent, or "\mathbf" is not specified in either equation, the second one will produce "=1" as is already pointed.

from latex2e.

FrankMittelbach avatar FrankMittelbach commented on May 14, 2024

really think we should make at least sure that only c/b/t are accepted as optional argument the fact that the optional arg can start on a new line is something we can't rally change in core amsmath because it is too long ot there but dropping a bracket group is clearly an unintended bug and so is the fact that [aa] will be interpreted as top and the group dropped.

from latex2e.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.