Math & ScienceWrong spacing

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Wrong spacing

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass{article}

\usepackage{mathtools}
\usepackage{xparse}
\usepackage{upgreek}

\makeatletter
\def\resetMathstrut@{%
  \setbox\z@\hbox{%
    \mathchardef\@tempa\mathcode`\[\relax
    \def\@tempb##1"##2##3{\the\textfont"##3\char"}%
    \expandafter\@tempb\meaning\@tempa \relax
  }%
  \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@}
\makeatother
\begingroup
  \catcode`(\active \xdef({\left\string(}
  \catcode`)\active \xdef){\right\string)}
\endgroup
\mathcode`(="8000 \mathcode`)="8000

\NewDocumentCommand\test{mmgg}
  {%
    {\mkern -#1mu}#2%
    \IfNoValueF{#3}{^}%
    {\mkern -\IfNoValueTF{#3}{#1}{#3}mu \IfNoValueF{#4}{#4}}%
  }

\begin{document}

\begin{equation}
  \sin\test{6}{(\tfrac{3}{5}\uppi)} + k
\end{equation}

\end{document}
(The code is taken from this post.)

As can be seen, the spacing between `)' and `+' is too small. If possible, how do I fix this automatically within the \NewDocumentCommand command?

Thank you in advance!

Update:
If I add a ``{3}'' as a third argument , the spacing is more or less fine; i.e.,

Code: Select all

\sin\test{6}{(\tfrac{3}{5}\uppi)}{3} + k
It is, however, rather time-consuming if I have to do this at every (relevant) equation.

Update 2:
The command [color=#800000]\tfrac[/color] is unnecessary. A look at

Code: Select all

\sin\test{6}{(\uppi)} + k
makes my point ever more obvious.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply