1

I defined the following command:

\newcommand{\mymathrm}[1]{\operatorname{\mathrm{#1}}}

The problem is that $\mymathrm{A B}$ gives something like AB, which does not typeset the space between A and B.

Is there anyway I can modify the definition of \mymathrm so that it would typeset the space, as if I wrote \mymathrm{A\ B}?

Finally, it would be better if the command automatically halves the space between A and B

The post Making mathmode obey spaces seems relevant, but I don't know how to change catcode inside of a command.

MWE (based on the answer below):

\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{palatino}

\begin{document}

\newcommand{\mymathrm}[1]{\operatorname{\textrm{\spaceskip.15em#1}}}
$\mymathrm{max sup}$

\renewcommand{\mymathrm}[1]{\operatorname{\mathrm{\spaceskip.15em#1}}}
$\mymathrm{max sup}$

\end{document}
4
  • are you sure you want \mathrm rather than \textrm ? Dec 29, 2021 at 19:53
  • @DavidCarlisle Yes. I'd like to combine 1) the font of \mathrm (which seems to be different from that of \textrm); 2) the spacing of \textrm (want to halve it though); 3) the space added by \operatorname
    – user182849
    Dec 29, 2021 at 19:59
  • 1
    but obeying spaces is more or less a distinguishing feature of text as opposed to math, it would be easy enough to have a version of textrm that uses the same font as mathrm (as that is the default behaviour anyway) the spac in text mode is custimisable by setting \spaceskip Dec 29, 2021 at 20:02
  • @DavidCarlisle Sounds reasonable. I'll search for a way in that direction. Thanks! Also thanks for the suggestion of \spaceskip
    – user182849
    Dec 29, 2021 at 20:04

1 Answer 1

1

You can use \textrm rather than \mathrm so that spaces can be controlled more easily.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand{\mymathrm}[1]{\operatorname{\textrm{\spaceskip.15em#1}}}
\begin{document}

$\operatorname{max sup} x$

$\operatorname{\textrm{max sup}} x$

$\mymathrm{max sup} x$

\end{document}

In the example document added later the fonts are set up with the somewhat surprising choice of palatino text and computer modern math so there is a big visual discrepancy beyween \textrm and \mathrm. However you can specify the OT1 Computer modern roman to be used in \text:

enter image description here

\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{palatino}

\begin{document}

\newcommand{\mymathrm}[1]{\operatorname{\text{\fontencoding{OT1}\fontfamily{cmr}\selectfont\spaceskip.15em#1}}}
$\mymathrm{max sup}$

\renewcommand{\mymathrm}[1]{\operatorname{\mathrm{\spaceskip.15em#1}}}
$\mymathrm{max sup}$

\end{document}

However you might consider replacing palatino with

 \usepackage{newpxtext,newpxmath}

To use a more modern palatino clone setup with matching text and math fonts.

7
  • Thanks. I didn't know that the default fonts are the same across \textrm and \mathrm. I might have changed it somewhere in my code.
    – user182849
    Dec 29, 2021 at 20:12
  • I use palatino package, and this is why I have different fonts (which is intended). Can I turn-off the font changing feature of palatino package inside of \mymathrm command? I added a MWE. Thanks in advance!
    – user182849
    Dec 29, 2021 at 20:21
  • @user182849 that's why questions are always better with a test file:-) I see you added one thanks, I'll look what the package is doing and add a modified answer in a bit Dec 29, 2021 at 20:31
  • are you sure you want palatino text with computer modern math? (irrespective of the specifics of this operator question) @user182849 Dec 29, 2021 at 20:35
  • Yes. I should have written a test file:) Also yes that I want palatino text with computer modern math!
    – user182849
    Dec 29, 2021 at 20:39

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.