3

How can I renew the macro "\log" (from "log" to "\ell og")?

Default function \log in line 1

I use renewcommand for \log:

\renewcommand{\log}{\ell\text{og }}

That shows in line 2.

But I want to function \log in line 3:

Enter image description here

    Default: \hspace{0.5 cm} $\log_M x^N = N \log_M x$ \\
    \renewcommand{\log}{\ell\text{og }}
    That show: $\log_M x^N = N \log_M x$ \\
    \renewcommand{\log}{\ell\text{og}}
    I want: \hspace{0.625 cm} $\log_M\hspace{2 pt}x^N = N \log_M\hspace{2 pt}x$ \\
6
  • 4
    \mathop{\ell\mathrm{og}} but why would you do that?? May 17 at 15:09
  • Without trying things, in \text{og } it looks like you are adding the space you want to remove(?). Also, see this old answer.
    – mickep
    May 17 at 15:09
  • People want to typeset all sort of weird things. Generally speaking though, if you submit to journals etc. they would expect the "standard" (i.e. default) styles && the people making the default had researched lots about good typography.
    – user202729
    May 17 at 15:09
  • Thank you every one :D
    – Deeridear
    May 17 at 15:16
  • Never ever use \text for things like this. See what happens if you issue \itshape before That show...
    – daleif
    May 17 at 15:16

2 Answers 2

6

The standard macro \log is defined as a "math operator". You first need to undefine the existing macro and then recreate it via, e.g., a \DeclareMathOperator instruction.

enter image description here

\documentclass{article} % or some other suitable doc. class
\usepackage{amsmath} % for "\DeclareMathOperator" macro
\let\log\relax  % first, undefine the existing macro
\DeclareMathOperator{\log}{\ell og} % now, (re)define it

\begin{document}
$\log_M x^N = N \log_M x$
\end{document} 
3
  • Technically true undefine would be \let\log\undefined, but that way would be able to "trick" most programs (is it documented behavior?).
    – user202729
    May 17 at 15:51
  • Oh! Thank You :D
    – Deeridear
    May 17 at 16:17
  • 1
    @user202729 Yes, that's used also in other cases. Since \DeclareMathOperator relies on \@ifdefinable, if the control sequence being defined is either currently undefined or its meaning is \relax, then \@ifdefinable returns true. This internally uses \@ifundefined that's classically based on a \csname...\endcsname construction, which yields \relax when the control sequence is undefined.
    – egreg
    May 17 at 20:49
2

An alternative to undefining and redefining the command is to declare the log-like operator as a \mathop atom. You would also want to add \nolimits so superscripts and subscripts appear to the right, instead of above and below. This also works for operators that should not use the operator font.

\documentclass{article}
\usepackage{amsmath}

\newcommand\ellog{\mathop{\ell\mathrm{og}}\nolimits}

\pagestyle{empty}  

\begin{document}
\begin{align*}
  \log_M   x^N &= N \log_M   x \\
  \ellog_M x^N &= N \ellog_M x
\end{align*}
\end{document}

Computer Modern sample

In this case, I avoided redefining \log in order to show the old and new output above and below, but you can easily change \newcommand\ellog to something like \DeclareRobustCommand\log.

4
  • +1. Is there an advantage to running \newcommand\ellog{\mathop{\ell\mathrm{og}}\nolimits} instead of \DeclareMathOperator{\ellog}{\ell og}?
    – Mico
    May 18 at 5:57
  • 1
    @Mico I guess there are two minor ones: you don’t change to the operator font, if that’s undesired, and you don’t need to redefine the command to \relax first.
    – Davislor
    May 18 at 5:59
  • 1
    @Mico This wasn’t intended as criticism of your fine answer, though. Just a different method.
    – Davislor
    May 18 at 6:01
  • Thanks. I suppose the second advantage is doubtful since \ellog hasn't been defined so far. (If it has been defined, then \newcommand{\ellog}{...} fails too...)
    – Mico
    May 18 at 6:02

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.