0

I am having issues with inline listings line wrapping. As you can see in the linked image, the period ending the sentence is on the next line due to wrapping of the cite-website text. The listings package decided to wrap the text even though the whole of it is on the first line. If the red hook-arrow was not there, the period would fit there.

listings wrapping issues image

MWE:

\documentclass[twoside]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
\usepackage{listings}
\usepackage[vmargin=1in,headheight=13pt,twoside,twocolumn,a5paper]{geometry}
\usepackage{accsupp}
\usepackage{MnSymbol}
\usepackage{textcomp}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

\newcommand{\noncopy}[1]{%
    \BeginAccSupp{method=escape,ActualText={}}%
    #1%
    \EndAccSupp{}%
}

\lstset{breaklines=true,
  xleftmargin=1.5em,framexleftmargin=1em,
  basicstyle=\ttfamily,
  upquote=true,
  literate={`}{{\BeginAccSupp{method=plain,ActualText=`}‵\EndAccSupp{}}}1
  {"}{{\BeginAccSupp{method=plain,ActualText="}"\EndAccSupp{}}}1
  {'}{{\BeginAccSupp{method=plain,ActualText='}'\EndAccSupp{}}}1,
  showstringspaces=false,
  numbers=left, numberstyle=\scriptsize\noncopy,
  %postbreak=\raisebox{0ex}[0ex][0ex]{\noncopy{\ensuremath{\color{red}\hookrightarrow}}},
  prebreak=\raisebox{0ex}[0ex][0ex]{\noncopy{\ensuremath{\color{red}\rhookswarrow}}}
}

\begin{document}
Foo bar baaz \lstinline!cite-website!.
\end{document}

UPDATE 1

Here is smaller MWE. I am keeping the above in the post because I am actually using all those things in the actual document:

\documentclass[twoside]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{listings}
\usepackage[vmargin=1in,headheight=13pt,twoside,twocolumn,a5paper]{geometry}
\usepackage{MnSymbol}
\usepackage{textcomp}

\lstset{breaklines=true,
  basicstyle=\ttfamily,
  showstringspaces=false,
  prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\rhookswarrow}}}

\begin{document}
Foo bar baaz \lstinline!cite-website!.
\end{document}
  • Although this doesn't solve the issue with listings, have you had a look at minted? It is a pretty good package to highlight code. Also, if you're inserting a URL, you could use \url provided by hyperref. – JP-Ellis Feb 10 '16 at 11:33
  • @JP-Ellis: Well, I am using org-mode which I convert to LaTeX using Pandoc. It supports minted highlighting by default but the last time I tried it was not wrapping long lines, which is something I need. – wilx Feb 10 '16 at 11:41
  • @JP-Ellis: The cite-website is actually a name of a tool that I have created. – wilx Feb 10 '16 at 11:42
  • Yeah, \mintinline doesn't support line breaks because it is intended to be use to single keywords. If you have snippets of code which are quite long, then perhaps you want them in their own small listings instead of having them inline? – JP-Ellis Feb 10 '16 at 11:48
1

I've just begun experimenting with listings. Have you tried adding this line to your \lstset definition?

breakatwhitespace=true,

This setting determines whether automatic breaks should only happen at whitespace (I think by default they can happen anywhere in a line, to accommodate people who are writing types of code without much whitespace in it.)

Source: https://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings#Settings

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.