Skip to content

Modified align environment is not rendered properly #111

@leanhdung1994

Description

@leanhdung1994

I have a tex file

\documentclass[12pt]{article}
\usepackage{amsthm,amssymb,mathtools}

% Create modification of align environments
% https://tex.stackexchange.com/a/751147/161639
% https://tex.stackexchange.com/a/751622/161639
\makeatletter
\ExplSyntaxOn
    %% Variable declarations.
    \int_new:N \g__example_position_int

    %% The list of environments to define.
    \prop_const_from_keyval:Nn \c__example_envs_prop {
        myalign = align,
        myaligned = aligned,
        myalign* = align*,
        myaligned* = aligned*,
        myequation = equation,
    }

    \prop_map_inline:Nn \c__example_envs_prop {
        %% Define the new environments.
        \NewEnvironmentCopy { #1 } { #2 }

        %% Inside the environments, make `&` active and make have it run
        %% the `\__example_align:` command.
        \hook_gput_code:nnn { env / #1 / begin } { . } {
            \zcsetup { currentcounter = equation }
            \int_gzero:N \g__example_position_int
            \char_set_catcode_active:N \&
            \char_set_active_eq:NN \& \__example_align:
        }
    }

    %% Workaround for https://github.com/latex3/latex3/issues/1796
    \cs_new:Nn \__example_only_align: {
        \c_alignment_token
    }

    %% Also make `&` active inside the specified environments, so that nested
    %% `myaligned`s work inside of them.
    \clist_map_inline:nn { align, align*, equation, equation* } {
        \hook_gput_code:nnn { env / #1 / begin } { . } {
            \char_set_catcode_active:N \&
            \char_set_active_eq:NN \& \__example_only_align:
        }
    }

    %% Reset the position counter after measurement is done, otherwise the
    %% counter will be twice as large as it should be.
    \hook_gput_code:nnn { cmd / measure@ / after } { . } {
        \int_gzero:N \g__example_position_int
    }

    %% Define the `\__example_align:` that runs every time `&` is encountered.
    \cs_new_protected:Nn \__example_align: {
        %% Increment the position counter.
        \int_gincr:N \g__example_position_int

        %% Equivalent to a regular alignment `&`.
        \c_alignment_token

        %% If this is not the first `&`, insert a `\quad`.
        \bool_if:nT {
            \prop_if_in_p:NV \c__example_envs_prop \@currenvir &&
            \int_compare_p:n { \g__example_position_int > 1}
        } {
            \quad
        }
    }
\ExplSyntaxOff
\makeatother

\begin{document}

\begin{myalign}
& a \\
& = \begin{myaligned}
& b + c \\
& + d + e .
\end{myaligned} 
\end{myalign}

\end{document}

It seems the user-defined environments myalign and myaligned are not "loaded":

Image

Could you have a check on this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions