Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I wish to use an upright mu character in various places in my document, and so I've put the following in my preamble:

% textcomp, for its upright mu
\usepackage{textcomp}
% some user macros
\newcommand{\murm}{\hbox{\textmu}}

This is fine in both text and math mode, except when I try to place the mu in sub/superscript positions, and its size remains unchanged. Is there any way to resize it to fit its environment within math mode?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You can use \mathchoice to give four different definitions of the macro dependent if it is in display, in-text, script or scriptscript mode. (See also \mathpalette)

\newcommand{\murm}{%
    \mathchoice
        {\hbox{\normalsize\textmu}}
        {\hbox{\normalsize\textmu}}
        {\hbox{\scriptsize\textmu}}
        {\hbox{\tiny\textmu}}%
}

The whole expression should actually be wrapped into \ensuremath (amsmath package) or use \ifmmode manually to avoid errors if used in text-mode:

\newcommand{\murm}{%
  \ifmmode
    \mathchoice
        {\hbox{\normalsize\textmu}}
        {\hbox{\normalsize\textmu}}
        {\hbox{\scriptsize\textmu}}
        {\hbox{\tiny\textmu}}%
  \else
    \textmu
  \fi
}
share|improve this answer
    
Is there a way to use \ensuremath or similar to choose whether in math mode or not, and issue the \mathchoice command if so, and the regular command if not? –  Statto Mar 29 '11 at 13:36
    
@Statto: Yes, like \ensuremath you can use \ifmmode to check if you are in mathmode: \ifmmode \mathchoice ... (above code) \else \textmu \fi –  Martin Scharrer Mar 29 '11 at 13:40
    
Thanks, that's perfect! –  Statto Mar 29 '11 at 13:47
    
@Statto: You are welcome. Also note that you have now over 15rep points and are able to up-vote answers. –  Martin Scharrer Mar 29 '11 at 13:51
1  
@Martin: The AMS \text macro does exactly this. \newcommand*{\murm}{\text{\textmu}} will do the right thing –  Danie Els Mar 30 '11 at 5:06
show 1 more comment

Why don't you use \upmu from the upgreek package? It will resize automatically in math mode.

share|improve this answer
2  
Because the \upmu command doesn't render in the same font as the rest of the text. Since mu is the upright Greek character I'll be using most, it would be nice to get it right... –  Statto Mar 29 '11 at 13:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.