# Typesetting inline row vector

I have (another) question on typesetting inline row vectors. I'm using amsmath and mathtools. I'm aware of the smallmatrix environment. Unfortunately, the elements of the vector get scaled. This seems completely unnecessary to me. Also the bmatrix environment is not a solution for me, since the delimiters are larger than "normal" text brackets.

I'd like to have something more like

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
Text $[\,x^* \quad y^*\,]^*$
$\begin{bmatrix} x^* & y^* \end{bmatrix}^* or \begin{bsmallmatrix} x^* & y^* \end{bsmallmatrix}^*$

\end{document}


Is there a package that can handle this special case for an arbitrary number of elements in the row vector?

I recommend a general solution so that you can change the behaviour later, apart from using a more clean input code. Here's one with expl3.

\documentclass{scrartcl}

\usepackage{xparse,mathtools}

\ExplSyntaxOn

\NewDocumentCommand \vect { s o m }
{
\IfBooleanTF {#1}
{ \vectaux*{#3} }
{ \IfValueTF {#2} { \vectaux[#2]{#3} } { \vectaux{#3} } }
^*
}

\DeclarePairedDelimiterX \vectaux [1] {\lbrack} {\rbrack}
{ \, \dbacc_vect:n { #1 } \, }

\cs_new_protected:Npn \dbacc_vect:n #1
{
\seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
\seq_use:Nn \l_tmpa_seq { \enspace }
}
\ExplSyntaxOff

\begin{document}

Text
$\vect{x^*,y^*}$
$\begin{bsmallmatrix} x^* & y^* \end{bsmallmatrix}^*$

\end{document}


And you can input \vect{x,y,z,t,u,v}, or \vect*{\int,\sum,\prod} or \vect[\Big]{a,b,\frac{n}{z}}, etc. like any other delimiter from \DeclarePairedDelimiter. Substitute \enspace for any space you want.

In case what you want is to input \vect{x,y,z} and get [x^* y^* z^*]^* just change one command

\cs_new_protected:Npn \dbacc_vect:n #1
{
\seq_clear:N \l_tmpb_seq
\seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
\seq_map_inline:Nn \l_tmpa_seq { \seq_put_right:Nn \l_tmpb_seq { ##1^* } }
\seq_use:Nn \l_tmpb_seq { \enspace }
}

• Thanks a lot. This seems really like a robust implementation. Is it possible to put a star on each element of a vector for the starred version? – dba Sep 10 '15 at 14:36
• Instead of \enspace you could add any other spacing like \quad (which, in my opinion is too much), or even use matrixes like egreg solutions; and maybe even more useful would be to use \enspace\allowbreak so, for long vectors it would break across lines (except if you use the starred version \vect*{a,a,a,a,a,a,a,a}). In any case, the basic idea is to use a nice syntax, which, apart from clarity, gives you the power to change the behaviour later. – Manuel Sep 10 '15 at 15:35
• My question was rather how to get stars on each element automatically. E.g. if I put ^* in here \seq_use:Nn \l_tmpa_seq { ^* \enspace }, this will not respect the last element – dba Sep 11 '15 at 8:22
• How to get stars? That was definitely not clear. In any case, I will just update. – Manuel Sep 11 '15 at 9:28

My suggestion is to simply type

\begin{bmatrix} x^* & y^* \end{bmatrix}


perhaps with a proper definition like

\newcommand{\rvect}[1]{\begin{bmatrix} #1 \end{bmatrix}}


and inputting

\rvect{x^* & y^*}


If you consider the & a nuisance, you can use a comma separated list:

\documentclass{scrartcl}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\rvect}{m}
{
\seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
\begin{bmatrix}
\seq_use:Nn \l_tmpa_seq { & }
\end{bmatrix}
}
\ExplSyntaxOff

\begin{document}

Text
$\rvect{x^*,y^*}$

\end{document}


Alternative, with \DeclarePairedDelimiterX and matrix inside.

\documentclass{scrartcl}

\usepackage{xparse,mathtools}

\DeclarePairedDelimiterX{\rvect}[1]{[}{]}{\,\makervect{#1}\,}

\ExplSyntaxOn
\NewDocumentCommand{\makervect}{m}
{
\seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
\begin{matrix}
\seq_use:Nn \l_tmpa_seq { & }
\end{matrix}
}
\ExplSyntaxOff

\begin{document}

Text
$\rvect{x^*,y^*}$

\end{document}


You can manually increase the size of the delimiters with the usual optional argument to \rvect.

• Thanks. I should probably have mentioned this, the problem with bmatrix is that the delimiters take too much space. I do not want to blow up the space between text lines with inline formulas. – dba Sep 10 '15 at 14:35
• @dbacc Do they? I'm not sure they do. – egreg Sep 10 '15 at 14:35
• I edited my question and added a picture. This should show my problem. – dba Sep 10 '15 at 15:06
• @dbacc No, you don't get that picture, with your code. Are you using setspace and increased interline space? This would explain the problem, and, in this case, it should be mentioned in the question, because it's very important information. Anyway, my second solution doesn't show the issue. – egreg Sep 10 '15 at 15:10
• You're right. It's in my document where its getting that large Could not track it down to any package for now and no I'm not setting setspace or something similar. However, even in the snippet from my answer the brackets from bmatrix are larger – dba Sep 10 '15 at 15:15