How to issue a cr within a group in amsmath `align` and friends











up vote
3
down vote

favorite
1












I would like to enclose multiple lines in an align in a group.
Because of the group, the \ delimiting the rows generates a mistake (if I'm guessing right the group is broken at \ and latex complains about unclosed groups).



My goal is to have a macro mymath that typesets some complex formula.
The formula is a combination of fixed symbols and optional symbols that are defined via local macros (A and B) in the MWE.
I would like the definitions to be local to the arguments of the mymath macro,
but I would also like the ability to break lines and align content from "outside" the macro, i.e. without baking in align or similar environments inside the macro itself.



MWE



documentclass[12pt]{article}
usepackage{amsmath}
defA{alpha_0}defB{beta_0}
defmymath#1#2{defA{alpha}defB{beta}sum #1=[#2]}
defmymathb#1#2{defA{gamma}defB{delta}sum #1=[#2]}
defGmymath#1#2{{defA{alpha}defB{beta}sum #1=[#2]}}
defGmymathb#1#2{{defA{gamma}defB{delta}sum #1=[#2]}}

begin{document}
begin{equation}
mymath{A}{B}
+A % want alpha_0 here
mymathb{A}{B}
end{equation}
color{red}
begin{align*}
mymath{A&}{5B}\
mymathb{A&}{7B\&qquadA}
end{align*}
color{blue}
begin{multline*}
mymath{A B}{long+\B superlong A}
end{multline*}
end{document}


If I use mymath the definitions of A and B are lost once I use \, and are not local to the argument only.



If I use gmymath the extra group make align and friends very confused about the \.



Question: Is there a way in which mymath can make the \ "leak" the group?
The same story applies to alignment characters &.










share|improve this question
























  • Have you tried defbluemath#1{{color{blue}begin{gathered}#1end{gathered}}}?
    – Mico
    2 days ago










  • @Mico that would fix the possible uses: for example I would not be able to use &. The intent is to have the user of bluemath to be able to choose the math environment from outside. For example one may want to do begin{align} bluemath{a&b}\bluemath{c&d}end{align} if you use an inner aligned you can't align across rows anymore
    – Bordaigorl
    2 days ago












  • each cell of an alignment is a group, you should think of & as a special form equivalent to }{ so basically what you ask is not possible.
    – David Carlisle
    2 days ago






  • 1




    if you remove the group, there is no error but the color only extends as far as the first & so "I know that the effect can be achieved without the groups," is rather misleading.
    – David Carlisle
    2 days ago










  • I'm not sure I fully understand your typesetting objective. (Actually, I'm pretty sure that I don't fully understand that you're trying to achieve...) In multi-line environments such as align and gather, each row is a group onto itself. Hence, if you can't issue the instruction color{blue} globally, you'll have to issue it separately for each and every row that's supposed to get a non-default color.
    – Mico
    2 days ago















up vote
3
down vote

favorite
1












I would like to enclose multiple lines in an align in a group.
Because of the group, the \ delimiting the rows generates a mistake (if I'm guessing right the group is broken at \ and latex complains about unclosed groups).



My goal is to have a macro mymath that typesets some complex formula.
The formula is a combination of fixed symbols and optional symbols that are defined via local macros (A and B) in the MWE.
I would like the definitions to be local to the arguments of the mymath macro,
but I would also like the ability to break lines and align content from "outside" the macro, i.e. without baking in align or similar environments inside the macro itself.



MWE



documentclass[12pt]{article}
usepackage{amsmath}
defA{alpha_0}defB{beta_0}
defmymath#1#2{defA{alpha}defB{beta}sum #1=[#2]}
defmymathb#1#2{defA{gamma}defB{delta}sum #1=[#2]}
defGmymath#1#2{{defA{alpha}defB{beta}sum #1=[#2]}}
defGmymathb#1#2{{defA{gamma}defB{delta}sum #1=[#2]}}

begin{document}
begin{equation}
mymath{A}{B}
+A % want alpha_0 here
mymathb{A}{B}
end{equation}
color{red}
begin{align*}
mymath{A&}{5B}\
mymathb{A&}{7B\&qquadA}
end{align*}
color{blue}
begin{multline*}
mymath{A B}{long+\B superlong A}
end{multline*}
end{document}


If I use mymath the definitions of A and B are lost once I use \, and are not local to the argument only.



If I use gmymath the extra group make align and friends very confused about the \.



Question: Is there a way in which mymath can make the \ "leak" the group?
The same story applies to alignment characters &.










share|improve this question
























  • Have you tried defbluemath#1{{color{blue}begin{gathered}#1end{gathered}}}?
    – Mico
    2 days ago










  • @Mico that would fix the possible uses: for example I would not be able to use &. The intent is to have the user of bluemath to be able to choose the math environment from outside. For example one may want to do begin{align} bluemath{a&b}\bluemath{c&d}end{align} if you use an inner aligned you can't align across rows anymore
    – Bordaigorl
    2 days ago












  • each cell of an alignment is a group, you should think of & as a special form equivalent to }{ so basically what you ask is not possible.
    – David Carlisle
    2 days ago






  • 1




    if you remove the group, there is no error but the color only extends as far as the first & so "I know that the effect can be achieved without the groups," is rather misleading.
    – David Carlisle
    2 days ago










  • I'm not sure I fully understand your typesetting objective. (Actually, I'm pretty sure that I don't fully understand that you're trying to achieve...) In multi-line environments such as align and gather, each row is a group onto itself. Hence, if you can't issue the instruction color{blue} globally, you'll have to issue it separately for each and every row that's supposed to get a non-default color.
    – Mico
    2 days ago













up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





I would like to enclose multiple lines in an align in a group.
Because of the group, the \ delimiting the rows generates a mistake (if I'm guessing right the group is broken at \ and latex complains about unclosed groups).



My goal is to have a macro mymath that typesets some complex formula.
The formula is a combination of fixed symbols and optional symbols that are defined via local macros (A and B) in the MWE.
I would like the definitions to be local to the arguments of the mymath macro,
but I would also like the ability to break lines and align content from "outside" the macro, i.e. without baking in align or similar environments inside the macro itself.



MWE



documentclass[12pt]{article}
usepackage{amsmath}
defA{alpha_0}defB{beta_0}
defmymath#1#2{defA{alpha}defB{beta}sum #1=[#2]}
defmymathb#1#2{defA{gamma}defB{delta}sum #1=[#2]}
defGmymath#1#2{{defA{alpha}defB{beta}sum #1=[#2]}}
defGmymathb#1#2{{defA{gamma}defB{delta}sum #1=[#2]}}

begin{document}
begin{equation}
mymath{A}{B}
+A % want alpha_0 here
mymathb{A}{B}
end{equation}
color{red}
begin{align*}
mymath{A&}{5B}\
mymathb{A&}{7B\&qquadA}
end{align*}
color{blue}
begin{multline*}
mymath{A B}{long+\B superlong A}
end{multline*}
end{document}


If I use mymath the definitions of A and B are lost once I use \, and are not local to the argument only.



If I use gmymath the extra group make align and friends very confused about the \.



Question: Is there a way in which mymath can make the \ "leak" the group?
The same story applies to alignment characters &.










share|improve this question















I would like to enclose multiple lines in an align in a group.
Because of the group, the \ delimiting the rows generates a mistake (if I'm guessing right the group is broken at \ and latex complains about unclosed groups).



My goal is to have a macro mymath that typesets some complex formula.
The formula is a combination of fixed symbols and optional symbols that are defined via local macros (A and B) in the MWE.
I would like the definitions to be local to the arguments of the mymath macro,
but I would also like the ability to break lines and align content from "outside" the macro, i.e. without baking in align or similar environments inside the macro itself.



MWE



documentclass[12pt]{article}
usepackage{amsmath}
defA{alpha_0}defB{beta_0}
defmymath#1#2{defA{alpha}defB{beta}sum #1=[#2]}
defmymathb#1#2{defA{gamma}defB{delta}sum #1=[#2]}
defGmymath#1#2{{defA{alpha}defB{beta}sum #1=[#2]}}
defGmymathb#1#2{{defA{gamma}defB{delta}sum #1=[#2]}}

begin{document}
begin{equation}
mymath{A}{B}
+A % want alpha_0 here
mymathb{A}{B}
end{equation}
color{red}
begin{align*}
mymath{A&}{5B}\
mymathb{A&}{7B\&qquadA}
end{align*}
color{blue}
begin{multline*}
mymath{A B}{long+\B superlong A}
end{multline*}
end{document}


If I use mymath the definitions of A and B are lost once I use \, and are not local to the argument only.



If I use gmymath the extra group make align and friends very confused about the \.



Question: Is there a way in which mymath can make the \ "leak" the group?
The same story applies to alignment characters &.







align amsmath grouping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Bordaigorl

11.8k2555




11.8k2555












  • Have you tried defbluemath#1{{color{blue}begin{gathered}#1end{gathered}}}?
    – Mico
    2 days ago










  • @Mico that would fix the possible uses: for example I would not be able to use &. The intent is to have the user of bluemath to be able to choose the math environment from outside. For example one may want to do begin{align} bluemath{a&b}\bluemath{c&d}end{align} if you use an inner aligned you can't align across rows anymore
    – Bordaigorl
    2 days ago












  • each cell of an alignment is a group, you should think of & as a special form equivalent to }{ so basically what you ask is not possible.
    – David Carlisle
    2 days ago






  • 1




    if you remove the group, there is no error but the color only extends as far as the first & so "I know that the effect can be achieved without the groups," is rather misleading.
    – David Carlisle
    2 days ago










  • I'm not sure I fully understand your typesetting objective. (Actually, I'm pretty sure that I don't fully understand that you're trying to achieve...) In multi-line environments such as align and gather, each row is a group onto itself. Hence, if you can't issue the instruction color{blue} globally, you'll have to issue it separately for each and every row that's supposed to get a non-default color.
    – Mico
    2 days ago


















  • Have you tried defbluemath#1{{color{blue}begin{gathered}#1end{gathered}}}?
    – Mico
    2 days ago










  • @Mico that would fix the possible uses: for example I would not be able to use &. The intent is to have the user of bluemath to be able to choose the math environment from outside. For example one may want to do begin{align} bluemath{a&b}\bluemath{c&d}end{align} if you use an inner aligned you can't align across rows anymore
    – Bordaigorl
    2 days ago












  • each cell of an alignment is a group, you should think of & as a special form equivalent to }{ so basically what you ask is not possible.
    – David Carlisle
    2 days ago






  • 1




    if you remove the group, there is no error but the color only extends as far as the first & so "I know that the effect can be achieved without the groups," is rather misleading.
    – David Carlisle
    2 days ago










  • I'm not sure I fully understand your typesetting objective. (Actually, I'm pretty sure that I don't fully understand that you're trying to achieve...) In multi-line environments such as align and gather, each row is a group onto itself. Hence, if you can't issue the instruction color{blue} globally, you'll have to issue it separately for each and every row that's supposed to get a non-default color.
    – Mico
    2 days ago
















Have you tried defbluemath#1{{color{blue}begin{gathered}#1end{gathered}}}?
– Mico
2 days ago




Have you tried defbluemath#1{{color{blue}begin{gathered}#1end{gathered}}}?
– Mico
2 days ago












@Mico that would fix the possible uses: for example I would not be able to use &. The intent is to have the user of bluemath to be able to choose the math environment from outside. For example one may want to do begin{align} bluemath{a&b}\bluemath{c&d}end{align} if you use an inner aligned you can't align across rows anymore
– Bordaigorl
2 days ago






@Mico that would fix the possible uses: for example I would not be able to use &. The intent is to have the user of bluemath to be able to choose the math environment from outside. For example one may want to do begin{align} bluemath{a&b}\bluemath{c&d}end{align} if you use an inner aligned you can't align across rows anymore
– Bordaigorl
2 days ago














each cell of an alignment is a group, you should think of & as a special form equivalent to }{ so basically what you ask is not possible.
– David Carlisle
2 days ago




each cell of an alignment is a group, you should think of & as a special form equivalent to }{ so basically what you ask is not possible.
– David Carlisle
2 days ago




1




1




if you remove the group, there is no error but the color only extends as far as the first & so "I know that the effect can be achieved without the groups," is rather misleading.
– David Carlisle
2 days ago




if you remove the group, there is no error but the color only extends as far as the first & so "I know that the effect can be achieved without the groups," is rather misleading.
– David Carlisle
2 days ago












I'm not sure I fully understand your typesetting objective. (Actually, I'm pretty sure that I don't fully understand that you're trying to achieve...) In multi-line environments such as align and gather, each row is a group onto itself. Hence, if you can't issue the instruction color{blue} globally, you'll have to issue it separately for each and every row that's supposed to get a non-default color.
– Mico
2 days ago




I'm not sure I fully understand your typesetting objective. (Actually, I'm pretty sure that I don't fully understand that you're trying to achieve...) In multi-line environments such as align and gather, each row is a group onto itself. Hence, if you can't issue the instruction color{blue} globally, you'll have to issue it separately for each and every row that's supposed to get a non-default color.
– Mico
2 days ago















active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460454%2fhow-to-issue-a-cr-within-a-group-in-amsmath-align-and-friends%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460454%2fhow-to-issue-a-cr-within-a-group-in-amsmath-align-and-friends%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Entries order in /etc/network/interfaces

新発田市

Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)