3

I will show the settings of the listings package, like this MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset{ 
   backgroundcolor=\color{yellow!10},
   basicstyle=\ttfamily\footnotesize,
   breakatwhitespace=false,
   breaklines=true,
   captionpos=b,
   commentstyle=\color{green},
   deletekeywords={...},
   escapeinside={\%*}{*)},
   frame=leftline,
   keepspaces=true,
   keywordstyle=\color{blue},
   language={[LaTeX]{TeX}},
   morekeywords={documentclass,document,book,article,usepackage,begin,end,newcommand,renewcommand,table,tabular,figure,toprule,midrule,bottomrule},
   numbers=left,
   numbersep=5pt,
   numberstyle=\ttfamily\color{blue},
   rulecolor=\color{blue},
   showlines=true,
   showspaces=false,
   showstringspaces=false,
   showtabs=false,
   stepnumber=1,
   stringstyle=\color{blue},
   tabsize=2,
   title=\lstname
}
\begin{document}
\begin{lstlisting}[caption=Listings Package Setting]
\lstset{ 
    backgroundcolor=\color{yellow!10},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    commentstyle=\color{green},
    deletekeywords={...},
    escapeinside={\%*}{*)},
    frame=leftline,
    keepspaces=true,
    keywordstyle=\color{blue},
    language={[LaTeX]{TeX}},
    morekeywords={documentclass,document,book,article,usepackage,begin,end,newcommand,renewcommand,table,tabular,figure,toprule,midrule,bottomrule},
    numbers=left,
    numbersep=5pt,
    numberstyle=\ttfamily\color{blue},
    rulecolor=\color{blue},
    showlines=true,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    stepnumber=1,
    stringstyle=\color{blue},
    tabsize=2,
    title=\lstname
}
\end{lstlisting}
\end{document}

but does not show what I want

listing trouble

2

This is because you're duplicating your settings as part of a listing to which all the settings apply. As such, not only do you define the listing to escape inside some set of elements, but you also supply those elements.

I would just temporarily disable the escapeinside key-value for the listing that contains your settings:

\begin{lstlisting}[caption=Listings Package Setting, escapeinside={}{}]

This provides the output:

enter image description here

4

It's because of escapeinside it will create area to you that's not in the listing area, you can write LaTeX code there for example

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset{ 
   backgroundcolor=\color{yellow!10},
   basicstyle=\ttfamily\footnotesize,
   breakatwhitespace=false,
   breaklines=true,
   captionpos=b,
   commentstyle=\color{green},
   deletekeywords={...},
   escapeinside={\%*}{*)},
   frame=leftline,
   keepspaces=true,
   keywordstyle=\color{blue},
   language={[LaTeX]{TeX}},
   morekeywords={documentclass,document,book,article,usepackage,begin,end,newcommand,renewcommand,table,tabular,figure,toprule,midrule,bottomrule},
   numbers=left,
   numbersep=5pt,
   numberstyle=\ttfamily\color{blue},
   rulecolor=\color{blue},
   showlines=true,
   showspaces=false,
   showstringspaces=false,
   showtabs=false,
   stepnumber=1,
   stringstyle=\color{blue},
   tabsize=2,
   title=\lstname
}
\begin{document}

\begin{lstlisting}[caption=Listings Package Setting]
\lstset
    backgroundcolor=\color{yellow!10},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    commentstyle=\color{green},
    deletekeywords={...},
    escapeinside={%* book,article are keywords but here!!\\
        I can use \LaTeX codes here like $\Sigma$
     *)},
    frame=leftline,
    keepspaces=true,
    keywordstyle=\color{blue},
    language={[LaTeX]{TeX}},
    morekeywords={documentclass,document,book,article,usepackage,begin,end,newcommand,renewcommand,table,tabular,figure,toprule,midrule,bottomrule},
    numbers=left,
    numbersep=5pt,
    numberstyle=\ttfamily\color{blue},
    rulecolor=\color{blue},
    showlines=true,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    stepnumber=1,
    stringstyle=\color{blue},
    tabsize=2,
    title=\lstname

\end{lstlisting}
\end{document}

enter image description here

so the code between escapeinside %*[Code here]*) will be LaTeX code and when you copy past it the }{ would cause an error because its an error in LaTeX document.

If you want have the exact text use this escapeinside=%*\{\textbackslash \%\textasteriskcentered\}\{\textasteriskcentered)\}*)

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.