Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Jun 4 at 13:48

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer
    
Solved! Thanks, @Werner! –  Edy Jo Jun 1 at 7:17

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)\}*)

share|improve this answer
    
Thank you, @Karo! –  Edy Jo Jun 1 at 7:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.