Is there a way to make the solutions here

typesetting column vector

and here

Typesetting a Row Vector

work by including \ensuremath in their definitions?

  • 1
    Yes just add \ensuremath{...} around the existing definitions. What did you try? Using \ensuremath for such constructs is probably a bad idea though really, the TeX model is to have different commands for TeX and math and trying to over-use \ensuremath to use the same commands for both leads to pain in the end. Sep 22 '12 at 22:04
  • Of course I tried that, but no matter where I put the \ensuremath{} I always got an error telling me math delimiters were missing. Where's the best place to put them? Not having to specify math delimiters is a feature of the physics/math related package I'm developing. So far there have been no problems.
    – user19024
    Sep 22 '12 at 22:27
  • Oh sorry I just saw the first answer in the row case not the second that took arbitrary number of {} arguments. I would not use that syntax in LaTeX it breaks a very string latex syntax rule that commands always take the same argument form. Every documented latex command in the core distribution follows that. The way to get an arbitrary number of arguments is to use a single {} argument with a comma separated list. (That would also, not coincidentally, make it trivial to add \ensuremath) Sep 22 '12 at 22:45
  • Welcome to TeX.SE. Sep 23 '12 at 16:13

For the cases where you are starting and ending in different macros just split the definition of \ensuremath in to two. So put


At the start of the first macro definition and


at the end of the second one.

Note however a format such as LaTeX works best if package authors follow the syntax guidelines so that the language as a whole remains more or less coherent and consistent. TeX makes a big distinction between math mode and text mode \. is not the same as \dot for example, and a user needs to be aware if they are in math mode or text. Sometimes for some small symbols where the user may not really need to know that math mode is being used internally \ensuremath is useful, but it is not usually a good idea to use it for something like a vector taking user-supplied arguments as the user in any case needs to know that the supplied arguments are processed as math. Compare the standard LaTeX array environment, this is identical to tabular except that each cell is in math mode, however rather than make this switch to math mode implicit the environment checks that it is not already in math mode and makes an error if not. Thus the user needs to switch to math before using array. This error check is purely for maintaining language consistency, the array environment would otherwise work in the same way in text or math. Similar considerations apply to argument structure. LaTeX comamnds never take variable number of {} arguments. {} arguments are intended to be mandatory. Optional arguments should be in [] and variable number of items should be in comma separated list, so \colvec{a,b} would be a syntax far more compatible with latex than \colvec{a}{b} if the vector may be of arbitrary length.


I took David Carlisle's advice and found a solution here using a comma separated list of arguments. Arguments of custom commands as comma separated list? really helped me.


      \rc@vector #2,\relax\noexpand\@eolst%
\def\rc@vector #1,#2\@eolst{%
    \rc@vector #2\@eolst%




  • Clearly I give you +1 for taking my advice:-) Sep 25 '12 at 8:43
  • 1
    @David I took your advice so seriously that I'm now rewriting parts of my package to use this comma separated list strategy. I think it better suits the package's intended audience. Many thanks!
    – user19024
    Sep 25 '12 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy