17

How can I insert parentheses around the content of the natural log? I want my document to show

ln(x+1)

but the code

\ln{x+1}

or

\ln(x+1)

or

\ln \left( x+1 \right)

will not produce this.

Edit: I should have specified that this issue was occurring in an equation (math mode).

Earlier today I was having some issues compiling due to corrupt temporary files (log and aux files) but never restarted my tex environment. Upon rebooting this evening, my original document is placing parentheses as expected.

I am marking Christian's post as the solution due to his effort and his explanation really clears up what the command \ln actually is (a comand without an argument).

Thank you all for your quick responses.

4
  • 4
    Welcome to TeX.SX! With $\ln(x+1)$ you surely get what you want.
    – egreg
    Jun 13, 2016 at 23:20
  • 2
    \ln is an operator typeset command and does have an argument, i.e. \ln{x+1} works because {...} is not used as an argument here. Anyway, \ln does not typeset the parentheses
    – user31729
    Jun 14, 2016 at 0:03
  • 2
    Really? \ln(x+1) does not produce the desired results? If it does not , please post an image of what it does produce? Jun 14, 2016 at 0:24
  • Thanks for your responses. Restarting my tex environment has resolved the issue and '\ln(x+1)' does yield the expected results.
    – Steven M
    Jun 14, 2016 at 2:48

2 Answers 2

14

There are some possibilities to achieve this, but all of them require entering into math mode, i.e. with $...$, \(...\), or \[...\] or one of the various math environments such as equation and align.

But \ln{x+1} is not producing a pair of parentheses. In fact, it's the same as \ln x+1. \ln is an command without arguments, so \ln stands alone actually and ignores the following {...}.

If the parentheses are required in many occasions, wrapper macros, say \lnn and \lnb are useful, which uses either \left(...\right) or the medium spaced version \mleft(...\mright), both of which has the advantage of growing parenthesis for fractions etc.

\documentclass{article}

\usepackage{amsmath}
\usepackage{mleftright}

\newcommand{\lnn}[1]{%
  \ln\left(#1\right)%
}

\newcommand{\lnb}[1]{%
  \ln\mleft(#1\mright)%
}

\begin{document}


\verb!$\ln x+1$ and $\ln{x+1}$ produce the same output!

\begin{center}
  \fboxsep=0pt
  \fbox{$\ln x+1$}

  \fbox{$\ln{x+1}$}
\end{center}

produce the same output

With parentheses:

$
\begin{array}{ccc}
  \verb!\ln(x+1)! & \verb!\ln \left(x+1\right)! & \verb!\ln \mleft(x+1\mright)! \\
  \\
  \ln (x+1) & \ln \left(x+1\right) & \ln \mleft(x+1\mright) \\
  \\
   \verb!\lnb{x+1}! & \verb!\lnb{\dfrac{x+1}{x-1}}! & \verb+\lnn{n!}+\\
   \\
  \lnb{x+1} & \lnb{\dfrac{x+1}{x-1}} & \lnn{n!} \\
\end{array}
$

\end{document}

enter image description here

5
  • 3
    +1. You may also want to point out that a common typographical convention -- which, naturally, is implemented by TeX -- posits that there should be no whitespace between a math operator (such as \ln, \cos, and \det) and a subsequent opening parenthesis (or, more generally, a math atom of type "math open"). Hence, \ln\mleft(... and \lnb{...} produce the typographically preferred look, whereas \ln\left(... and \lnn{...} do not.
    – Mico
    Jun 14, 2016 at 1:28
  • And it should be noted that \ln\mleft(x+1\mright) is just a waste of tokens and keys, because the result differs in no way from the simpler \ln(x+1).
    – egreg
    Jun 14, 2016 at 10:50
  • @egreg: I can remember times you 'attacked' me for not using \mleft... ;-)
    – user31729
    Jun 14, 2016 at 11:13
  • If you have to use automatic scalable fences, then \mleft and \mright are better than \left and \right. But in the case of \ln(x+1) there is no need whatsoever; worse, \ln\mleft(x^2+1\mright) might give too big parentheses than needed.
    – egreg
    Jun 14, 2016 at 11:15
  • @egreg: Well, I keep it this way. It's up to the OP, which style he prefers.
    – user31729
    Jun 14, 2016 at 11:17
0

The physics package automatically produces log() and ln() with parentheses of the correct size. Just use

\usepackage{physics}

and $log(x+1)$ and $\log(\dfrac{x+1}{x-1})$ will work out-of-the-box.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .