# Customized log notation

In my country, the base of logarithm is written in superscript before the log sign, i.e. $^a\log b$ means log base a of b. This doesn't look nice on LaTeX, because there is a gap between ^a and \log. How to remove this gap?

• I've never seen that notation and I find it a source for ambiguities, even if there's a thin space before the superscript: $2\mylog{2}x$ (with David's definition) will leave the reader with the doubt whether it's "four times the logarithm of x" or "2 times the base 2 logarithm of x". – egreg Jul 16 '12 at 17:37
• Indeed it is. Unfortunately I have no choice but to follow the consensus. For such case of ambiguity, I'd put a dot to indicate multiplication. – steve Jul 16 '12 at 19:41
• Can you reveal where this notation is used? It's certainly uncommon. – egreg Jul 16 '12 at 19:42
• I'm from Indonesia – steve Jul 16 '12 at 19:43
• This is not an uncommon notation at all. Here in the Netherlands it is also widely used. It is taught like this at the middle school. – Chiel ten Brinke Apr 25 '13 at 12:38

You can use a negative space \! to remove (or reduce) this to your liking. It would be best to define a command for this, for the sake of consistency:

\documentclass{article}
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\Log}{o}{%
\IfNoValueTF{#1}{}{{}^{#1}\!}\log}%
\begin{document}
${}^a\log xyz\ \mbox{or}\ \Log[a]xyz\ \mbox{or}\ \Log xyz\ \mbox{or}\ \log_a xyz$
\end{document}​


Of course, more specific kerning is also possible using \kern.

The above MWE defined \Log[<base>] that takes an optional argument <base>. Without <base> it defaults to \log.

The space comes because \log is a \mathop command. Here you don't want any space between the superscript and the log but you do want the entire construct to be a \mathop so:

\documentclass{article}

\newcommand\mylog[1]{\mathop{{}^{#1}\mathrm{log}}}

\begin{document}

$x+x\mylog2 x$
\end{document}​

• The downside to this method seems to be that te base is not typset in mathfont. For instance, the "g" in \mylog{g} will look different from $g$. – gebruiker May 12 '20 at 12:28
• I found a quick solve by using {}\textsuperscript{$#1$} – gebruiker May 12 '20 at 12:45
• @gebruiker never use \textsuperscript in math: if you want the superscript in the same font as log then simply specify it in the same way, change #1 to \mathrm{#1} Oh no you say you want the base to be in a math font. That is what my original definition does. – David Carlisle May 12 '20 at 13:00