I'm trying to get long inline code to wrap at points that I specify with \-. I've got it working almost perfectly with this:

% !TEX program = xelatex







Here is a paragraph with some inline code. \code{Really\-Long\-Name\-First\-Second\-Third\-Fourth\-Fifth}.



enter image description here

My last remaining goal is to have the hyphen appear black rather than red, so it appears distinct from the code. I thought I'd just be able to use textcolor like this:


However, this gives me:

Improper discretionary list

I've tried various things, like wrapping the entire discretionary piece in {}, but nothing I've tried has worked.

How can I make the hyphen black?


Instead of using \textcolor inside a discretionary, you can use it around the discretionary:


Are you aware of the \lstset macro? Instead of using your \code, you can write


in your preamble. Then \lstinline always uses the options.

  • Wonderful, thanks! I'm at the point where I don't even question why one way works when another doesn't now. Regarding using lstset and lstinline, I just find \code reads (and writes) far nicer. – Kent Boogaart Mar 12 '18 at 7:15
  • 1
    For the question why: In \discretionary only characters, boxes and kerns are allowed, but \textcolor inserts a whatsit. – Marcel Krüger Mar 12 '18 at 7:18
  • @MarcelKrüger whether I was sure or not doesn't really matter, but certainly I was wrong:-) I'll clean up the comments here and fix my answer, thanks (who implemented \textcolor I wonder....) – David Carlisle Mar 12 '18 at 16:32

\textcolor colour whatsits to change the colour which are not allowed in a discretionary, however you can have boxes so you just need to put the content of each field in an \hbox

enter image description here





Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.