10

I have a 300+ page thesis and I constantly used $\mu$, which showcases mu in italic format. Now my supervisor wants me to correct this to non-italic. I do not want to change each one-by-one, therefore thought to re-define it by using: \newcommand{\mu}{\ensuremath{\textrm{\mu}}}

But ofc I cannot do it since \mu is already defined. How can I re-define it such that it is not in italic in my equation, without changing all one-by-one? Certain things in math format$$ should remain italic though..

% !TEX TS-program = pdflatex

\documentclass[11pt]{article} \usepackage[utf8]{inputenc} \usepackage[a4paper,width=150mm,top=25mm,bottom=25mm]{geometry}

\begin{document} 5 $\mu$ \end{document}

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
lay lay
  • 131
  • 2
    Should all lower case Greek letters be upright? Or are you using the \mus as units, such as in 5 micro metres? – Skillmon Feb 12 '22 at 17:37
  • 1
    I am using it as units! – lay lay Feb 12 '22 at 17:45
  • 8
    your error is not so much that mu is already defined but that you are defining it in terms of itself (so it will be an infinite loop) you could fix that but I woulduse a different name such as \textmu or \micro and globally change your \mu to \micro first which should only be a few seconds in any text editor – David Carlisle Feb 12 '22 at 17:47

4 Answers4

29

Per your comments, you are using "mu" to denote "micro", as in one millionth of some scientific unit. Given this situation, you need to get out of the business of attempting to define your own micro symbol immediately. Instead, do please employ the siunitx package and its \unit and \qty macros to typeset scientific units and associated quantities. The macros \unit and \qty can be used in both text and math mode.

enter image description here

Observe that the typographically correct glyph for "micro" has serifs and is quite different from both $\mu$ and $\upmu$. Do also observe that \qty also automatically inserts a typographically correct amount of (non-breakable) whitespace between the number and associated unit.

% !TEX TS-program = pdflatex
\documentclass[11pt]{article}
%%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[a4paper,width=150mm,vmargin=25mm]{geometry}
\usepackage{siunitx,upgreek}

\begin{document} \unit{\micro\meter}, $\unit{\micro\farad}$, \unit{\micro\second}

$\qty{4}{\micro\meter}$, \qty{5}{\micro\farad}, $\qty{6}{\micro\second}$ \end{document}


Addendum: The siunitx package provides the shortcut macros \ug, \um, \us, \umol, \uA, \uV, and \uL to denote one millionth gram, meter/metre, second, mol, Ampere, Volt, and Liter, respectively. Thus, the first line in the body of the document environment above could also be written succinctly as \unit{\um}, $\unit{\uF}$, \unit{\us}.

Mico
  • 506,678
11

I guess it's too late to have correct input. You can solve your problem by using upgreek and redefining \mu to be \upmu.

\documentclass{article}
\usepackage{upgreek}

\renewcommand{\mu}{\upmu}

\begin{document}

$\mu$ but $\pi\alpha\beta$

\end{document}

enter image description here

egreg
  • 1,121,712
5

In general, italic greeks do not present upright via \mathrm or \textrm. Here, I recommend the answer Upright Greek font fitting to Computer Modern which, for pdflatex, allows unslanting of any glyph.

Then, I save the italic mu as \itmu and redefine \mu in terms of it. One can still call upon \itmu if the italic mu is required.

\documentclass[a4paper]{article}
\newsavebox{\foobox}
\newcommand{\slantbox}[2][0]{\mbox{%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
}}
\newcommand\unslant[2][-.25]{\slantbox[#1]{$#2$}}

\let\itmu\mu \renewcommand\mu{\ensuremath{\unslant\itmu}}

\begin{document} 5 \mu m. If needed italic in math mode, $\alpha\itmu$. \end{document}

enter image description here

4

You can use any of the options from here. You probably want either the siunitx package or \textmicrometer from the laTeX kernel. If you could redefine \mu, you could also do a search-and-replace.

The problem you’re getting with \newcommand can be fixed very simply, however, by using \DeclareRobustCommand. With some packages that delay their definitions for various reasons, you might need \AtBeginDocument{\DeclareRobustCommand\mu{\textup{\textmicrometer}}}.

Davislor
  • 44,045