Выделение обратной косой черты с помощью 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, morekeyword, и literateнесовместимы в некоторых отношениях. Так что просто пробуйте все, что приходит вам в голову.

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

Связанный контент