How to show a LaTeX command in lstlisting?

241 views Asked by At

I code this in a .tex file.

\begin{lstlisting}
  % This is the syntax for inserting code.
  \begin{lstlisting}
  \end{lstlisting}
\end{lstlisting}

And this is what I expect:

  % This is the syntax for inserting code.
  \begin{lstlisting}
  \end{lstlisting}

Unfortunately, this is not feasible. What is the correct format?

1

There are 1 answers

0
samcarter_is_at_topanswers.xyz On

You can use another name for the lstlisting:

\documentclass{article}
\usepackage{listings}

\lstnewenvironment{mylisting}{}{}

\begin{document}

\begin{mylisting}
  % This is the syntax for inserting code.
  \begin{lstlisting}
  \end{lstlisting}
\end{mylisting}


\end{document}