I want to write a new command for the trace of a matrix that I've defined like:


but when I call \trace{A^\top} the automatic scaling makes the [ and ] characters \bigl[ and \bigr]. How can I pass an optional additional argument to my new command so that I can control the scaling? Ideally it would be like \trace[\big]{A^\top} to get the scaled version and \trace{A^\top} to get the standard version.

2 Answers 2


I suggest you employ the mathtools package and its \DeclarePairedDelimiterXPP macro to create a user macro called \trace that satisfies your syntax requirements. With this setup,

  • \trace may be used to generate basic-size square brackets,

  • \trace* may be used to auto-size the square brackets, and

  • \trace[\big] through \trace[\Bigg] are available to choose specific sizes of the square brackets directly.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{mathtools}  % for '\DeclarePairedDelimiterXPP' macro
% See pp. 27f. of user guide of 'mathtools' package:

$\trace{A}$, $\trace[\big]{A^\top}$, $\trace*{A^\top}$, $\trace[\Bigg]{A^\top}$
  • \operatorname{\mathsf{trace}}
    – egreg
    Feb 26 at 8:32
  • @egreg - Many thanks for suggesting this improvement!
    – Mico
    Feb 26 at 8:41

You can define two new commands like in this code:


\newcommand{\traceb}[1]{\mathsf{trace}\!\Bigl[#1\Bigr]} %<-- Big not big
    $\traceb{A^\top}$ \qquad $\trace{A^\top}$
    $\traceb{\dfrac{x+y}{x-y}}$ \qquad $\trace{\dfrac{x+y}{x-y}}$
    \qquad  $\trace{\begin{matrix}a&b\\c&d\end{matrix}}$

The output is:

enter image description here

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.