4

I want to write a^b in latex where ^ is not a power symbol. If I just write b^a in latex, the latter obliged me to put $. But in fact I don't want to write a to the power b, but just a^b.

How can I solve this issue?

Any help will be very appreciated!

7
  • Can you not use \^ ?
    – Plergux
    Nov 7, 2020 at 18:32
  • 1
    In what context would you use a^b?
    – egreg
    Nov 7, 2020 at 18:33
  • 3
    @Plergux \^ is the accent, \textasciicircum is ^ Nov 7, 2020 at 18:55
  • 1
    @DavidCarlisle ah, ok. Sorry :|
    – Plergux
    Nov 7, 2020 at 19:01
  • 1
    But if you're writing code (especially if it's a lot), you might want to look into the packages listings or minted.
    – Teepeemm
    Nov 7, 2020 at 23:41

2 Answers 2

6

Here, \string can be used to avoid special (catcode induced) interpretations of the token than follows.

Such syntax will work in both text as well as math modes, though, of course, a and b will be rendered in the math font, in such a case.

\documentclass{article}
\begin{document}
a\string^b $a\string^b$
\end{document}

enter image description here

1
  • 1
    Thank you a lot. It works well.
    – Christina
    Nov 7, 2020 at 19:58
3

This is \textasciicircum in text mode, and can be used in math mode as well with proper wrappers.

\documentclass{article}

\newcommand\mathcaret{\mathbin{\textup{\textasciicircum}}}

\begin{document}
a {\textasciicircum} b

\(a \mathcaret  b \)
\end{document}

Computer modern font sample

1
  • Thank you. Your suggestions also work very well.
    – Christina
    Nov 7, 2020 at 23:30

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