showexpl または listings でバックスラッシュを強調表示する

showexpl または listings でバックスラッシュを強調表示する

\LaTeX コード内の単一のバックスラッシュ ( ) をlistingsまたはを使用して強調表示する方法はありますかshowexpl? 次の例では、\LaTeXは正しく強調表示されていますが、次のバックスラッシュは強調表示されていません。

\documentclass{article}
\usepackage{xcolor,showexpl}
\lstset{language=[LaTeX]Tex,
   basicstyle=\ttfamily,
   keywordstyle=\color{red},
   texcsstyle=*\color{blue}
   }

\begin{document}

\begin{LTXexample}
Test \LaTeX\ test
\end{LTXexample}

\end{document}

答え1

参照showexpl で中括弧に色を付けるにはどうすればいいですか?

問題はshowexpl、、、、、がいくつかの点で互換性がないことtexclです。したがってmoretexcs、思いつくものはすべて試してみてください。morekeywordliterate

\documentclass{article}
    \usepackage{xcolor,showexpl}
        \lstset{language=[LaTeX]Tex,basicstyle=\ttfamily,texcsstyle=*\color{blue}}
        \lstdefinestyle{myLaTeX}{literate={~}{\textcolor{blue}{\char`\\\char`\ }}2}
\begin{document}
    \def~{}
    \begin{LTXexample}[style=myLaTeX]
        Test \LaTeX~test
    \end{LTXexample}
\end{document}

これも、スペースが間違っていますが、機能します。(私はU+00A0、改行なしスペース を使用しています。ただし、 の前に ASCII スペースがありますtest)

\documentclass{article}
\usepackage{xcolor,showexpl}
    \lstset{language=[LaTeX]Tex,basicstyle=\ttfamily,texcsstyle=*\color{blue}}
    \lstdefinestyle{myLaTeX}{moretexcs={ }}
\begin{document}
    \def\ {}
    \begin{LTXexample}[style=myLaTeX]
        Test\LaTeX\  test
    \end{LTXexample}

\end{document}

関連情報