Math & ScienceOld code not working anymore

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

Old code not working anymore

Post by svend_tveskaeg »

Hi all.

I found the following code some time ago and then it compiled without problems:

Code: Select all

\documentclass[a4paper,12pt]{article}

\usepackage{mathtools}

\makeatletter
 \newcommand*{\textupperscript}[2]{%
  \@textupperscript{\selectfont#1}{\selectfont#2}
 }
 \def\@textupperscript#1#2{%
  {\m@th\ensuremath{%
    ^{\mbox{\fontsize\sf@size\z@#1}}
    _{\mbox{\fontsize\sf@size\z@#2}}
  }}
 }
\def\@super{^}
\def\@sub{_}

\catcode`^\active
\catcode`_\active
  \def\@super@sub#1_#2{\textbothscript{#1}{#2}}
  \def\@sub@super#1^#2{\textbothscript{#2}{#1}}
    \def\@@super#1{\@ifnextchar_{\@super@sub{#1}}{\textsuperscript{#1}}}
    \def\@@sub#1{\@ifnextchar^{\@sub@super{#1}}{\textsubscript{#1}}}
      \def^{\let\@next\relax\ifmmode\@super\else\let\@next\@@super\fi\@next}
      \def_{\let\@next\relax\ifmmode\@sub\else\let\@next\@@sub\fi\@next}
\makeatother

\begin{document}

\noindent Something:
\begin{equation*}
  \Psi\textupperscript{Horse}{Fish}(x)
\end{equation*}

\end{document}
Now it does not compile and I have no idea what I have changed; the error I get is the following:

Code: Select all

! Extra \else.
\@next #1#2#3#4->\ifx #2\@empty #4\else 
                                        \expandafter \@xnext #2\@@ #1#2#3\fi 
l.25  \catcode`\noexpand\^^
                           A\the\catcode`\^^A\relax
Can anyone help my make the code wotk again? An explanation would be great but it is not necessary.

Thank you in advance!
``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

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Old code not working anymore

Post by Stefan Kottwitz »

It's a compatibility issue with mathtools and those definitions. If you would just use amsmath, it would work fine.

Stefan
LaTeX.org admin
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Old code not working anymore

Post by svend_tveskaeg »

Thank you, Stefan.

It used to work with mathtools (if I am not mistaken).
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply