In my current document, I have a lot of angle brackets, which are computed via:

\langle a, b \rangle

Is there anyway I could create a new command, something in the look of:

\newcommand{\dotproduct{ab}}{\langle a, b \rangle}

so that I could replace the a and b by other variables? To be more specific, I would love for that command template to work also for:

\dotproduct{cd}, \dotproduct{Q,R}
  • 1
    \dotproduct{a,b} seems much easier to parse. – egreg Aug 18 '20 at 20:48
  • 1
    why not simply \newcommand\dotproduct[2]{\langle#1,#2\rangle} then \dotproduct{Q}{R} ? – David Carlisle Aug 18 '20 at 20:58
  • @DavidCarlisle I like your suggestion. If you could turn that into an answer I would accept it happily :) – Quang Thinh Ha Aug 18 '20 at 21:20

The standard LaTeX syntax would be




I'd prefer the syntax suggested by @DavidCarlisle.

If you still want your syntax (which is imho unclean) this macro will test whether your argument contains a comma, if so it just uses it as is, if not it will put a comma after the first item of your input.



\NewDocumentCommand \dotproduct { m }
    \tl_if_in:nnTF { #1 } { , }
      { #1 }
      { \tl_head:n { #1 } , \tl_tail:n { #1 } }

$\dotproduct{a,b} \dotproduct{cd} \dotproduct{abc}$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.