[Tex/LaTex] A more wedge-like symbol instead of a caret in typewriter-font text

symbolstypewriter

I'm trying to typeset some computer code which involves a caret (for powers); for example

\verb!x^3+x^2-1!

The trouble here is that the caret produced is rather flat. I could use a wedge instead:

\newcommand{\pwr}{${}^\wedge}$}
\texttt{x\pwr 3+x\pwr 2-1}

but the wedge here is too pointy, as well as being the wrong weight for the typewriter font. What I want to know is: is there a symbol, which comes halfway between caret and wedge in shape, and is the same weight as a typewriter caret (so can be used within \texttt{})?

I've tried replacing \verb!^! with {{}\large\textasciicircum} and this sort of works, but is still clearly not an optimum solution.

Best Answer

The appearance of the care symbol depends on the used font. For example, Courier or TeX Gyre Cursor has a symbol that is something between the caret of the Computer Modern fonts and the \wedge solution.

The following example uses \lstinline instead of \verb, because a symbol can more easily be replaced via option literate:

\documentclass{article}
\usepackage{listings}
\newcommand*{\caret}{%
  \begingroup
    \fontencoding{T1}%
    \fontfamily{qcr}% TeX Gyre Cursor
    %\fontfamily{pcr}% Courier
    \selectfont
    \string^%
  \endgroup
}
\lstdefinestyle{caret}{
  basicstyle=\ttfamily,
  literate={^}{\caret}{1},
}
\newcommand*{\lstverb}{\lstinline[style=caret]}

\begin{document}
\begin{tabular}{ll}
\verb|\verb|: &
  \verb|x^3+x^2-1| \\
\verb|\wedge|: &
  \texttt{x$^\wedge$3+x$^\wedge$2-1} \\
\verb|\lstinline| + \verb|\caret|: &
  \lstverb|x^3+x^2-1| \\
\end{tabular}
\end{document}

Result