1

Does anyone know why I'm getting extra spaces in front of the keywords in my code listings? I've attached a picture of one of my listings that I've compile with showspaces=true and showtabs=true. You can clearly see gaps in front of the void, range, int, and other keywords. However these gaps aren't denoted as being spaces with the underscoring.

The styles I'm using are:

basicstyle=\ttfamily\footnotesize,
keywordstyle=\color{black}\bfseries\rmfamily\footnotesize,

Also there are no spaces in front of any of the keywords in the keywords={ or morekeywords={ sections of my language definition.

Is it something to do with the change in font families between the keywords and regular identifiers? Does anyone have any suggestions how I can get rid of them?

Example of code listing with extra spaces

1
0

In the process of trying to create a minimum working example I managed to track down the problem. Initially I couldn't reproduce the glitch. It's not actually connected to the Listings package, but rather other header statements in my thesis.

Some microtype compilation code that I'd come across in a blog post by Cameron Bracken was the real culprit.

The troublesome section was:

\usepackage{microtype}
\makeatletter 
\def\MT@register@subst@font{
    \MT@exp@one@n\MT@in@clist\font@name\MT@font@list 
    \ifMT@inlist@\else\xdef\MT@font@list{\MT@font@list\font@name,}\fi} 
\makeatother

In particular it seems like the indentation in Cameron's example between the @font{ and the \MT@exp@one.... was the problem. If you remove the carriage return (or new line) and place both statements on a single line the problem disappears from any listings.

2
  • 1
    90% of all questions with the word "space" in them are answered by adding % to ends of line. Aug 6 '13 at 15:16
  • I think I was wrong-footed by the fact the issue only revealed itself in code listings, so it wasn't particularly obvious that actually the microtype stuff was to blame. Ach well, the joys of LaTeX!
    – Alastair
    Aug 6 '13 at 15:38

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.