2

I would like to define a macro

\newcommand{\III}{I\hspace{-0.2em}I\hspace{-0.2em}I}

in such a way that when I type

$ \mathrm{\III} $

in math-mode, the compiler will compile

$ \mathrm{I\hspace{-0.05em}I\hspace{-0.05em}I} $

instead. Is there any way to do this?

6
  • Are you planning to use \III in math mode not inside \mathrm?
    – egreg
    Commented Mar 27, 2018 at 19:17
  • Yes I am indeed. Commented Mar 27, 2018 at 19:18
  • So what’s the reason for using the same name for two distinct things?
    – egreg
    Commented Mar 27, 2018 at 19:20
  • I would like to treat III as a symbol, but with good spacing properties. The spacing in my definition makes the mathrm form look way too compact. Commented Mar 27, 2018 at 19:21
  • You said (in a comment to an answer that has now been deleted) that you need to use your \III symbol both in italic and in upright shape: did you consider inputting it as $\mathit{\III}$ (and not just as $\III$) when you want it to appear in italic, and as $\mathrm{\III}$ when you want it to be upright? I’m saying this because I suspect that you are tampering with the space only in order to compensate for the fact that $\III$ uses wider characters than $\mathit{\III}$.
    – GuM
    Commented Mar 27, 2018 at 19:44

3 Answers 3

4

You can set a spacing for the case when \mathnormal is in force and less space for other math groups.

\documentclass{article}

\usepackage{amsmath}

\newcommand{\III}{{I\IIIspace I\IIIspace I}}
\newcommand{\IIIspace}{%
  \mspace{%
    \ifnum\mathgroup=-1
      -5mu
    \else
      -2mu
    \fi
  }%
}

\begin{document}

$\III\ne\mathrm{\III}\ne\mathbf{\III}$

\end{document}

enter image description here

A different implementation, where in case of \mathnormal we use \mathit (and suppress the italic correction by inserting a suitable subscript that nullifies \scriptspace.

\documentclass{article}

\usepackage{amsmath}

\newcommand{\III}{%
  \ifnum\mathgroup=-1
    \expandafter\mathit
  \fi
  {I_{\kern-\scriptspace}\mspace{-2mu}I_{\kern-\scriptspace}\mspace{-2mu}I}%
}

\begin{document}

$\III\ne\mathrm{\III}\ne\mathbf{\III}$

$\scriptstyle\III\mathrm{\III}\mathbf{\III}$

$\scriptscriptstyle\III\mathrm{\III}\mathbf{\III}$

\end{document}

enter image description here

6
  • Although I don't understand why a symbol should change shape.
    – egreg
    Commented Mar 27, 2018 at 20:02
  • Italic correction between the “I”s? But cmti10’s \fontdimen2 is not zero (cf. Appendix G, Rule 17).
    – GuM
    Commented Mar 27, 2018 at 21:17
  • @GuM Did you try it? See rule 14.
    – egreg
    Commented Mar 27, 2018 at 21:35
  • Yes, I tried it and I got .\OT1/cmr/m/it/10 I .\OT1/cmr/m/it/10 I .\OT1/cmr/m/it/10 I .\kern1.58055 (from \showlists, after conversion from math to horizontal, newlines replaced by spaces); that is, no italic correction between the “I”s. By Rule 14, the “I”s are marked as text symbols, plus \fontdimen2 of cmti10 is not zero, so in Rule 17 delta is set to zero, not to the italic correction.
    – GuM
    Commented Mar 27, 2018 at 21:43
  • @GuM Did you try with a math kern in between?
    – egreg
    Commented Mar 27, 2018 at 21:46
3

You can test the current value of \fam register:

\def\III{I\ikern I\ikern I}
\def\ikern{\mkern-\ifnum\fam<0 4.5mu\else 1.5mu \fi}

$\III \quad \rm \III$

\bye
2
  • 1
    Do you see any significant difference with my answer, apart using plain TeX that's apparently not the OP's aim?
    – egreg
    Commented Mar 27, 2018 at 20:38
  • 2
    Significant difference is: \mathgroup works only in LaTeX but \fam works in all TeX formats (inluding LaTeX, of course). I don't understand why LaTeX says \let\mathgroup=\fam and introduces new functionless terminology.
    – wipet
    Commented Mar 27, 2018 at 20:44
0

To answer what your title ask:

I do not dare to recommend this since \mathrm doesn't take any arguments, I suspect something bad happens.

Both examples below prints hello world

\documentclass{article}
\begin{document}
  \newif\ifMathrm
  \newcommand\mathrmNew[1]{\Mathrmtrue\mathrm{#1}\Mathrmfalse}
  \newcommand\hello{\ifMathrm world\else hello\fi}
  \[ \hello~\mathrm{\hello} \]
\end{document}

It would be a little bit better to make \mathrmNew that toggles a flag. This is better because it doesn't execute the if-statements everytime \mathrm is called. Like this:

\documentclass{article}
\begin{document}
  \newif\ifMathrm
  \newcommand{\mathrmNew}[1]{\Mathrmtrue\mathrm{#1}\Mathrmfalse}
  \newcommand{\hello}{\ifMathrm world\else hello\fi}
  \[ \hello~\mathrmNew{\hello} \]
\end{document}
2
  • Since I don’t know, what exactly goes wrong if I try your second (non) suggestion? Commented Mar 27, 2018 at 19:22
  • Nothing really goes wrong. I think? But since the definition of \mathrm doesn't take any arguments, I suspect you're doing something bad. I'll ask the kings around here, maybe they know if this actually is bad? Commented Mar 27, 2018 at 19:29

You must log in to answer this question.

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