Skip to content

[amsmath] Issues with \DeclareMathOperator #785

Description

@matteosecli

I've run into a problem with \DeclareMathOperator from the amsopn package (loaded by the amsmath package, in my understanding). I've got this MWE:

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\Tr}{Tr}

\begin{document}
    \begin{equation}
        \Tr\left(e^{-\beta H}\right)
    \end{equation}
\end{document}

Then, I run latexmlc --verbose --destination=MWE.html MWE.tex and I get a clean output without problems. But if I run latexmlc --verbose --mathsvg --destination=MWE.html MWE.tex, I get 1 error:

Error:shell:latex LaTeX command 'latex ltxmlimg > ltxmlimg.ltxoutput' failed
    returned code 256 (!= 0): 
    See /tmp/LaTeXML2vtErS/ltxmlimg.log
    In Post::MathImages[@0x46fd890] ->generateImages
Couldn't find image for 'LaTeXML::Post::MathImages:svg:\beginDISPLAY \Tr\left(e^{-\beta H}\right)\endDISPLAY'

The same with --mathimages. By looking into ltxmlimg.tex, I've found no definition at all about my \Tr operator; the file looks like

\batchmode
\def\inlatexml{true}
\documentclass[onecolumn]{article}
\usepackage{amsmath}
\makeatletter
% STUFF HERE, NO REFERENCE AT \Tr.
\makeatother
\begin{document}
\beginDISPLAY \Tr\left(e^{-\beta H}\right)\endDISPLAY\clearpage
\end{document}

If I manually add \DeclareMathOperator{\Tr}{Tr} just after \usepackage{amsmath}, then ltxmlimg.tex compiles as expected.

As a workaround, if I substitute \DeclareMathOperator{\Tr}{Tr} with \newcommand{\Tr}{\mathrm{Tr}} in my MWE, then both latexmlc --verbose --destination=MWE.html MWE.tex and latexmlc --verbose --mathsvg --destination=MWE.html MWE.tex produce the expected output. However, also for semantic reasons, I'd prefer to stick with \DeclareMathOperator.

Thanks in advance! 😃

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions