5

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 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 – Markus Gratis Apr 29 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 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? – Markus Gratis Apr 29 at 11:49
3

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

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

\begin{document}
$-\Tr(A)$ vs. $-\Tr\mleft(A\mright)$ vs. $-\Tr\left(A\right)$
\end{document}
| improve this answer | |
3

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

| improve this answer | |
  • 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). – Markus Gratis Apr 29 at 8:15
  • I tried $\Tr{\begin{smallmatrix}a&b\\c&d\end{smallmatrix}}$and it worked. What bout you? – José Carlos Santos Apr 29 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? – Markus Gratis Apr 29 at 8:49
  • Yes, the subscript is the issue, because, after \Tr, TeX is expecting the argument of that command. – José Carlos Santos Apr 29 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! – Markus Gratis Apr 29 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.