[Tex/LaTex] How to show latex commands in text mode


Sorry for the basic question.
What I want to do is to show the LaTeX command and, right after that, the output. But how can I show LaTeX formulas without obtaining errors for not using the math mode environment.

The problem is if I put the $...$, the formula appears and not the command. If I dont use the $...$ I get an error.

I have tried also to put inside a \text{}. No good either.
Any suggestions?
Thanks in advance.

Best Answer

You can use \verb as

\verb!$x^2 + y^2 = r^2$!

Or better use listings package


Full code:


Using \verb|\verb|:

\verb!$x^2 + y^2 = r^2$! \quad $\longrightarrow$ \quad $x^2 + y^2 = r^2$

Using \verb|listings|:

\lstinline[language={[LaTeX]TeX},basicstyle=\ttfamily]{$x^2 + y^2 = r^2$} \quad $\longrightarrow$ \quad $x^2 + y^2 = r^2$

enter image description here

Related Question