0

in the manual of the command of the listing package, "LaTex" is one of the predefined languages. I know it may sounds confusing but I want to write my Latex code with the \ and everything (imagine it as a tutorial), inside de command of lstlistings. I want to style the code, because if I only use lstlistings looks very boring, and simple. I know I can define de language using

\begin{lstlisting}[language=Tex]

For example, but for some reason even though TeX is a language that is in the manual as a predefined language, it doesn't change a bit! Stills the same, I tried to do mystyle, and define my own style but there are already predefined things like comments, valuable words, etc, that of course in LaTex not the same words as Python. I want to make my code look aesthetic, good for my students no boring and simple. This is an example of how I have my code.

This is how I actually have it:

\lstdefinestyle{R}
{
  language=LaTex,                     % <===================================
  basicstyle=\small\ttfamily,
  numbers=none,                   % where to put the line-numbers
  backgroundcolor=\color{white},  % choose the background color
  frame=single,                   % frame around code
  rulecolor=\color{black},        % if not set, the frame-color may be changed on line-breaks within not-black text
  tabsize=1,                      % sets default tabsize
  breaklines=true,                % sets automatic line breaking
  breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
}

1 Answer 1

0

Try this:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings,xcolor}

\lstdefinestyle{mystyle}
{
  language=[LaTeX]{TeX},
  texcsstyle=*\color{blue},
  basicstyle=\ttfamily,
  moretexcs={mycommand}, % user command highlight
  frame=single,
}
\begin{document}

\begin{lstlisting}[style=mystyle]
\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand*{\mycommand}{Hello World!}
\begin{document}
  \mycommand
\end{document}
\end{lstlisting}

\end{document}

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.