1

I am trying to use the hack to highlight code between (but not including) two delimiters discussed in this question, but I am producing duplicate delimiters.

My goal is to highlight in orange everything between by (including the word "by") up until (but not including) a semicolon. So ideally thus X by a,b,c; would be highlighted as thus X \textcolor{orange}{by a,b,c};.

Here's a minimal working example with the bug:

\documentclass[varwidth=6.75in]{standalone}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{citeOrange}{HTML}{fb7640}

\newcommand{\mizarByStyle}[1]{\ \textcolor{citeOrange}{by} \textcolor{citeOrange}{#1};}

\lstdefinelanguage{mizar}{ morekeywords=[0]{->,(#,#),.=)}, moredelim=[is][\mizarByStyle]{\ by}{;} }

\lstnewenvironment{mizar}[1][]% {\lstset{language=mizar, basicstyle=\ttfamily, upquote=true}}% {}

\begin{document} \begin{mizar} theorem Th3: for f being Element of Aut G holds f is Automorphism of G proof let f be Element of Aut G; f is bijective Homomorphism of G,G by AUTGROUP:def 1; thus thesis; end; \end{mizar} \end{document}

And this is what it looks like:

Duplicate by keywords, this seems like a bug...

Addendum: what I suspect is happening is that listings is treating thus X by a:def 3; as several "tokens" delimited between by and ;, which then applies the \mizarByStyle to each "token". And if this is the case, is there any way to remedy the situation?

Almost certainly I will need to highlight situations like thus X by a, b, c; and the spaces between the a, b, and c would produce this "bug" all over again :(

Alex Nelson
  • 1,060

1 Answers1

1

It turns out I am not the only one to experience this problem, and the solution can be found in another post. For my problem, the minimal working solution:

\documentclass[varwidth=6.75in]{standalone}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{citeOrange}{HTML}{fb7640}

\def\beginlstdelim#1#2#3% {% \def\endlstdelim{#2\egroup}% \textcolor{#3}{#1}\bgroup\color{#3}\aftergroup\endlstdelim% }

\lstdefinelanguage{mizar}% { keepspaces=true, alsoletter={&,^,\,:,1234567890}, morekeywords=[0]{->,(#,#),.=)}, moredelim = **[is][{\beginlstdelim{\ by}{;}{citeOrange}}]{\ by}{;} }

% everything else as before

This has some problems with whitespacing (as discussed in the other post) and is not as robust as I'd like (and I honestly don't understand why it needs to be **[is] but it must be, changing it to unstarred [is] doesn't work), but it's a "quick fix" to the problem at hand.

Alex Nelson
  • 1,060