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$ \\

2 Answers2

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}

Mico
  • 506,678
  • 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 '22 at 15:51
  • Oh! Thank You :D – Deeridear May 17 '22 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 '22 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.

Davislor
  • 44,045
  • +1. Is there an advantage to running \newcommand\ellog{\mathop{\ell\mathrm{og}}\nolimits} instead of \DeclareMathOperator{\ellog}{\ell og}? – Mico May 18 '22 at 05: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 '22 at 05:59
  • 1
    @Mico This wasn’t intended as criticism of your fine answer, though. Just a different method. – Davislor May 18 '22 at 06: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 '22 at 06:02