Conditional within align environment not resolving
up vote
3
down vote
favorite
I try to use a shortcut for setting matrices with different brackets.
My solution works fine in displaymath and equation environments.
However, as soon as I try to use it within align, there is an error coming up.
Does anyone know a solution where I can still use my definition within align?
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error:
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
align conditionals matrices
add a comment |
up vote
3
down vote
favorite
I try to use a shortcut for setting matrices with different brackets.
My solution works fine in displaymath and equation environments.
However, as soon as I try to use it within align, there is an error coming up.
Does anyone know a solution where I can still use my definition within align?
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error:
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
align conditionals matrices
welcome to tex.se! error is cause by use of ampersands. trybegin{align} {Mtrx[2]{A & B \ C & D}} &= 0 end{align}
...
– Zarko
Dec 7 at 13:58
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I try to use a shortcut for setting matrices with different brackets.
My solution works fine in displaymath and equation environments.
However, as soon as I try to use it within align, there is an error coming up.
Does anyone know a solution where I can still use my definition within align?
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error:
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
align conditionals matrices
I try to use a shortcut for setting matrices with different brackets.
My solution works fine in displaymath and equation environments.
However, as soon as I try to use it within align, there is an error coming up.
Does anyone know a solution where I can still use my definition within align?
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error:
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
align conditionals matrices
align conditionals matrices
asked Dec 7 at 13:49
NER
184
184
welcome to tex.se! error is cause by use of ampersands. trybegin{align} {Mtrx[2]{A & B \ C & D}} &= 0 end{align}
...
– Zarko
Dec 7 at 13:58
add a comment |
welcome to tex.se! error is cause by use of ampersands. trybegin{align} {Mtrx[2]{A & B \ C & D}} &= 0 end{align}
...
– Zarko
Dec 7 at 13:58
welcome to tex.se! error is cause by use of ampersands. try
begin{align} {Mtrx[2]{A & B \ C & D}} &= 0 end{align}
...– Zarko
Dec 7 at 13:58
welcome to tex.se! error is cause by use of ampersands. try
begin{align} {Mtrx[2]{A & B \ C & D}} &= 0 end{align}
...– Zarko
Dec 7 at 13:58
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You solve the issue by simply adding braces in the definition of Mtrx
:
newcommand{Mtrx}[2][1]{{% <--- brace
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}} % <--- brace
However, here's how I'd do:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2]{%
begin{#1matrix} #2 end{#1matrix}
}
begin{document}
begin{equation}
Mtrx[p]{A & B \ C & D} = Mtrx[b]{c\d}
end{equation}
begin{align}
Mtrx[p]{A & B \ C & D} &= 0
end{align}
end{document}
If you really prefer numbers,
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][0]{%
begin{mtrxtype{#1}matrix} #2 end{mtrxtype{#1}matrix}
}
newcommand{mtrxtype}[1]{%
ifcase#1or bor pfi
}
begin{document}
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
add a comment |
up vote
1
down vote
error is caused by use of ampersands. these from your new command had to be some how hidden from align
ones. for example try
begin{align}
{Mtrx[2]{A & B \ C & D}} &= 0
end{align}
or redefine your command as follows:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx 0#1
{begin{matrix} #2 end{matrix}}
elseifx 1#1
{begin{bmatrix} #2 end{bmatrix}}
elseifx 2#1
{begin{pmatrix} #2 end{pmatrix}}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error: NOT ANYMORE
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f463696%2fconditional-within-align-environment-not-resolving%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You solve the issue by simply adding braces in the definition of Mtrx
:
newcommand{Mtrx}[2][1]{{% <--- brace
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}} % <--- brace
However, here's how I'd do:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2]{%
begin{#1matrix} #2 end{#1matrix}
}
begin{document}
begin{equation}
Mtrx[p]{A & B \ C & D} = Mtrx[b]{c\d}
end{equation}
begin{align}
Mtrx[p]{A & B \ C & D} &= 0
end{align}
end{document}
If you really prefer numbers,
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][0]{%
begin{mtrxtype{#1}matrix} #2 end{mtrxtype{#1}matrix}
}
newcommand{mtrxtype}[1]{%
ifcase#1or bor pfi
}
begin{document}
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
add a comment |
up vote
1
down vote
accepted
You solve the issue by simply adding braces in the definition of Mtrx
:
newcommand{Mtrx}[2][1]{{% <--- brace
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}} % <--- brace
However, here's how I'd do:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2]{%
begin{#1matrix} #2 end{#1matrix}
}
begin{document}
begin{equation}
Mtrx[p]{A & B \ C & D} = Mtrx[b]{c\d}
end{equation}
begin{align}
Mtrx[p]{A & B \ C & D} &= 0
end{align}
end{document}
If you really prefer numbers,
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][0]{%
begin{mtrxtype{#1}matrix} #2 end{mtrxtype{#1}matrix}
}
newcommand{mtrxtype}[1]{%
ifcase#1or bor pfi
}
begin{document}
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You solve the issue by simply adding braces in the definition of Mtrx
:
newcommand{Mtrx}[2][1]{{% <--- brace
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}} % <--- brace
However, here's how I'd do:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2]{%
begin{#1matrix} #2 end{#1matrix}
}
begin{document}
begin{equation}
Mtrx[p]{A & B \ C & D} = Mtrx[b]{c\d}
end{equation}
begin{align}
Mtrx[p]{A & B \ C & D} &= 0
end{align}
end{document}
If you really prefer numbers,
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][0]{%
begin{mtrxtype{#1}matrix} #2 end{mtrxtype{#1}matrix}
}
newcommand{mtrxtype}[1]{%
ifcase#1or bor pfi
}
begin{document}
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
You solve the issue by simply adding braces in the definition of Mtrx
:
newcommand{Mtrx}[2][1]{{% <--- brace
ifx0#1
begin{matrix} #2 end{matrix}
elseifx1#1
begin{bmatrix} #2 end{bmatrix}
elseifx2#1
begin{pmatrix} #2 end{pmatrix}
fififi
}} % <--- brace
However, here's how I'd do:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2]{%
begin{#1matrix} #2 end{#1matrix}
}
begin{document}
begin{equation}
Mtrx[p]{A & B \ C & D} = Mtrx[b]{c\d}
end{equation}
begin{align}
Mtrx[p]{A & B \ C & D} &= 0
end{align}
end{document}
If you really prefer numbers,
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][0]{%
begin{mtrxtype{#1}matrix} #2 end{mtrxtype{#1}matrix}
}
newcommand{mtrxtype}[1]{%
ifcase#1or bor pfi
}
begin{document}
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
end{document}
answered Dec 7 at 14:29
egreg
704k8618763155
704k8618763155
add a comment |
add a comment |
up vote
1
down vote
error is caused by use of ampersands. these from your new command had to be some how hidden from align
ones. for example try
begin{align}
{Mtrx[2]{A & B \ C & D}} &= 0
end{align}
or redefine your command as follows:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx 0#1
{begin{matrix} #2 end{matrix}}
elseifx 1#1
{begin{bmatrix} #2 end{bmatrix}}
elseifx 2#1
{begin{pmatrix} #2 end{pmatrix}}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error: NOT ANYMORE
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
add a comment |
up vote
1
down vote
error is caused by use of ampersands. these from your new command had to be some how hidden from align
ones. for example try
begin{align}
{Mtrx[2]{A & B \ C & D}} &= 0
end{align}
or redefine your command as follows:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx 0#1
{begin{matrix} #2 end{matrix}}
elseifx 1#1
{begin{bmatrix} #2 end{bmatrix}}
elseifx 2#1
{begin{pmatrix} #2 end{pmatrix}}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error: NOT ANYMORE
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
add a comment |
up vote
1
down vote
up vote
1
down vote
error is caused by use of ampersands. these from your new command had to be some how hidden from align
ones. for example try
begin{align}
{Mtrx[2]{A & B \ C & D}} &= 0
end{align}
or redefine your command as follows:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx 0#1
{begin{matrix} #2 end{matrix}}
elseifx 1#1
{begin{bmatrix} #2 end{bmatrix}}
elseifx 2#1
{begin{pmatrix} #2 end{pmatrix}}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error: NOT ANYMORE
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
error is caused by use of ampersands. these from your new command had to be some how hidden from align
ones. for example try
begin{align}
{Mtrx[2]{A & B \ C & D}} &= 0
end{align}
or redefine your command as follows:
documentclass{scrreprt}
usepackage{amsmath}
newcommand{Mtrx}[2][1]{
ifx 0#1
{begin{matrix} #2 end{matrix}}
elseifx 1#1
{begin{bmatrix} #2 end{bmatrix}}
elseifx 2#1
{begin{pmatrix} #2 end{pmatrix}}
fififi
}
begin{document}
% everything as expected here:
begin{equation}
Mtrx[2]{A & B \ C & D} = Mtrx[1]{c\d}
end{equation}
% The following align-equation gives an error: NOT ANYMORE
begin{align}
Mtrx[2]{A & B \ C & D} &= 0
end{align}
edited Dec 7 at 14:16
answered Dec 7 at 14:00
Zarko
119k865155
119k865155
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f463696%2fconditional-within-align-environment-not-resolving%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
welcome to tex.se! error is cause by use of ampersands. try
begin{align} {Mtrx[2]{A & B \ C & D}} &= 0 end{align}
...– Zarko
Dec 7 at 13:58