4

I'd like to declare the backtick symbol ` to be the math operation power ^, so that by writing

\documentclass{article}
\usepackage{amsmath}
% \DeclareMathSymbol{`}{\mathbin}{symbols}{^}
\begin{document}
$3`2$
\end{document}

it is displayed enter image description here

I was thinking to use \DeclareMathSymbol{<symbol>}{<type>}{<sym-font>}{<slot>} but I'm not sure there is a slot code for ^ since it is an operation rather than a symbol.

I'd like to avoid using \newcommand because otherwise I will have to write 3\`2 in order to get the power.

PAINLESS SOLUTION

Install the lightweight program autohotkey and create a script with the following code

NumLock::
send {^}
return

once run, you can print the caret symbol ^ by pressing the Num Lock key in the numpad.

You can change NumLock to whatever you want, check the list of all keys and the list of all hotkeys, for example

MButton::     middle/wheel mouse button
^p::          ctrl+p
+p::          shift+p
F2::          F2
  • 3
    If you want to live dangerously: \documentclass{article} \let\oldbacktick` \catcode``=\active \protected\def`{\ifmmode\expandafter^\else\expandafter\oldbacktick\fi} \begin{document} $3`2$ a`b \end{document} (see here). – Schrödinger's cat Aug 20 at 13:24
  • 1
    Out of curiosity, why? Is it simply to avoid hitting the shift key? – Teepeemm Aug 20 at 13:29
  • @Teepeemm Yes i know i'm lazy but i'm going to type thousands of ^, i solved with a small autohotkey script which prints ^ when i press NumLock – sound wave Aug 20 at 14:26
7

All of this is really not recommended, unless you really know what you are doing and/or is willing to suffer the consequences. In the words of Mr. Cat, this is "living dangerously", and you may end up being dead when someone opens the box ;-)

\DeclareMathSymbol is used to select the glyph in a font which will be used to write a specific symbol on the paper. The superscript happens in a much lower level in TeX. Usually, the ^ symbol has the category code (catcode) 7, which is a "superscript token". This means that whenever TeX sees a ^, it will make a superscript. At the simplest, you can have that effect by changing the catcode of a ` to 7:

\documentclass{article}
\catcode`\`=7
\begin{document}
$3`2$ and some `quoted' text
\end{document}

however, the code above will raise a Missing $ inserted because now that ` is a superscript character, it is only meant to be used in math-mode. You can redefine \` to mean a "normal" (catcode 12) ` character:

\documentclass{article}
\renewcommand\`{`}
\catcode`\`=7
\begin{document}
$3`2$ and some \`quoted' text
\end{document}

and then you won't be able to write a grave accent with, say, D\'ej\`a vu (the output will be "Déj‘a vu"). Plus, any code which relies on ` being a catcode-12 token will fail miserably.

A arguably better alternative is to make the ` an active character only in math-mode and define it equal to a superscript token:

\documentclass{article}
{\catcode`\`=\active
 \global\let`=^}
\mathcode`\`="8000
\begin{document}
$3`2$ and some `quoted' text
\end{document}

the output is:

enter image description here

But again, this might break something, somewhere, which relies on ` being a catcode 12 token.

  • 3
    Hmmh, I was hoping that you would refer to my code as "cat code". ;-) – Schrödinger's cat Aug 20 at 13:44
  • 2
    @Schrödinger'scat LOL! How could I miss that? :-) – Phelype Oleinik Aug 20 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.