I would like to declare a new MathOperator for the trace of a matrix / an operator.

So far I have: \DeclareMathOperator{\Tr}{Tr}, but I don't know how to implement the parentheses.

What may make it more complicated, is that I would also like to compute the partial Trace, which I would like to write in the tex file as $ \Tr_{i} { ... } $ and have the effect of $ Tr_{i} \left( ... \right) $. I prefer \left( and \right) to ( and ), respectively because some of the objects I will compute the trace of have hats and \left( and \right) seem to adjust the size of the brackets.

I am new to Latex, so if declaring a math operator is not the way to go about things to accomplish what I want, I am open to other suggestions.

  • Is there a reason why you don't write \DeclareMathOperator{\Tr}{Tr} in the preamble, followed by \Tr_i\left(...\right) in the body of the document?
    – Mico
    Apr 29, 2020 at 8:48
  • It was defined that way before. Basically, I wanted to save time, and I thought this was more elegant, but it's turning out to be much more of a hassle Apr 29, 2020 at 8:51
  • There is no reason whatsoever for using \left and \right whenever you have ( and ). Doint so is even wrong.
    – egreg
    Apr 29, 2020 at 9:28
  • you mean $ \mleft( \frac{1}{2} \mright) $ whould be $ (\frac{1}{2}) $ even though the parantheses don't resize because that's the way it's supposed to be? Apr 29, 2020 at 11:49

2 Answers 2


I don't think you are going to save yourself much time by creating a math operator that takes a parenthesis-delimited argument.

Moreover, if you use \left and \right to auto-size the delimiters, you will end up with a typographically incorrect amount of space between Tr and the opening parenthesis. To avoid this incorrect spacing, I suggest you load the mleftright package and use \mleft( and \mright) instead of \left( and \right).

enter image description here

\usepackage{mathtools}  % for '\DeclareMathOperator' macro
\usepackage{mleftright} % for '\mleft' and '\mright' macros

$-\Tr(A)$ vs. $-\Tr\mleft(A\mright)$ vs. $-\Tr\left(A\right)$

You can define \newcommand{\Tr}[1]{\operatorname{Tr}\left(#1\right)}.

  • I have copied your line to the declaration lines, but I am getting the missing { inserted error. I am using texmaker btw. First, I tried it in the following way, for instance: $ \Tr_{i}{...} $. After the error, I replaced those instances by $ \Tr_{i}[...] $ There are multiple instances of the latter in my texfile now, only some of which cause errors. One of them being $ \Tr_{N \setminus \{i\}}[ \hat{\rho} ] $ (the trace over all subsystem, but the i-th). Apr 29, 2020 at 8:15
  • I tried $\Tr{\begin{smallmatrix}a&b\\c&d\end{smallmatrix}}$and it worked. What bout you? Apr 29, 2020 at 8:20
  • yes, it does work. I also reverted back to paranthesising the argument in {}. All but three instances work and they are also displayed fine, also an example involving curled brackets within the expression: $ -\Tr{ \hat{\rho} \ln \left( \hat{\rho} \right) }. $ (this works fine vs. the one given above causing an error). Might the subscript be the issue? Or the fact the tex pdflatex interprets on of those brackets as ending the Trace expression? Apr 29, 2020 at 8:49
  • Yes, the subscript is the issue, because, after \Tr, TeX is expecting the argument of that command. Apr 29, 2020 at 9:10
  • I'm sorry, I may have added the subscript part to the problem description while you were already busy trying / typing out the answer. Lo siento! Apr 29, 2020 at 9:13

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.