How to generate a matrix from an arbitrary sequence of arguments?
This answer shows me how I can handle an arbitrary number of arguments. I have adapted it a bit to my purpose:
usepackage{pgffor}
newcommand*{twolinematrix}[1]{%
foreach firstrowelement/secondrowelement in {#1} {%
<something should happen here!}%
}
}
The above macro should take input like this as an example: autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
.
I have become stuck because, normally, if you want to create a matrix (assuming you have amsmath
loaded), you would so something like:
newcommand{manualtwolinematrix}[10]{%
begin{matrix}
#1 & #2 & #3 & #4 & #5 \
#6 & #7 & #8 & #9 & #10
end{matrix}%
}
So, this suggests that you'd need to have logic that knows when you are about to be done with the element pairs, because you have to put the \
. I think if we are programmatically generating the matrix, it would be better to think of it like this:
newcommand{manualtwolinematrix}[10]{%
begin{matrix}
#1 & #2 & #3 & #4 & #5 \ #6 & #7 & #8 & #9 & #10
end{matrix}%
}
where #1 & #2 & #3 & #4 & #5 \ #6 & #7 & #8 & #9 & #10
is the string that has to be auto-generated within the body of our macro. Our macro gets input pairwise, so we have to generate this string given pairs. Okay, then in the body of our macro, we should have two variables: call it firstrow
and secondrow
.
The firstrow
and secondrow
should be built up sequentially, given each pair of elements, and then finally a variable called matrixbody
should be generated like so:
matrixbody = firstrow \ secondrow
Can you help me put these thoughts together?
macros
add a comment |
This answer shows me how I can handle an arbitrary number of arguments. I have adapted it a bit to my purpose:
usepackage{pgffor}
newcommand*{twolinematrix}[1]{%
foreach firstrowelement/secondrowelement in {#1} {%
<something should happen here!}%
}
}
The above macro should take input like this as an example: autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
.
I have become stuck because, normally, if you want to create a matrix (assuming you have amsmath
loaded), you would so something like:
newcommand{manualtwolinematrix}[10]{%
begin{matrix}
#1 & #2 & #3 & #4 & #5 \
#6 & #7 & #8 & #9 & #10
end{matrix}%
}
So, this suggests that you'd need to have logic that knows when you are about to be done with the element pairs, because you have to put the \
. I think if we are programmatically generating the matrix, it would be better to think of it like this:
newcommand{manualtwolinematrix}[10]{%
begin{matrix}
#1 & #2 & #3 & #4 & #5 \ #6 & #7 & #8 & #9 & #10
end{matrix}%
}
where #1 & #2 & #3 & #4 & #5 \ #6 & #7 & #8 & #9 & #10
is the string that has to be auto-generated within the body of our macro. Our macro gets input pairwise, so we have to generate this string given pairs. Okay, then in the body of our macro, we should have two variables: call it firstrow
and secondrow
.
The firstrow
and secondrow
should be built up sequentially, given each pair of elements, and then finally a variable called matrixbody
should be generated like so:
matrixbody = firstrow \ secondrow
Can you help me put these thoughts together?
macros
add a comment |
This answer shows me how I can handle an arbitrary number of arguments. I have adapted it a bit to my purpose:
usepackage{pgffor}
newcommand*{twolinematrix}[1]{%
foreach firstrowelement/secondrowelement in {#1} {%
<something should happen here!}%
}
}
The above macro should take input like this as an example: autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
.
I have become stuck because, normally, if you want to create a matrix (assuming you have amsmath
loaded), you would so something like:
newcommand{manualtwolinematrix}[10]{%
begin{matrix}
#1 & #2 & #3 & #4 & #5 \
#6 & #7 & #8 & #9 & #10
end{matrix}%
}
So, this suggests that you'd need to have logic that knows when you are about to be done with the element pairs, because you have to put the \
. I think if we are programmatically generating the matrix, it would be better to think of it like this:
newcommand{manualtwolinematrix}[10]{%
begin{matrix}
#1 & #2 & #3 & #4 & #5 \ #6 & #7 & #8 & #9 & #10
end{matrix}%
}
where #1 & #2 & #3 & #4 & #5 \ #6 & #7 & #8 & #9 & #10
is the string that has to be auto-generated within the body of our macro. Our macro gets input pairwise, so we have to generate this string given pairs. Okay, then in the body of our macro, we should have two variables: call it firstrow
and secondrow
.
The firstrow
and secondrow
should be built up sequentially, given each pair of elements, and then finally a variable called matrixbody
should be generated like so:
matrixbody = firstrow \ secondrow
Can you help me put these thoughts together?
macros
This answer shows me how I can handle an arbitrary number of arguments. I have adapted it a bit to my purpose:
usepackage{pgffor}
newcommand*{twolinematrix}[1]{%
foreach firstrowelement/secondrowelement in {#1} {%
<something should happen here!}%
}
}
The above macro should take input like this as an example: autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
.
I have become stuck because, normally, if you want to create a matrix (assuming you have amsmath
loaded), you would so something like:
newcommand{manualtwolinematrix}[10]{%
begin{matrix}
#1 & #2 & #3 & #4 & #5 \
#6 & #7 & #8 & #9 & #10
end{matrix}%
}
So, this suggests that you'd need to have logic that knows when you are about to be done with the element pairs, because you have to put the \
. I think if we are programmatically generating the matrix, it would be better to think of it like this:
newcommand{manualtwolinematrix}[10]{%
begin{matrix}
#1 & #2 & #3 & #4 & #5 \ #6 & #7 & #8 & #9 & #10
end{matrix}%
}
where #1 & #2 & #3 & #4 & #5 \ #6 & #7 & #8 & #9 & #10
is the string that has to be auto-generated within the body of our macro. Our macro gets input pairwise, so we have to generate this string given pairs. Okay, then in the body of our macro, we should have two variables: call it firstrow
and secondrow
.
The firstrow
and secondrow
should be built up sequentially, given each pair of elements, and then finally a variable called matrixbody
should be generated like so:
matrixbody = firstrow \ secondrow
Can you help me put these thoughts together?
macros
macros
asked Sep 24 '17 at 19:20
user89user89
1,5362933
1,5362933
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Perhaps less attractive than hand-made recursive macros, here is an implementation in expl3
.
I also added an optional argument (default empty) for producing different matrix types; the optional argument should be among p
, b
, B
, v
or V
, for the corresponding type.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
setcounter{MaxMatrixCols}{20} % or maybe more
ExplSyntaxOn
NewDocumentCommand{twolinematrix}{O{}m}
{
twoline_matrix:nn { #1 } { #2 }
}
seq_new:N l__twoline_i_seq
seq_new:N l__twoline_ii_seq
cs_new_protected:Nn twoline_matrix:nn
{
seq_clear:N l__twoline_i_seq
seq_clear:N l__twoline_ii_seq
clist_map_function:nN { #2 } twoline_add:n
begin{#1matrix}
seq_use:Nn l__twoline_i_seq { & }
\
seq_use:Nn l__twoline_ii_seq { & }
end{#1matrix}
}
cs_new_protected:Nn twoline_add:n
{
__twoline_add:w #1 q_stop
}
cs_new_protected:Npn __twoline_add:w #1/#2 q_stop
{
seq_put_right:Nn l__twoline_i_seq { #1 }
seq_put_right:Nn l__twoline_ii_seq { #2 }
}
ExplSyntaxOff
begin{document}
[
twolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
qquad
twolinematrix[b]{1/6, 2/7, 3/8, 4/9, 5/10, 6/11, 7/12, 8/13, 9/14, 10/15}
]
end{document}
This isn't really so different from wipet's code.
- We clear the containers for the rows (here sequences)
- We map the input given as a comma separated list, calling the internal function
__twoline_add:w
that splits each item at the slash and adds the pieces to the sequences - We use the sequences, placing
&
between items
There is no need to do different things for the first item and the others, this is taken care of by seq_use:Nn
, which only adds between items.
The advantage over the seemingly more compact code is that we don't need to reinvent the wheel, but just to give an appropriate definition for the action on each item of the comma separated list.
For a deeper explanation of the code, see this: https://tug.org/TUGboat/tb39-1/tb121gregorio-expl3.pdf
wow...look ma! latex3e!
– user89
Sep 25 '17 at 1:38
add a comment |
For example, you can use this code:
defaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}
defautotwolinematrix#1{deffirstrow{}defsecondrow{}atwolmA#1,/,}
defatwolmA#1/#2,{ifx,#2,pmatrix{firstrowcrsecondrow}else
ifxfirstrowempty deffirstrow{#1}defsecondrow{#2}else
addtofirstrow{}addtosecondrow{}fi
expandafter atwolmA fi
}
test:
$$
autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
$$
bye
First step: firstrow
and secondrow
are set in the loop while parameters are read. Second step: these macros are used in pmatrix
.
add a comment |
Inside alignments it is best to use an expandable loop construct, so using expl3
or here I just code it directly.
documentclass{article}
makeatletter
defautotwolinematrix#1{%
begin{bmatrix}%
firstrow,#1,relax/%
secondrow,#1,relax/%
}
deffirstrow#1,#2/{ifxrelax#2\elseifxrelax#1relaxelse&fi#2expandafterfirstrowfi}
defsecondrow#1,#2/{ifxrelax#2#1end{bmatrix}else#1ifxrelax#1relaxelse&fiexpandaftersecondrowfi}
makeatother
usepackage{amsmath}
begin{document}
$autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}$
end{document}
Your second loop ends byifxrelaxelse ...do somethingfi
. This was not probably your intend... Moreover, there is empty column at the end of the matrix.
– wipet
Sep 24 '17 at 20:32
@wipet theifx
was OK I think but I did have an extra&
as you said. Thanks. Fixed now (not as elegant as it was but I wanted to keep the expandable loop to keep the distinction between the answers:-) usedbmatrix
to make the column count clearer.
– David Carlisle
Sep 24 '17 at 21:33
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',
autoActivateHeartbeat: false,
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%2f393053%2fhow-to-generate-a-matrix-from-an-arbitrary-sequence-of-arguments%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Perhaps less attractive than hand-made recursive macros, here is an implementation in expl3
.
I also added an optional argument (default empty) for producing different matrix types; the optional argument should be among p
, b
, B
, v
or V
, for the corresponding type.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
setcounter{MaxMatrixCols}{20} % or maybe more
ExplSyntaxOn
NewDocumentCommand{twolinematrix}{O{}m}
{
twoline_matrix:nn { #1 } { #2 }
}
seq_new:N l__twoline_i_seq
seq_new:N l__twoline_ii_seq
cs_new_protected:Nn twoline_matrix:nn
{
seq_clear:N l__twoline_i_seq
seq_clear:N l__twoline_ii_seq
clist_map_function:nN { #2 } twoline_add:n
begin{#1matrix}
seq_use:Nn l__twoline_i_seq { & }
\
seq_use:Nn l__twoline_ii_seq { & }
end{#1matrix}
}
cs_new_protected:Nn twoline_add:n
{
__twoline_add:w #1 q_stop
}
cs_new_protected:Npn __twoline_add:w #1/#2 q_stop
{
seq_put_right:Nn l__twoline_i_seq { #1 }
seq_put_right:Nn l__twoline_ii_seq { #2 }
}
ExplSyntaxOff
begin{document}
[
twolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
qquad
twolinematrix[b]{1/6, 2/7, 3/8, 4/9, 5/10, 6/11, 7/12, 8/13, 9/14, 10/15}
]
end{document}
This isn't really so different from wipet's code.
- We clear the containers for the rows (here sequences)
- We map the input given as a comma separated list, calling the internal function
__twoline_add:w
that splits each item at the slash and adds the pieces to the sequences - We use the sequences, placing
&
between items
There is no need to do different things for the first item and the others, this is taken care of by seq_use:Nn
, which only adds between items.
The advantage over the seemingly more compact code is that we don't need to reinvent the wheel, but just to give an appropriate definition for the action on each item of the comma separated list.
For a deeper explanation of the code, see this: https://tug.org/TUGboat/tb39-1/tb121gregorio-expl3.pdf
wow...look ma! latex3e!
– user89
Sep 25 '17 at 1:38
add a comment |
Perhaps less attractive than hand-made recursive macros, here is an implementation in expl3
.
I also added an optional argument (default empty) for producing different matrix types; the optional argument should be among p
, b
, B
, v
or V
, for the corresponding type.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
setcounter{MaxMatrixCols}{20} % or maybe more
ExplSyntaxOn
NewDocumentCommand{twolinematrix}{O{}m}
{
twoline_matrix:nn { #1 } { #2 }
}
seq_new:N l__twoline_i_seq
seq_new:N l__twoline_ii_seq
cs_new_protected:Nn twoline_matrix:nn
{
seq_clear:N l__twoline_i_seq
seq_clear:N l__twoline_ii_seq
clist_map_function:nN { #2 } twoline_add:n
begin{#1matrix}
seq_use:Nn l__twoline_i_seq { & }
\
seq_use:Nn l__twoline_ii_seq { & }
end{#1matrix}
}
cs_new_protected:Nn twoline_add:n
{
__twoline_add:w #1 q_stop
}
cs_new_protected:Npn __twoline_add:w #1/#2 q_stop
{
seq_put_right:Nn l__twoline_i_seq { #1 }
seq_put_right:Nn l__twoline_ii_seq { #2 }
}
ExplSyntaxOff
begin{document}
[
twolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
qquad
twolinematrix[b]{1/6, 2/7, 3/8, 4/9, 5/10, 6/11, 7/12, 8/13, 9/14, 10/15}
]
end{document}
This isn't really so different from wipet's code.
- We clear the containers for the rows (here sequences)
- We map the input given as a comma separated list, calling the internal function
__twoline_add:w
that splits each item at the slash and adds the pieces to the sequences - We use the sequences, placing
&
between items
There is no need to do different things for the first item and the others, this is taken care of by seq_use:Nn
, which only adds between items.
The advantage over the seemingly more compact code is that we don't need to reinvent the wheel, but just to give an appropriate definition for the action on each item of the comma separated list.
For a deeper explanation of the code, see this: https://tug.org/TUGboat/tb39-1/tb121gregorio-expl3.pdf
wow...look ma! latex3e!
– user89
Sep 25 '17 at 1:38
add a comment |
Perhaps less attractive than hand-made recursive macros, here is an implementation in expl3
.
I also added an optional argument (default empty) for producing different matrix types; the optional argument should be among p
, b
, B
, v
or V
, for the corresponding type.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
setcounter{MaxMatrixCols}{20} % or maybe more
ExplSyntaxOn
NewDocumentCommand{twolinematrix}{O{}m}
{
twoline_matrix:nn { #1 } { #2 }
}
seq_new:N l__twoline_i_seq
seq_new:N l__twoline_ii_seq
cs_new_protected:Nn twoline_matrix:nn
{
seq_clear:N l__twoline_i_seq
seq_clear:N l__twoline_ii_seq
clist_map_function:nN { #2 } twoline_add:n
begin{#1matrix}
seq_use:Nn l__twoline_i_seq { & }
\
seq_use:Nn l__twoline_ii_seq { & }
end{#1matrix}
}
cs_new_protected:Nn twoline_add:n
{
__twoline_add:w #1 q_stop
}
cs_new_protected:Npn __twoline_add:w #1/#2 q_stop
{
seq_put_right:Nn l__twoline_i_seq { #1 }
seq_put_right:Nn l__twoline_ii_seq { #2 }
}
ExplSyntaxOff
begin{document}
[
twolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
qquad
twolinematrix[b]{1/6, 2/7, 3/8, 4/9, 5/10, 6/11, 7/12, 8/13, 9/14, 10/15}
]
end{document}
This isn't really so different from wipet's code.
- We clear the containers for the rows (here sequences)
- We map the input given as a comma separated list, calling the internal function
__twoline_add:w
that splits each item at the slash and adds the pieces to the sequences - We use the sequences, placing
&
between items
There is no need to do different things for the first item and the others, this is taken care of by seq_use:Nn
, which only adds between items.
The advantage over the seemingly more compact code is that we don't need to reinvent the wheel, but just to give an appropriate definition for the action on each item of the comma separated list.
For a deeper explanation of the code, see this: https://tug.org/TUGboat/tb39-1/tb121gregorio-expl3.pdf
Perhaps less attractive than hand-made recursive macros, here is an implementation in expl3
.
I also added an optional argument (default empty) for producing different matrix types; the optional argument should be among p
, b
, B
, v
or V
, for the corresponding type.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
setcounter{MaxMatrixCols}{20} % or maybe more
ExplSyntaxOn
NewDocumentCommand{twolinematrix}{O{}m}
{
twoline_matrix:nn { #1 } { #2 }
}
seq_new:N l__twoline_i_seq
seq_new:N l__twoline_ii_seq
cs_new_protected:Nn twoline_matrix:nn
{
seq_clear:N l__twoline_i_seq
seq_clear:N l__twoline_ii_seq
clist_map_function:nN { #2 } twoline_add:n
begin{#1matrix}
seq_use:Nn l__twoline_i_seq { & }
\
seq_use:Nn l__twoline_ii_seq { & }
end{#1matrix}
}
cs_new_protected:Nn twoline_add:n
{
__twoline_add:w #1 q_stop
}
cs_new_protected:Npn __twoline_add:w #1/#2 q_stop
{
seq_put_right:Nn l__twoline_i_seq { #1 }
seq_put_right:Nn l__twoline_ii_seq { #2 }
}
ExplSyntaxOff
begin{document}
[
twolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
qquad
twolinematrix[b]{1/6, 2/7, 3/8, 4/9, 5/10, 6/11, 7/12, 8/13, 9/14, 10/15}
]
end{document}
This isn't really so different from wipet's code.
- We clear the containers for the rows (here sequences)
- We map the input given as a comma separated list, calling the internal function
__twoline_add:w
that splits each item at the slash and adds the pieces to the sequences - We use the sequences, placing
&
between items
There is no need to do different things for the first item and the others, this is taken care of by seq_use:Nn
, which only adds between items.
The advantage over the seemingly more compact code is that we don't need to reinvent the wheel, but just to give an appropriate definition for the action on each item of the comma separated list.
For a deeper explanation of the code, see this: https://tug.org/TUGboat/tb39-1/tb121gregorio-expl3.pdf
edited 2 mins ago
user89
1,5362933
1,5362933
answered Sep 24 '17 at 20:56
egregegreg
711k8618893173
711k8618893173
wow...look ma! latex3e!
– user89
Sep 25 '17 at 1:38
add a comment |
wow...look ma! latex3e!
– user89
Sep 25 '17 at 1:38
wow...look ma! latex3e!
– user89
Sep 25 '17 at 1:38
wow...look ma! latex3e!
– user89
Sep 25 '17 at 1:38
add a comment |
For example, you can use this code:
defaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}
defautotwolinematrix#1{deffirstrow{}defsecondrow{}atwolmA#1,/,}
defatwolmA#1/#2,{ifx,#2,pmatrix{firstrowcrsecondrow}else
ifxfirstrowempty deffirstrow{#1}defsecondrow{#2}else
addtofirstrow{}addtosecondrow{}fi
expandafter atwolmA fi
}
test:
$$
autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
$$
bye
First step: firstrow
and secondrow
are set in the loop while parameters are read. Second step: these macros are used in pmatrix
.
add a comment |
For example, you can use this code:
defaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}
defautotwolinematrix#1{deffirstrow{}defsecondrow{}atwolmA#1,/,}
defatwolmA#1/#2,{ifx,#2,pmatrix{firstrowcrsecondrow}else
ifxfirstrowempty deffirstrow{#1}defsecondrow{#2}else
addtofirstrow{}addtosecondrow{}fi
expandafter atwolmA fi
}
test:
$$
autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
$$
bye
First step: firstrow
and secondrow
are set in the loop while parameters are read. Second step: these macros are used in pmatrix
.
add a comment |
For example, you can use this code:
defaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}
defautotwolinematrix#1{deffirstrow{}defsecondrow{}atwolmA#1,/,}
defatwolmA#1/#2,{ifx,#2,pmatrix{firstrowcrsecondrow}else
ifxfirstrowempty deffirstrow{#1}defsecondrow{#2}else
addtofirstrow{}addtosecondrow{}fi
expandafter atwolmA fi
}
test:
$$
autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
$$
bye
First step: firstrow
and secondrow
are set in the loop while parameters are read. Second step: these macros are used in pmatrix
.
For example, you can use this code:
defaddto#1#2{expandafterdefexpandafter#1expandafter{#1#2}}
defautotwolinematrix#1{deffirstrow{}defsecondrow{}atwolmA#1,/,}
defatwolmA#1/#2,{ifx,#2,pmatrix{firstrowcrsecondrow}else
ifxfirstrowempty deffirstrow{#1}defsecondrow{#2}else
addtofirstrow{}addtosecondrow{}fi
expandafter atwolmA fi
}
test:
$$
autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}
$$
bye
First step: firstrow
and secondrow
are set in the loop while parameters are read. Second step: these macros are used in pmatrix
.
answered Sep 24 '17 at 20:20
wipetwipet
35k4881
35k4881
add a comment |
add a comment |
Inside alignments it is best to use an expandable loop construct, so using expl3
or here I just code it directly.
documentclass{article}
makeatletter
defautotwolinematrix#1{%
begin{bmatrix}%
firstrow,#1,relax/%
secondrow,#1,relax/%
}
deffirstrow#1,#2/{ifxrelax#2\elseifxrelax#1relaxelse&fi#2expandafterfirstrowfi}
defsecondrow#1,#2/{ifxrelax#2#1end{bmatrix}else#1ifxrelax#1relaxelse&fiexpandaftersecondrowfi}
makeatother
usepackage{amsmath}
begin{document}
$autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}$
end{document}
Your second loop ends byifxrelaxelse ...do somethingfi
. This was not probably your intend... Moreover, there is empty column at the end of the matrix.
– wipet
Sep 24 '17 at 20:32
@wipet theifx
was OK I think but I did have an extra&
as you said. Thanks. Fixed now (not as elegant as it was but I wanted to keep the expandable loop to keep the distinction between the answers:-) usedbmatrix
to make the column count clearer.
– David Carlisle
Sep 24 '17 at 21:33
add a comment |
Inside alignments it is best to use an expandable loop construct, so using expl3
or here I just code it directly.
documentclass{article}
makeatletter
defautotwolinematrix#1{%
begin{bmatrix}%
firstrow,#1,relax/%
secondrow,#1,relax/%
}
deffirstrow#1,#2/{ifxrelax#2\elseifxrelax#1relaxelse&fi#2expandafterfirstrowfi}
defsecondrow#1,#2/{ifxrelax#2#1end{bmatrix}else#1ifxrelax#1relaxelse&fiexpandaftersecondrowfi}
makeatother
usepackage{amsmath}
begin{document}
$autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}$
end{document}
Your second loop ends byifxrelaxelse ...do somethingfi
. This was not probably your intend... Moreover, there is empty column at the end of the matrix.
– wipet
Sep 24 '17 at 20:32
@wipet theifx
was OK I think but I did have an extra&
as you said. Thanks. Fixed now (not as elegant as it was but I wanted to keep the expandable loop to keep the distinction between the answers:-) usedbmatrix
to make the column count clearer.
– David Carlisle
Sep 24 '17 at 21:33
add a comment |
Inside alignments it is best to use an expandable loop construct, so using expl3
or here I just code it directly.
documentclass{article}
makeatletter
defautotwolinematrix#1{%
begin{bmatrix}%
firstrow,#1,relax/%
secondrow,#1,relax/%
}
deffirstrow#1,#2/{ifxrelax#2\elseifxrelax#1relaxelse&fi#2expandafterfirstrowfi}
defsecondrow#1,#2/{ifxrelax#2#1end{bmatrix}else#1ifxrelax#1relaxelse&fiexpandaftersecondrowfi}
makeatother
usepackage{amsmath}
begin{document}
$autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}$
end{document}
Inside alignments it is best to use an expandable loop construct, so using expl3
or here I just code it directly.
documentclass{article}
makeatletter
defautotwolinematrix#1{%
begin{bmatrix}%
firstrow,#1,relax/%
secondrow,#1,relax/%
}
deffirstrow#1,#2/{ifxrelax#2\elseifxrelax#1relaxelse&fi#2expandafterfirstrowfi}
defsecondrow#1,#2/{ifxrelax#2#1end{bmatrix}else#1ifxrelax#1relaxelse&fiexpandaftersecondrowfi}
makeatother
usepackage{amsmath}
begin{document}
$autotwolinematrix{1/6, 2/7, 3/8, 4/9, 5/10}$
end{document}
edited Sep 24 '17 at 21:30
answered Sep 24 '17 at 20:19
David CarlisleDavid Carlisle
484k4011171858
484k4011171858
Your second loop ends byifxrelaxelse ...do somethingfi
. This was not probably your intend... Moreover, there is empty column at the end of the matrix.
– wipet
Sep 24 '17 at 20:32
@wipet theifx
was OK I think but I did have an extra&
as you said. Thanks. Fixed now (not as elegant as it was but I wanted to keep the expandable loop to keep the distinction between the answers:-) usedbmatrix
to make the column count clearer.
– David Carlisle
Sep 24 '17 at 21:33
add a comment |
Your second loop ends byifxrelaxelse ...do somethingfi
. This was not probably your intend... Moreover, there is empty column at the end of the matrix.
– wipet
Sep 24 '17 at 20:32
@wipet theifx
was OK I think but I did have an extra&
as you said. Thanks. Fixed now (not as elegant as it was but I wanted to keep the expandable loop to keep the distinction between the answers:-) usedbmatrix
to make the column count clearer.
– David Carlisle
Sep 24 '17 at 21:33
Your second loop ends by
ifxrelaxelse ...do somethingfi
. This was not probably your intend... Moreover, there is empty column at the end of the matrix.– wipet
Sep 24 '17 at 20:32
Your second loop ends by
ifxrelaxelse ...do somethingfi
. This was not probably your intend... Moreover, there is empty column at the end of the matrix.– wipet
Sep 24 '17 at 20:32
@wipet the
ifx
was OK I think but I did have an extra &
as you said. Thanks. Fixed now (not as elegant as it was but I wanted to keep the expandable loop to keep the distinction between the answers:-) used bmatrix
to make the column count clearer.– David Carlisle
Sep 24 '17 at 21:33
@wipet the
ifx
was OK I think but I did have an extra &
as you said. Thanks. Fixed now (not as elegant as it was but I wanted to keep the expandable loop to keep the distinction between the answers:-) used bmatrix
to make the column count clearer.– David Carlisle
Sep 24 '17 at 21:33
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%2f393053%2fhow-to-generate-a-matrix-from-an-arbitrary-sequence-of-arguments%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