
¿Hay alguna manera de resaltar una sola barra invertida ( \
) dentro del código LaTeX con listings
o showexpl
? En el siguiente ejemplo, \LaTeX
está resaltado correctamente, pero no la siguiente barra invertida.
\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}
Respuesta1
Ver también¿Cómo puedo colorear las llaves en showexpl?
El problema es que showexpl
, texcl
, moretexcs
, morekeyword
y literate
no son compatibles en algunos aspectos. Así que prueba todo lo que se te ocurra.
\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}
Esto también funciona, con un espaciado incorrecto. (Estoy usando U+00A0
el espacio que no se separa. Pero hay un espacio ascii antes 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}