2

I apologize in advance if this question has already been asked, and if it is a dumb question: my knowledge of LaTeX is very limited.

I'm doing a thesis in mathematics, and I've some problems regarding formulas, which sometimes appear upright -like using \text{}-, sometimes in italic -like using \emph{}-.

I divided the claims in two groups: \theoremstyle{plain} -for theorems, propositions, etc- and \theoremstyle{definition} -for definitions, remarks-.

Now, I use many times the letter $\text{H}$ to denote the cohomology: I therefore defined a new command

\newcommand{\coh}{\emph{H}}

but unfortunately, when is used in a definition, it is in italic, while in a theorem environment it is straight: how can I impose to LaTeX to always print this letter upright, no matter the environment in which is used? I tried \newcommand{\coh}{\text{H}} but it still doesn't work.

3
  • 2
    Welcome to TeX.SE. Include the package \usepackage{mathtools} (which includes amsmath) and then using \DeclareMathOperator{\coh}{H} should give you the desired results. FYI, instead of descrbing the problem, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Oct 13, 2020 at 7:37
  • @PeterGrill as of my knowledge \DeclareMathOperator is one of the best solution, can you make this as answer for this topic? So that it will help all to find solution in future...
    – MadyYuvi
    Oct 13, 2020 at 7:49
  • Thanks a lot @PeterGrill: I apologize for how I have written my question, it was my very first post on TSE!
    – netero
    Oct 13, 2020 at 7:50

2 Answers 2

4

You should use \DeclareMathOperator{\coh}{H} which yields the same results in normal usage and in italics:

enter image description here

Code:

\documentclass{article}
\usepackage{mathtools}
\DeclareMathOperator{\coh}{H}

\begin{document}
In normal usage we have an upright $\coh$.

In emphasized text it appears the same \emph{$\coh$}.
\end{document}
1
  • 2
    Correct for this particular case (the cohomology operator), but \DeclareMathOperator is not a general purpose command for defining “always upright letters”, see tex.stackexchange.com/q/48459/4427
    – egreg
    Oct 13, 2020 at 7:59
4

You can use \textnormal{H}, to reset the formatting. The \text command inherits the formatting the surrounding text. That is, because a theorem statement is italicized, the italics will bleed through into math formulas. So would bold or sans-serif or small-caps formatting if you use $\text{H}$ in a header.

You can instead use \mathrm{H}, which is always upright, and spaced like an ordinary math symbol. If you use \DeclareMathOperator, you will get spacing like log or sin.

The unicode-math package gives you the choice between \mathrm (which uses the text font, but can be changed) and \symup (which uses the math font, but can be changed). This allows you to use distinct fonts for ordinary words in math mode, and for upright math symbols. (You might try upright italics, or Neo Euler.)

If you want to inherit the weight but reset the shape (so that a formula in a bold header is bold), you can use \textup{H}. Alternatively, \text{\rmfamily\upshape H} lets you set font axes individually.

It would be a good idea to define commands like this once, in the preamble.

3
  • It is very very rare you'd ever want to use \text, for one of course it switches to the text font, which depending on setup my be different from the upright font used in math. I'm only mentioning this as we see so many users misuse \text because they think it gives them upright text. Which as you rightfully mention it does not always do. Though I rend to think that many users does not know what "inherits formatting from the surrounding text" actually mean.
    – daleif
    Oct 13, 2020 at 12:14
  • @daleif OK, I added a bit of explanation.
    – Davislor
    Oct 13, 2020 at 12:30
  • You actually did much better than most. Often the fact that it switches is not even mentioned.
    – daleif
    Oct 13, 2020 at 12:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .