When I want to print out some common "special meaning" characters, I use the \verb command, i.e.

\verb?x^2 + 1? 

(No, I don't wan't to use the math mode, I want to print out that ^ character.)

Works fine, except then when I want to "box" the text. This: \fbox{\verb?x + 1?} works fine, but this: \fbox{\verb?x^2 + 1?} fails: seems that the fbox removes the verbatim-ness, and processes the ^ as math-mode (even though I didn't put any $...)

Question: is there a "simple" way to (re-)enable the verbatim mode inside a \fbox ?

Note: I also checked this similar question, however I am unable to make the accepted answer work.


you could use

\texttt{x\char`\^2 + 1}

output of example code

  • Seems to be the simplest (no additional package). And, for the record, \fbox{\texttt{x\char\^2 + 1}}` works fine.
    – kebs
    Nov 18 '14 at 16:45

The verbatimbox package can help. It also works on true verbatim, unlike a \texttt alternative.

\verb?x^2 + 1 + \alpha? \par
\begin{verbbox}x^2 + 1 + \alpha\end{verbbox}

enter image description here


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.