是否可以使用其中 language=latex 的 \lstdefinestyle (列表包)?

是否可以使用其中 language=latex 的 \lstdefinestyle (列表包)?

使用此设置:

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{xcolor}
\pagecolor[rgb]{0,0,0} %black, you can reset to white setting all values to 1
\color[rgb]{0.8,0.8, 0.8} % set text color to white
\definecolor{orange}{RGB}{255,127,80}
\definecolor{dark_gray}{rgb}{0.3803921568627451,0.3803921568627451,0.3803921568627451}
\newcommand{\wedgep}{\color{keywordcolour}\wedge} %to use it in propositionalcalculus profile
\usepackage{listings}
\RequirePackage{listings}
\RequirePackage{xcolor}

\renewcommand*{\lstlistlistingname}{Code Listings}
\renewcommand*{\lstlistingname}{Code Listing}
\definecolor{gray}{gray}{0.5}
\colorlet{commentcolour}{green!50!black}

\colorlet{stringcolour}{red!60!black}
\colorlet{keywordcolour}{magenta!90!black}
\colorlet{exceptioncolour}{yellow!50!red}
\colorlet{commandcolour}{blue!60!black}
\colorlet{numpycolour}{blue!60!green}
\colorlet{literatecolour}{magenta!90!black}
\colorlet{promptcolour}{green!50!black}
\colorlet{specmethodcolour}{violet}

\newcommand*{\framemargin}{3ex}

\newcommand*{\literatecolour}{\textcolor{literatecolour}}

\newcommand*{\pythonprompt}{\textcolor{promptcolour}{{>}{>}{>}}}
\lstset{
  backgroundcolor=\color{black}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
  basicstyle=\footnotesize, % the size of the fonts that are used for the code
  breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
  breaklines=true, % sets automatic line breaking
  captionpos=b, % sets the caption-position to bottom
  commentstyle=\color{mygreen}, % comment style
  deletekeywords={...}, % if you want to delete keywords from the given language
  escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
  extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
  firstnumber=000, % start line enumeration with line 0
  frame=single, % adds a frame around the code
  framexleftmargin=10pt,
  keepspaces=false, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
  keywordstyle=\color{blue}, % keyword style
  language=Python, % the language of the code
  morekeywords={*,∧,...}, % if you want to add more keywords to the set
  numbers=left, % where to put the line-numbers; possible values are (none, left, right)
  numbersep=5pt, % how far the line-numbers are from the code
  numberstyle=\tiny\color{dark_gray}, % the style that is used for the line-numbers
  rulecolor=\color{darkgray}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
  showstringspaces=false, % underline spaces within strings only
  showtabs=false, % show tabs within strings adding particular underscores
  stepnumber=1, % the step between two line-numbers. If it's 1, each line will be numbered
  stringstyle=\color{mymauve}, % string literal style
  tabsize=2, % sets default tabsize to 2 spaces
  title=\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title,
}

\lstdefinestyle{propositionalcalculus}{
showtabs=true,
tab=,
tabsize=2,
basicstyle=\ttfamily\footnotesize,%\setstretch{.5},
stringstyle=\color{stringcolour},
showstringspaces=false,
alsoletter={1234567890},
escapeinside={\%*}{*)},
otherkeywords={},
keywordstyle=\color{keywordcolour}\bfseries,
emph={and,break,class,continue,def,yield,del,elif ,else,%
except,exec,finally,for,from,global,if,import,in,%
lambda,not,or,pass,print,raise,return,try,while,assert,with, },
emphstyle=\color{blue}\bfseries,
emph={[2]True, False, None},
emphstyle=[2]\color{keywordcolour},
emph={[3]All},
emphstyle=[3]\color{commandcolour},
emph={},
emphstyle=\color{exceptioncolour}\bfseries,
%upquote=true,
morecomment=[s]{"""}{"""},
commentstyle=\color{commentcolour}\slshape,
%emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
emph={[4]is, are},
emphstyle=[4]\color{numpycolour},
emph={[5]},
emphstyle=[5]\color{specmethodcolour},
emph={[6]assert,yield},
emphstyle=[6]\color{keywordcolour}\bfseries,
emph={[7]range},
emphstyle={[7]\color{keywordcolour}\bfseries},
% emph={[7]self},
% emphstyle=[7]\bfseries,
literate=*%
{:}{{\literatecolour:}}{1}%
{,}{{\literatecolour,}}{1}
{=}{{\literatecolour=}}{1}%
{-}{{\literatecolour-}}{1}%
{+}{{\literatecolour+}}{1}%
{*}{{\literatecolour*}}{1}%
{**}{{\literatecolour{**}}}2%
{/}{{\literatecolour/}}{1}%
{//}{{\literatecolour{//}}}2%
{!}{{\literatecolour!}}{1}%
%{(}{{\literatecolour(}}{1}%
%{)}{{\literatecolour)}}{1}%
{[}{{\literatecolour[}}{1}%
{]}{{\literatecolour]}}{1}%
{<}{{\literatecolour<}}{1}%
{>}{{\literatecolour>}}{1}%
,%
%aboveskip=.5ex,
frame=trbl,
%frameround=tttt,
%framesep=.3ex,
rulecolor=\color{black!40},
%framexleftmargin=\framemargin,
%framextopmargin=.1ex,
%framexbottommargin=.1ex,
%framexrightmargin=\framemargin,
%framexleftmargin=1mm, framextopmargin=1mm, frame=shadowbox, rulesepcolor=\color{blue},#1
%frame=tb,
backgroundcolor=\color{black},
breakindent=.5\textwidth,frame=single,breaklines=true%
%}
}
\begin{document}
   \begin{lstlisting}[style=propositionalcalculus]
        All philosophers are eccentric,
        Jack is a philosopher %*$\wedgep$*) Jack is eccentric
    \end{lstlisting}
\end{document}

我能够显示这个:

上述代码的输出

但我用了一个愚蠢的技巧来做到这一点:

%*$\wedgep$*)

我想到这个解决方案是因为我无法添加 language=latex内部内容\lstdefinestyle{propositionalcalculus}{},因此最终需要escapeinside={\%*}{*)}使用\wedge

有没有办法避免退出lstlisting环境,同时获得与我相同的输出?理想情况下,在其中实现 LaTeX 语言...

相关内容