2

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

\newcommand{\trace}[1]{\mathsf{trace}\!\left[#1\right]}

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

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:
\DeclarePairedDelimiterXPP\trace[1]{\operatorname{\mathsf{trace}}}[]{}{#1}

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

You can define two new commands like in this code:

\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}

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

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.