Typesetting a Row Vectortypesetting column vectorcolumn and row vectors with builtin math modeIs there a...
How can bays and straits be determined in a procedurally generated map?
Does an object always see its latest internal state irrespective of thread?
Why do I get two different answers for this counting problem?
Character reincarnated...as a snail
Is it possible to do 50 km distance without any previous training?
Theorems that impeded progress
meaning of に in 本当に?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?
Can I ask the recruiters in my resume to put the reason why I am rejected?
What does it mean to describe someone as a butt steak?
Is it inappropriate for a student to attend their mentor's dissertation defense?
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
Java Casting: Java 11 throws LambdaConversionException while 1.8 does not
How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?
What typically incentivizes a professor to change jobs to a lower ranking university?
What does the "remote control" for a QF-4 look like?
What's the point of deactivating Num Lock on login screens?
Perform and show arithmetic with LuaLaTeX
NMaximize is not converging to a solution
Can you really stack all of this on an Opportunity Attack?
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
Book with a girl whose grandma is a phoenix, cover depicts the emerald/green-eyed blonde girl
Why doesn't H₄O²⁺ exist?
Typesetting a Row Vector
typesetting column vectorcolumn and row vectors with builtin math modeIs there a shorthand for matrices that doesn't use an environmenttypesetting column vectorHorizontal line representing row vector in matrixTypesetting a Row Vector - Vol 2Bold bracket row vector/matrixMulticolumn vectorAlignment of labeled vector with other vectosTypesetting inline row vectorRow vector problemHow to write the following vectorRow vector bracket size with double spacing
In the question typesetting a column vector, a very nice solution was given for typesetting a column vector with an arbitrary number of rows. I am attempting to modify the code to produce row vectors instead of column vectors. I made the "obvious" change, i.e., substituting the &
for the \
as indicated by the snippet below:
newcountcolveccount
newcommand*colvec[1]{
globalcolveccount#1
begin{pmatrix}
colvecnext
}
defcolvecnext#1{
#1
globaladvancecolveccount-1
ifnumcolveccount>0
&
expandaftercolvecnext
else
end{pmatrix}
fi
}
My modification however fails to compile and the errors, of course, are not very helpful. So my question is, How can I modify the
colvec
and colvecnext
macros to produce row vectors?math-mode matrices vector
add a comment |
In the question typesetting a column vector, a very nice solution was given for typesetting a column vector with an arbitrary number of rows. I am attempting to modify the code to produce row vectors instead of column vectors. I made the "obvious" change, i.e., substituting the &
for the \
as indicated by the snippet below:
newcountcolveccount
newcommand*colvec[1]{
globalcolveccount#1
begin{pmatrix}
colvecnext
}
defcolvecnext#1{
#1
globaladvancecolveccount-1
ifnumcolveccount>0
&
expandaftercolvecnext
else
end{pmatrix}
fi
}
My modification however fails to compile and the errors, of course, are not very helpful. So my question is, How can I modify the
colvec
and colvecnext
macros to produce row vectors?math-mode matrices vector
add a comment |
In the question typesetting a column vector, a very nice solution was given for typesetting a column vector with an arbitrary number of rows. I am attempting to modify the code to produce row vectors instead of column vectors. I made the "obvious" change, i.e., substituting the &
for the \
as indicated by the snippet below:
newcountcolveccount
newcommand*colvec[1]{
globalcolveccount#1
begin{pmatrix}
colvecnext
}
defcolvecnext#1{
#1
globaladvancecolveccount-1
ifnumcolveccount>0
&
expandaftercolvecnext
else
end{pmatrix}
fi
}
My modification however fails to compile and the errors, of course, are not very helpful. So my question is, How can I modify the
colvec
and colvecnext
macros to produce row vectors?math-mode matrices vector
In the question typesetting a column vector, a very nice solution was given for typesetting a column vector with an arbitrary number of rows. I am attempting to modify the code to produce row vectors instead of column vectors. I made the "obvious" change, i.e., substituting the &
for the \
as indicated by the snippet below:
newcountcolveccount
newcommand*colvec[1]{
globalcolveccount#1
begin{pmatrix}
colvecnext
}
defcolvecnext#1{
#1
globaladvancecolveccount-1
ifnumcolveccount>0
&
expandaftercolvecnext
else
end{pmatrix}
fi
}
My modification however fails to compile and the errors, of course, are not very helpful. So my question is, How can I modify the
colvec
and colvecnext
macros to produce row vectors?math-mode matrices vector
math-mode matrices vector
edited Apr 13 '17 at 12:35
Community♦
1
1
asked Dec 21 '11 at 21:17
3Sphere3Sphere
1,39131827
1,39131827
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You have to collect the row beforehand, as doing it inside an array environment is quite difficult, as TeX ends a cell as soon as it sees an &
. I prefer to do in with a token register and the count255
scratch counter.
We collect two arguments: the first is the number of entries, the second the first entry, in order to initialize the token register with it. We set the counter to the number of requested element (since we have already collected one, we step it down immediately).
Then we start the recursion; the macro rowvectnexta
examines the value of the counter; if it's still greater than 0, it calls rowvecnextb
that gathers another argument, stores it into the token register (adding an &
) and steps down the counter; otherwise it builds the pmatrix
by releasing the contents of the register.
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
It shouldn't be a big limitation the fact that you need at least one element:
rowvec{1}{a}
rowvec{2}{a}{b}
rowvec{3}{a}{b}{c}
Notice: usepackage{amsmath}
is required. So a minimal example might be the following.
documentclass{article}
usepackage{amsmath}
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
begin{document}
$rowvec{1}{a}$
$rowvec{2}{a}{b}$
$rowvec{3}{a}{b}{c}$
end{document}
A completely different solution that can be generalized to column vectors uses xparse
and LaTeX3.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{Rowvec}{ O{,} m }
{
vector_main:nnnn { p } { & } { #1 } { #2 }
}
NewDocumentCommand{Colvec}{ O{,} m }
{
vector_main:nnnn { p } { \ } { #1 } { #2 }
}
seq_new:N l__vector_arg_seq
cs_new_protected:Npn vector_main:nnnn #1 #2 #3 #4
{
seq_set_split:Nnn l__vector_arg_seq { #3 } { #4 }
begin{#1matrix}
seq_use:Nnnn l__vector_arg_seq { #2 } { #2 } { #2 }
end{#1matrix}
}
ExplSyntaxOff
begin{document}
$Rowvec{a}Rowvec{a,b}Rowvec[;]{a;b;c}$
$Colvec{a}Colvec{a,b}Colvec[;]{a;b;c}$
end{document}
The optional argument is the delimiter to be used to separate entries in the list given as argument.
It's sufficient to change { p }
into { b }
in the two main definitions to get brackets instead of parentheses.
Note: this requires expl3
dated September 2012 or later.
Thank you! Your solution works beautifully. Considering the necessary steps, my modification attempt was naively futile.
– 3Sphere
Dec 21 '11 at 22:05
3
I'll expand the answer: the TV was broadcasting Beethoven's Ninth from the new theater in Florence, so my main attention was to it. :)
– egreg
Dec 21 '11 at 22:15
1
I suggest adding this tomathtools
package.
– azetina
Nov 12 '13 at 19:55
add a comment |
I would like to suggest a dirty solution, which I use:
newcommand*{rowvec}[1]{left( #1right)}
The advantage is that its usage is simple: rowvec{a,b,c,d,e}
. I can easily imagine that it is not robust... For me it works.
add a comment |
This is an old question... but as it surfaced again let me point out that one can do these things without token register or macro storage or count registers.
documentclass{article}
usepackage{amsmath}
makeatletter
% USAGE Matrix { a,..,z; A,.., Z ; ... ; aA, ..., zZ}
% NO semi-colon for the last row.
newcommand{Matrix}[1]
{begin{pmatrix}
Matrix@r #1;@bye;Matrix@r
end{pmatrix}}
defMatrix@r #1;{@bye #1Matrix@z@byeMatrix@s #1,@bye, }%
defMatrix@s #1,{#1Matrix@t }%
defMatrix@t #1,{@bye #1Matrix@y@bye@firstofone {}Matrix@t}%
defMatrix@y #1Matrix@t{\ Matrix@r }%
defMatrix@z #1Matrix@r {}
def@bye #1@bye {}% (the idea of @bye is from xint code)
makeatother
begin{document}thispagestyle{empty}
[ Matrix { a, b , c , d ; e ,f , 3, 5; 8, -1, x, y }]
[ Matrix { abc , mathrm{XYZ}; 7, 913; alpha, beta }]
end{document}
add a comment |
This is an extension to row vectors of my suggestion for column vectors, see here. The idea is to use a similar plain TeX mechanism, and separate the entries with a pipe. Again, the interface with parentheses is the same as used by PSTricks.
The code is:
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
and a MWE would be:
documentclass[margin=2pt]{standalone}
makeatletter
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
makeatother
begin{document}
$Pcoords(-3,+4,frac51)$
end{document}
Because the macros make use of the @i
notation the code will have to be placed inside at makeatletter
- makeatother
wrapping before document begins.
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%2f39051%2ftypesetting-a-row-vector%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have to collect the row beforehand, as doing it inside an array environment is quite difficult, as TeX ends a cell as soon as it sees an &
. I prefer to do in with a token register and the count255
scratch counter.
We collect two arguments: the first is the number of entries, the second the first entry, in order to initialize the token register with it. We set the counter to the number of requested element (since we have already collected one, we step it down immediately).
Then we start the recursion; the macro rowvectnexta
examines the value of the counter; if it's still greater than 0, it calls rowvecnextb
that gathers another argument, stores it into the token register (adding an &
) and steps down the counter; otherwise it builds the pmatrix
by releasing the contents of the register.
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
It shouldn't be a big limitation the fact that you need at least one element:
rowvec{1}{a}
rowvec{2}{a}{b}
rowvec{3}{a}{b}{c}
Notice: usepackage{amsmath}
is required. So a minimal example might be the following.
documentclass{article}
usepackage{amsmath}
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
begin{document}
$rowvec{1}{a}$
$rowvec{2}{a}{b}$
$rowvec{3}{a}{b}{c}$
end{document}
A completely different solution that can be generalized to column vectors uses xparse
and LaTeX3.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{Rowvec}{ O{,} m }
{
vector_main:nnnn { p } { & } { #1 } { #2 }
}
NewDocumentCommand{Colvec}{ O{,} m }
{
vector_main:nnnn { p } { \ } { #1 } { #2 }
}
seq_new:N l__vector_arg_seq
cs_new_protected:Npn vector_main:nnnn #1 #2 #3 #4
{
seq_set_split:Nnn l__vector_arg_seq { #3 } { #4 }
begin{#1matrix}
seq_use:Nnnn l__vector_arg_seq { #2 } { #2 } { #2 }
end{#1matrix}
}
ExplSyntaxOff
begin{document}
$Rowvec{a}Rowvec{a,b}Rowvec[;]{a;b;c}$
$Colvec{a}Colvec{a,b}Colvec[;]{a;b;c}$
end{document}
The optional argument is the delimiter to be used to separate entries in the list given as argument.
It's sufficient to change { p }
into { b }
in the two main definitions to get brackets instead of parentheses.
Note: this requires expl3
dated September 2012 or later.
Thank you! Your solution works beautifully. Considering the necessary steps, my modification attempt was naively futile.
– 3Sphere
Dec 21 '11 at 22:05
3
I'll expand the answer: the TV was broadcasting Beethoven's Ninth from the new theater in Florence, so my main attention was to it. :)
– egreg
Dec 21 '11 at 22:15
1
I suggest adding this tomathtools
package.
– azetina
Nov 12 '13 at 19:55
add a comment |
You have to collect the row beforehand, as doing it inside an array environment is quite difficult, as TeX ends a cell as soon as it sees an &
. I prefer to do in with a token register and the count255
scratch counter.
We collect two arguments: the first is the number of entries, the second the first entry, in order to initialize the token register with it. We set the counter to the number of requested element (since we have already collected one, we step it down immediately).
Then we start the recursion; the macro rowvectnexta
examines the value of the counter; if it's still greater than 0, it calls rowvecnextb
that gathers another argument, stores it into the token register (adding an &
) and steps down the counter; otherwise it builds the pmatrix
by releasing the contents of the register.
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
It shouldn't be a big limitation the fact that you need at least one element:
rowvec{1}{a}
rowvec{2}{a}{b}
rowvec{3}{a}{b}{c}
Notice: usepackage{amsmath}
is required. So a minimal example might be the following.
documentclass{article}
usepackage{amsmath}
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
begin{document}
$rowvec{1}{a}$
$rowvec{2}{a}{b}$
$rowvec{3}{a}{b}{c}$
end{document}
A completely different solution that can be generalized to column vectors uses xparse
and LaTeX3.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{Rowvec}{ O{,} m }
{
vector_main:nnnn { p } { & } { #1 } { #2 }
}
NewDocumentCommand{Colvec}{ O{,} m }
{
vector_main:nnnn { p } { \ } { #1 } { #2 }
}
seq_new:N l__vector_arg_seq
cs_new_protected:Npn vector_main:nnnn #1 #2 #3 #4
{
seq_set_split:Nnn l__vector_arg_seq { #3 } { #4 }
begin{#1matrix}
seq_use:Nnnn l__vector_arg_seq { #2 } { #2 } { #2 }
end{#1matrix}
}
ExplSyntaxOff
begin{document}
$Rowvec{a}Rowvec{a,b}Rowvec[;]{a;b;c}$
$Colvec{a}Colvec{a,b}Colvec[;]{a;b;c}$
end{document}
The optional argument is the delimiter to be used to separate entries in the list given as argument.
It's sufficient to change { p }
into { b }
in the two main definitions to get brackets instead of parentheses.
Note: this requires expl3
dated September 2012 or later.
Thank you! Your solution works beautifully. Considering the necessary steps, my modification attempt was naively futile.
– 3Sphere
Dec 21 '11 at 22:05
3
I'll expand the answer: the TV was broadcasting Beethoven's Ninth from the new theater in Florence, so my main attention was to it. :)
– egreg
Dec 21 '11 at 22:15
1
I suggest adding this tomathtools
package.
– azetina
Nov 12 '13 at 19:55
add a comment |
You have to collect the row beforehand, as doing it inside an array environment is quite difficult, as TeX ends a cell as soon as it sees an &
. I prefer to do in with a token register and the count255
scratch counter.
We collect two arguments: the first is the number of entries, the second the first entry, in order to initialize the token register with it. We set the counter to the number of requested element (since we have already collected one, we step it down immediately).
Then we start the recursion; the macro rowvectnexta
examines the value of the counter; if it's still greater than 0, it calls rowvecnextb
that gathers another argument, stores it into the token register (adding an &
) and steps down the counter; otherwise it builds the pmatrix
by releasing the contents of the register.
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
It shouldn't be a big limitation the fact that you need at least one element:
rowvec{1}{a}
rowvec{2}{a}{b}
rowvec{3}{a}{b}{c}
Notice: usepackage{amsmath}
is required. So a minimal example might be the following.
documentclass{article}
usepackage{amsmath}
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
begin{document}
$rowvec{1}{a}$
$rowvec{2}{a}{b}$
$rowvec{3}{a}{b}{c}$
end{document}
A completely different solution that can be generalized to column vectors uses xparse
and LaTeX3.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{Rowvec}{ O{,} m }
{
vector_main:nnnn { p } { & } { #1 } { #2 }
}
NewDocumentCommand{Colvec}{ O{,} m }
{
vector_main:nnnn { p } { \ } { #1 } { #2 }
}
seq_new:N l__vector_arg_seq
cs_new_protected:Npn vector_main:nnnn #1 #2 #3 #4
{
seq_set_split:Nnn l__vector_arg_seq { #3 } { #4 }
begin{#1matrix}
seq_use:Nnnn l__vector_arg_seq { #2 } { #2 } { #2 }
end{#1matrix}
}
ExplSyntaxOff
begin{document}
$Rowvec{a}Rowvec{a,b}Rowvec[;]{a;b;c}$
$Colvec{a}Colvec{a,b}Colvec[;]{a;b;c}$
end{document}
The optional argument is the delimiter to be used to separate entries in the list given as argument.
It's sufficient to change { p }
into { b }
in the two main definitions to get brackets instead of parentheses.
Note: this requires expl3
dated September 2012 or later.
You have to collect the row beforehand, as doing it inside an array environment is quite difficult, as TeX ends a cell as soon as it sees an &
. I prefer to do in with a token register and the count255
scratch counter.
We collect two arguments: the first is the number of entries, the second the first entry, in order to initialize the token register with it. We set the counter to the number of requested element (since we have already collected one, we step it down immediately).
Then we start the recursion; the macro rowvectnexta
examines the value of the counter; if it's still greater than 0, it calls rowvecnextb
that gathers another argument, stores it into the token register (adding an &
) and steps down the counter; otherwise it builds the pmatrix
by releasing the contents of the register.
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
It shouldn't be a big limitation the fact that you need at least one element:
rowvec{1}{a}
rowvec{2}{a}{b}
rowvec{3}{a}{b}{c}
Notice: usepackage{amsmath}
is required. So a minimal example might be the following.
documentclass{article}
usepackage{amsmath}
newtoksrowvectoks
newcommand{rowvec}[2]{%
rowvectoks={#2}count255=#1relax
advancecount255 by -1
rowvecnexta}
newcommand{rowvecnexta}{%
ifnumcount255>0
expandafterrowvecnextb
else
begin{pmatrix}therowvectoksend{pmatrix}
fi}
newcommandrowvecnextb[1]{%
rowvectoks=expandafter{therowvectoks}%
advancecount255 by -1
rowvecnexta}
begin{document}
$rowvec{1}{a}$
$rowvec{2}{a}{b}$
$rowvec{3}{a}{b}{c}$
end{document}
A completely different solution that can be generalized to column vectors uses xparse
and LaTeX3.
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{Rowvec}{ O{,} m }
{
vector_main:nnnn { p } { & } { #1 } { #2 }
}
NewDocumentCommand{Colvec}{ O{,} m }
{
vector_main:nnnn { p } { \ } { #1 } { #2 }
}
seq_new:N l__vector_arg_seq
cs_new_protected:Npn vector_main:nnnn #1 #2 #3 #4
{
seq_set_split:Nnn l__vector_arg_seq { #3 } { #4 }
begin{#1matrix}
seq_use:Nnnn l__vector_arg_seq { #2 } { #2 } { #2 }
end{#1matrix}
}
ExplSyntaxOff
begin{document}
$Rowvec{a}Rowvec{a,b}Rowvec[;]{a;b;c}$
$Colvec{a}Colvec{a,b}Colvec[;]{a;b;c}$
end{document}
The optional argument is the delimiter to be used to separate entries in the list given as argument.
It's sufficient to change { p }
into { b }
in the two main definitions to get brackets instead of parentheses.
Note: this requires expl3
dated September 2012 or later.
edited Sep 30 '12 at 16:23
answered Dec 21 '11 at 21:47
egregegreg
732k8919303253
732k8919303253
Thank you! Your solution works beautifully. Considering the necessary steps, my modification attempt was naively futile.
– 3Sphere
Dec 21 '11 at 22:05
3
I'll expand the answer: the TV was broadcasting Beethoven's Ninth from the new theater in Florence, so my main attention was to it. :)
– egreg
Dec 21 '11 at 22:15
1
I suggest adding this tomathtools
package.
– azetina
Nov 12 '13 at 19:55
add a comment |
Thank you! Your solution works beautifully. Considering the necessary steps, my modification attempt was naively futile.
– 3Sphere
Dec 21 '11 at 22:05
3
I'll expand the answer: the TV was broadcasting Beethoven's Ninth from the new theater in Florence, so my main attention was to it. :)
– egreg
Dec 21 '11 at 22:15
1
I suggest adding this tomathtools
package.
– azetina
Nov 12 '13 at 19:55
Thank you! Your solution works beautifully. Considering the necessary steps, my modification attempt was naively futile.
– 3Sphere
Dec 21 '11 at 22:05
Thank you! Your solution works beautifully. Considering the necessary steps, my modification attempt was naively futile.
– 3Sphere
Dec 21 '11 at 22:05
3
3
I'll expand the answer: the TV was broadcasting Beethoven's Ninth from the new theater in Florence, so my main attention was to it. :)
– egreg
Dec 21 '11 at 22:15
I'll expand the answer: the TV was broadcasting Beethoven's Ninth from the new theater in Florence, so my main attention was to it. :)
– egreg
Dec 21 '11 at 22:15
1
1
I suggest adding this to
mathtools
package.– azetina
Nov 12 '13 at 19:55
I suggest adding this to
mathtools
package.– azetina
Nov 12 '13 at 19:55
add a comment |
I would like to suggest a dirty solution, which I use:
newcommand*{rowvec}[1]{left( #1right)}
The advantage is that its usage is simple: rowvec{a,b,c,d,e}
. I can easily imagine that it is not robust... For me it works.
add a comment |
I would like to suggest a dirty solution, which I use:
newcommand*{rowvec}[1]{left( #1right)}
The advantage is that its usage is simple: rowvec{a,b,c,d,e}
. I can easily imagine that it is not robust... For me it works.
add a comment |
I would like to suggest a dirty solution, which I use:
newcommand*{rowvec}[1]{left( #1right)}
The advantage is that its usage is simple: rowvec{a,b,c,d,e}
. I can easily imagine that it is not robust... For me it works.
I would like to suggest a dirty solution, which I use:
newcommand*{rowvec}[1]{left( #1right)}
The advantage is that its usage is simple: rowvec{a,b,c,d,e}
. I can easily imagine that it is not robust... For me it works.
answered Nov 12 '13 at 19:45
DrorDror
11.2k1973150
11.2k1973150
add a comment |
add a comment |
This is an old question... but as it surfaced again let me point out that one can do these things without token register or macro storage or count registers.
documentclass{article}
usepackage{amsmath}
makeatletter
% USAGE Matrix { a,..,z; A,.., Z ; ... ; aA, ..., zZ}
% NO semi-colon for the last row.
newcommand{Matrix}[1]
{begin{pmatrix}
Matrix@r #1;@bye;Matrix@r
end{pmatrix}}
defMatrix@r #1;{@bye #1Matrix@z@byeMatrix@s #1,@bye, }%
defMatrix@s #1,{#1Matrix@t }%
defMatrix@t #1,{@bye #1Matrix@y@bye@firstofone {}Matrix@t}%
defMatrix@y #1Matrix@t{\ Matrix@r }%
defMatrix@z #1Matrix@r {}
def@bye #1@bye {}% (the idea of @bye is from xint code)
makeatother
begin{document}thispagestyle{empty}
[ Matrix { a, b , c , d ; e ,f , 3, 5; 8, -1, x, y }]
[ Matrix { abc , mathrm{XYZ}; 7, 913; alpha, beta }]
end{document}
add a comment |
This is an old question... but as it surfaced again let me point out that one can do these things without token register or macro storage or count registers.
documentclass{article}
usepackage{amsmath}
makeatletter
% USAGE Matrix { a,..,z; A,.., Z ; ... ; aA, ..., zZ}
% NO semi-colon for the last row.
newcommand{Matrix}[1]
{begin{pmatrix}
Matrix@r #1;@bye;Matrix@r
end{pmatrix}}
defMatrix@r #1;{@bye #1Matrix@z@byeMatrix@s #1,@bye, }%
defMatrix@s #1,{#1Matrix@t }%
defMatrix@t #1,{@bye #1Matrix@y@bye@firstofone {}Matrix@t}%
defMatrix@y #1Matrix@t{\ Matrix@r }%
defMatrix@z #1Matrix@r {}
def@bye #1@bye {}% (the idea of @bye is from xint code)
makeatother
begin{document}thispagestyle{empty}
[ Matrix { a, b , c , d ; e ,f , 3, 5; 8, -1, x, y }]
[ Matrix { abc , mathrm{XYZ}; 7, 913; alpha, beta }]
end{document}
add a comment |
This is an old question... but as it surfaced again let me point out that one can do these things without token register or macro storage or count registers.
documentclass{article}
usepackage{amsmath}
makeatletter
% USAGE Matrix { a,..,z; A,.., Z ; ... ; aA, ..., zZ}
% NO semi-colon for the last row.
newcommand{Matrix}[1]
{begin{pmatrix}
Matrix@r #1;@bye;Matrix@r
end{pmatrix}}
defMatrix@r #1;{@bye #1Matrix@z@byeMatrix@s #1,@bye, }%
defMatrix@s #1,{#1Matrix@t }%
defMatrix@t #1,{@bye #1Matrix@y@bye@firstofone {}Matrix@t}%
defMatrix@y #1Matrix@t{\ Matrix@r }%
defMatrix@z #1Matrix@r {}
def@bye #1@bye {}% (the idea of @bye is from xint code)
makeatother
begin{document}thispagestyle{empty}
[ Matrix { a, b , c , d ; e ,f , 3, 5; 8, -1, x, y }]
[ Matrix { abc , mathrm{XYZ}; 7, 913; alpha, beta }]
end{document}
This is an old question... but as it surfaced again let me point out that one can do these things without token register or macro storage or count registers.
documentclass{article}
usepackage{amsmath}
makeatletter
% USAGE Matrix { a,..,z; A,.., Z ; ... ; aA, ..., zZ}
% NO semi-colon for the last row.
newcommand{Matrix}[1]
{begin{pmatrix}
Matrix@r #1;@bye;Matrix@r
end{pmatrix}}
defMatrix@r #1;{@bye #1Matrix@z@byeMatrix@s #1,@bye, }%
defMatrix@s #1,{#1Matrix@t }%
defMatrix@t #1,{@bye #1Matrix@y@bye@firstofone {}Matrix@t}%
defMatrix@y #1Matrix@t{\ Matrix@r }%
defMatrix@z #1Matrix@r {}
def@bye #1@bye {}% (the idea of @bye is from xint code)
makeatother
begin{document}thispagestyle{empty}
[ Matrix { a, b , c , d ; e ,f , 3, 5; 8, -1, x, y }]
[ Matrix { abc , mathrm{XYZ}; 7, 913; alpha, beta }]
end{document}
answered Nov 12 '13 at 21:29
user4686
add a comment |
add a comment |
This is an extension to row vectors of my suggestion for column vectors, see here. The idea is to use a similar plain TeX mechanism, and separate the entries with a pipe. Again, the interface with parentheses is the same as used by PSTricks.
The code is:
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
and a MWE would be:
documentclass[margin=2pt]{standalone}
makeatletter
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
makeatother
begin{document}
$Pcoords(-3,+4,frac51)$
end{document}
Because the macros make use of the @i
notation the code will have to be placed inside at makeatletter
- makeatother
wrapping before document begins.
add a comment |
This is an extension to row vectors of my suggestion for column vectors, see here. The idea is to use a similar plain TeX mechanism, and separate the entries with a pipe. Again, the interface with parentheses is the same as used by PSTricks.
The code is:
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
and a MWE would be:
documentclass[margin=2pt]{standalone}
makeatletter
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
makeatother
begin{document}
$Pcoords(-3,+4,frac51)$
end{document}
Because the macros make use of the @i
notation the code will have to be placed inside at makeatletter
- makeatother
wrapping before document begins.
add a comment |
This is an extension to row vectors of my suggestion for column vectors, see here. The idea is to use a similar plain TeX mechanism, and separate the entries with a pipe. Again, the interface with parentheses is the same as used by PSTricks.
The code is:
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
and a MWE would be:
documentclass[margin=2pt]{standalone}
makeatletter
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
makeatother
begin{document}
$Pcoords(-3,+4,frac51)$
end{document}
Because the macros make use of the @i
notation the code will have to be placed inside at makeatletter
- makeatother
wrapping before document begins.
This is an extension to row vectors of my suggestion for column vectors, see here. The idea is to use a similar plain TeX mechanism, and separate the entries with a pipe. Again, the interface with parentheses is the same as used by PSTricks.
The code is:
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
and a MWE would be:
documentclass[margin=2pt]{standalone}
makeatletter
defcoords(#1,#2){!left({textstyle#1coords@i#2,,}right)}
defcoords@i#1,{if,#1,else|{#1}expandaftercoords@ifi}
makeatother
begin{document}
$Pcoords(-3,+4,frac51)$
end{document}
Because the macros make use of the @i
notation the code will have to be placed inside at makeatletter
- makeatother
wrapping before document begins.
answered 9 hours ago
fborchersfborchers
839
839
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.
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%2f39051%2ftypesetting-a-row-vector%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