Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am having problem with lstinline macro. It keeps adding a space after the keyword "Module" - see MWE. How could I convince Latex not to do so?

I already tried with including the "." inside the \koda argument, but then I get 2 spaces onward.


\lstinline[language=[Visual]Basic,keywordstyle=\ttfamily\color{blue}, %
basicstyle=\rmfamily\normalsize, prebreak=, %
morekeywords={Or, Loop, Until, To, As, Single, Module, Double, ByVal}]
{#1}} %

An example with \koda{Console, Sub et Module}. Continued text ...

Thanks in advance!

share|improve this question
Your MWE is too minimal this time. You need to add \usepackage{xcolor}. Also, you should put curly braces around the language selection, as in \lstinline[language={[Visual]Basic},...], because otherwise there are issues with the parsing of the square brackets. With these fixes, I do not see the space between 'Module' and the '.' that you are talking about. – cyberSingularity Dec 12 '12 at 17:52

2 Answers 2

up vote 4 down vote accepted

If you fix your example by adding curly braces around the language and loading xcolor, there aren't any issues with the spacing after the code. But there is still an issue with spacing before: there's an extra space. I've tried taking out spaces and putting in %'s, and nothing seems to fix it. Also, it seems to be specific to [Visual]Basic; if you try [Visual]C++, the extra space goes away. If you delete the language setting within the \lstinline, and use a \lstset{language=[Visual]Basic} outside the \koda definition, the space also goes away. Maybe a bug somewhere in the Visual Basic definition?

enter image description here


    morekeywords={Or, Loop, Until, To, As, Single, Module, Double, ByVal}]}


An example with LEFT\koda{Console, Sub et Module}RIGHT. Continued text ...

share|improve this answer
In this case I would consider to define \koda with no argument, leaving off {#1}, so that one could use all the features of \lstinline such as \koda!text!, avoiding premature tokenization. – egreg Dec 12 '12 at 23:28
@egreg I agree, that's a better approach. I've edited the answer. Unfortunately, the extra space is still present, and still goes away for language={[Visual]C++}. – G. Poore Dec 13 '12 at 1:31
Thank you both for your ideas. I used the curly braces around the language definition and left out the argument to \koda. – Pjanc Matuzl Dec 21 '12 at 7:48

The space before is a bug in lstmisc.sty (2007/02/22 v1.4) in the following "aspect", line 849:

    \lst@KCAkeywordsB@list\lst@KCAkeywordsB \lst@KC@also
    \lst@gKCAkeywordsB@list\lst@gKCAkeywordsB \lst@KCAWorkB
    {kcb}owo % prefix, other key, working procedure, Output hook

Line 849 should remove the space before the comment:

    {kcb}owo% prefix, other key, working procedure, Output hook

(The next lines without the comment work, because the end of line character 13 (^^M) has catcode 9 for ignore.)


If the language is loaded in the preamble, the white space is executed in vertical mode causing no harm:

share|improve this answer
PLEASE IGNORE THE ABOVE COMMENT. Could not delete it :( I tried fixing the bug and removing the space in lstmisc.sty and it did not help. However, using lstset{...} not straight before lstinline solved the extra space problem. – Eran Marom Sep 14 at 9:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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