6

This code

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \[ J(\sqrt[n]{x}) \]
\end{document}

compiles into this:

screenshot

The spacing after the opening parentheses is ugly. What's the proper way to fix this?

user541686
  • 9,547
  • 1
    J(\!\sqrt[n]{x})? – Manuel Jan 29 '15 at 20:58
  • @Manuel: Don't I have to do that where I do \sqrt? Doesn't seem like a good solution... – user541686 Jan 29 '15 at 20:59
  • @Mehrdad Small adjustments are necessary for such cases; you should also add \, between the radical and the closing parenthesis: J(\!\sqrt[n]{x}\,) – egreg Jan 29 '15 at 21:01
  • @Mehrdad When you finish your document: Find & Replace (\sqrt by (\!\sqrt and that's probably it. – Manuel Jan 29 '15 at 21:07
  • @Manuel: I think you're completely missing the point of my question. – user541686 Jan 29 '15 at 21:10
  • Well, the question to me says “What's the proper way to fix this” and my answer was “Do it manually”. And I added the Find & Replace because it removes lot's of work from that solution. If what you are looking for a redefinition of \sqrt command, may be it's doable, but it doesn't seem too obvious. – Manuel Jan 29 '15 at 21:16

1 Answers1

10

There is really a difference between J(\sqrt{x}) and J(\sqrt[n](x)), that's not justified by the root index: a small horizontal space is added in the latter case.

You can get the same width by patching the \sqrt command:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\sqrt}{\@sqrt}{{\mspace{-2.9274mu}\@sqrt}}{}{}
\makeatother

\begin{document}

\sbox0{$J(\sqrt{x})$}\the\wd0

\sbox0{$J(\sqrt[n]{x})$}\the\wd0

\[ J(\sqrt{x})+J(\sqrt[n]{x})\]

\end{document}

enter image description here

There will still be some more space in script style, though.

However, proper typesetting of this requires a thin space after the radical:

J(\sqrt[n]{x}\,)

so the output would be

enter image description here

Such adjustment can't be provided automatically, because it depends on the symbol following the radical.

egreg
  • 1,121,712
  • @Mehrdad Probably @barbarabeeton will see this and add it to the list of adjustments for amsmath. – egreg Jan 29 '15 at 22:49
  • That's awesome :) By the way, is there a way to avoid the magic -2.9274mu number? Where did it come from? (Can I calculate it based on something else?) – user541686 Jan 29 '15 at 22:50
  • @Mehrdad Computed with trial and error. It's not really the best patch, but at least it works in normal size. Be careful that with different fonts the amount of adjustment might not be the best. – egreg Jan 29 '15 at 22:51
  • Ah I see, okay. – user541686 Jan 29 '15 at 22:52
  • Only just now noticed this answer. Out of idle curiosity: What was the reason for choosing \mspace{-2.9274mu} rather than \mkern-2.9274mu as the spacing adjustment directive? – Mico Jul 12 '15 at 07:02
  • @Mico Because \mspace is a higher level command. – egreg Jul 12 '15 at 09:14