Anthony Cramp
Anthony Cramp

Reputation: 4585

How do I show a caret (^) in math mode in LaTeX?

I'm trying to display a caret (^) in math mode in LaTeX to represent the exclusive or operation implemented in the "C languages". By default, ^ is for creating a superscript in math mode. The closest I can seem to get is by using \wedge, which isn't the same.

Upvotes: 21

Views: 51950

Answers (7)

solveeid
solveeid

Reputation: 41

This is what I did:

$2\hat{\text{ }}3$

Upvotes: 4

txemagon
txemagon

Reputation: 119

Use the wedge symbol as a superscript. It has the perfect size.

Something like this:

$ ^\wedge $

Upvotes: 11

Dayo Adetoye
Dayo Adetoye

Reputation: 51

Use \textasciicircum in text mode. If you are in math mode, you need to use something like $\mbox{\textasciicircum}$.

Upvotes: 5

Karl
Karl

Reputation: 9155

\^ is an accent character that applies to other characters, \^{4} gives a 4 with a carat on its head. It takes up no horizontal space. If you write $7 \^{} 3 = 4$ you get a 73 with a mark smashed onto both the 7 and the 3. What you need then is to fill out the space a little bit. Through trial and error and a nice application called LatexIt, I found this sequence to work beautifully:

\hspace{1.5} \^{} \hspace{1.5}  

This gives a 3 unit width with the carat centered in it. It looks nice.

It is a pointy carat though, and \verb|^| gives a more flattened one that looks more like a monotype font frequently used in programming languages.

Upvotes: 2

paxdiablo
paxdiablo

Reputation: 881323

Within math mode, you can use:

$7 \^{ } 3 = 4$

to do this, as shown from the online LaTeX renderer here.

enter image description here

Upvotes: 3

Will Robertson
Will Robertson

Reputation: 64530

You might want to use the common symbol for exclusive or instead, \oplus (but give it a proper name with something like \newcommand\XOR{\oplus}).

The caret is a bit too small to be noticeable as a binary operator. However, if you do insist using a caret instead, use this:

\newcommand\XOR{\mathbin{\char`\^}}
$x \XOR y$

The \mathbin puts the right spacing around the symbol for a binary operator, and the \char ensures that the glyph is obtained from the roman font.

Upvotes: 20

genehack
genehack

Reputation: 140728

How about

\^{}

or

\verb|^|

?

Upvotes: 11

Related Questions