
MWE:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
basicstyle=\small\sffamily,
frame=tb,
columns=fullflexible,
escapeinside={`}{`},
escapebegin={\color{darkgray}\textlangle},
escapeend={\textrangle}
}
\begin{document}
\begin{lstlisting}
`what`
\end{lstlisting}
\end{document}
이스케이프 시퀀스`코드에서 자리 표시자 값을 스타일링하는 특정 사용 사례가 있다고 가정합니다(예: ).
보다 일반적인 사항에 대해 별도의 이스케이프 시퀀스를 사용할 수 있기를 바랍니다. 내가 할 수 있는 방법이 있나요?
답변1
아니요, 가능하지 않다고 생각합니다. 목록당 한 쌍의 이스케이프 시퀀스만 허용됩니다.
대신 다양한 작업에 대한 매크로를 정의할 수 있습니다.
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
basicstyle=\small\sffamily,
frame=tb,
columns=fullflexible,
escapeinside={`}{`},
}
\NewDocumentCommand{\AAA}{m}{\textcolor{darkgray}{\textlangle #1\textrangle}}
\NewDocumentCommand{\BBB}{m}{\textcolor{red!80}{\textnormal{\textbf{#1}}}}
\begin{document}
\begin{lstlisting}
xyz `\AAA{what}` uvw
abc `\BBB{where}` def
\end{lstlisting}
\end{document}