Listings adds whitespaces, how to remove it? - latex

Hey guys,
when using listings to present code in my PDF, it adds whitespaces after some characters.
This is how it looks in the pdf (I'm not allowed to post images because of reputation, 'hence add ".png" to the url, sorry).
I'm using the following code to add the listings.
\newcommand{\lstchange}[2]{
\lstset{breaklines=true,
frame=single,
captionpos=b,
basicstyle={\ttfamily\footnotesize},
showspaces=false,
showstringspaces=false,
showtabs=false,
numberstyle={\ttfamily\footnotesize},
keywordstyle={\bfseries\color{blue}},
stringstyle=\color{darkorange}\ttfamily,
commentstyle=\color{OliveGreen},
language=#1,
morekeywords={#2} }
}
% ...
\lstchange{bash}{svn , cd, gnome-open}
\begin{lstlisting}[caption=someCaption, label=someLabel]
#!/bin/bash
svn checkout http://opendecisionrepository.googlecode.com/svn/trunk/sources/web-interface/src/main/webapp odr-appetizer-2 -r 621
cd odr-appetizer-2
#open drawing.xhtml
gnome-open drawing.xhtml
\end{lstlisting}
Does anyone of you have an idea why this happens? Even if I use the standard example from the latex wikibook this happens.
Maybe this is also important for you, the config file:
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[left=2.5cm, right=2.5cm, top=2.5cm, bottom=3cm, a4paper]{geometry}
\usepackage[pdftex]{graphics}
\usepackage{fancyhdr}
\usepackage{%
array,
booktabs,
dcolumn,
rotating,
shortvrb,
tabularx,
units,
url,
xcolor,
lastpage,
longtable,
lscape,
multirow,
amssymb,
amsmath,
float,
chngpage,
colortbl,
helvet,
listings
}
Thanks in advance!
Cheers,
Ben

Cannot reproduce this here (with \documentclass{article}), it looks fine. I only had to comment out "OliveGreen" because it was unknown.

Related

Is there a way to make the a glossary entry clickable?

I'm making a glossary using the package \usepackage{glossaries}. This works fine but I have a slight problem.
I would like to make the word I call from the glossary (with \gls(a_word)) clickable, so the reader is automatically taken to the glossary entry that match the word he clicked on.
So far, I tried to use hyperlinks, without any success, and I couldn't find a similar problem on Internet nor on SO.
I hope you will be able to help me out with this!
Thanks by advance
Edit: Here's the code I'm using
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[nonumberlist,toc,chapter=chapter]{glossaries}
In glossary:
\makeglossaries
\setglossarypreamble{Source is INSEE}
\newglossaryentry{AAV}
{
name=AAV,
description={The description of what AAV is.}
}
In document:
sometextsometext (see \Gls{AAV}). Sometextsometext
If you load the hyperref package, the abbreviation will automatically be clickable:
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage[nonumberlist,toc]{glossaries}
\makeglossaries
\setglossarypreamble{Source is INSEE}
\newglossaryentry{AAV}
{
name=AAV,
description={The description of what AAV is.}
}
\begin{document}
sometextsometext (see \Gls{AAV}). Sometextsometext
\printglossaries
\end{document}

How can i use special characters (ä,ü..) in LaTeX package qrcode

Code with Vcard informations in it. How can i use sepcial german characters like ä,ü, and so on. My file is saved under utf-8 encoding. This minimal example gives error.
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[]{qrcode}
\begin{document}
\qrcode{
BEGIN:VCARD\?
VERSION:4.0\?
N:Do;Jon;;Dr.\?
FN:Dr. Jon Do\?
ORG:Firma; Überirdische Firma\?
END:VCARD
}
\end{document}
I could solve the problem. But i do not know why it works..
Adding this line VERSION:3.0\? fixed the problem.

Custom caption prefix

When using:
\begin{listing}
...
\caption{foo}
\end{listing}
The caption will say: Listing x: foo. How can I replace the word Listing with something else?
If you are using minted (I am, and my source looks like yours), you may want to try
\renewcommand{\listingscaption}{Some fancy listing}
You might want to read the manual
http://mirror.switch.ch/ftp/mirror/tex/macros/latex/contrib/listings/listings.pdf
page 32
\begin{listing}[caption=Some fancy listing]
or try
\begin{listing}[title=Some fancy listing]
or try
\renewcommand{\lstlistingname}{A funny listing}
Minimal example that works for me:
\documentclass{article}
\usepackage{listings}
\renewcommand{\lstlistingname}{Something}
\begin{document}
Some text.
\begin{lstlisting}[caption=wwww]
xxxx
\end{lstlisting}
Some more text.
\end{document}

LaTeX lstlisting underlined

Is there an easy way to have the complete code in a lstlisting environment underlined?
My current solution looks like this, but I'm not really happy with it.
\begin{lstlisting}[mathescape]
$\ul{if(gt(x1, 0)) then} $
...
\end{lstlisting}
Thanks for any tips.
According to page 5 in the user guide (found here):
\lstset{keywordstyle=\underbar}
If you want to underline the entire line (and not only the keywords), the best solution I can come up with is to do something along the lines below:
\usepackage{listings}
\newcommand{\lstul}[1]{\underline{\mbox{\tt #1}}}
\begin{document}
\begin{lstlisting}[mathescape]
$\lstul{if condition}$
$\lstul{statement 1}$
$\lstul{statement 2}$
...
\end{lstlisting}
\end{document}

header width on the last page of the chapter

I'm trying to turn off marginpar when starting a new multicols environment with this new environment, which uses the multicols and chngpage packages:
\newenvironment{multi}[1]{%
\newlength{\newtextwidth}%
\setlength{\newtextwidth}{\marginparwidth}%
\addtolength{\newtextwidth}{-1cm}%
\addtolength{\headheight}{.5cm}%
\let\oldheadrule\headrule%
\addtolength{\headwidth}{\newtextwidth}%
\begin{adjustwidth}{}{-\newtextwidth}\begin{multicols}{#1}}%
{\end{multicols}\end{adjustwidth}}
Which works great:
latex header http://img6.imageshack.us/img6/6757/screenshotewa.png
Uhm, almost, since on the last page of the current chapter "Lorem ipsum" it behaves like I hadn't instruct it to: \addtolength{\headwidth}{\newtextwidth}:
latex header at the end of the chapter http://img11.imageshack.us/img11/6072/screenshotwbd.png
How could I fix that?
Edit:
I'm also using fancyhdr.
2nd Edit:
A PoC:
\documentclass[12pt,a4paper,oneside]{report}
\usepackage[utf8]{inputenc}
\usepackage[top=2cm,left=2cm,right=4.5cm]{geometry}
\usepackage{chngpage}
\usepackage{color}
\usepackage{amsmath}
\usepackage[pdftex,bookmarks,pdfpagemode=UseOutlines,bookmarksopen,backref
,colorlinks,urlcolor=blue,linktocpage]{hyperref}
\usepackage{url}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{indentfirst}
\usepackage{listings}
\usepackage{boxedminipage}
\pagestyle{fancy}
\setlength{\columnseprule}{1pt}
\setlength{\marginparwidth}{4cm}
\rhead{\large\leftmark}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\makeatletter
\renewcommand*\#makechapterhead[1]{%
{\parindent \z# \raggedright \normalfont
\huge\bfseries
#1\par\nobreak
\vskip 20\p#
}}
\makeatother
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\sffamily\raggedleft\footnotesize #1]%
{\sffamily\raggedright\footnotesize
\begin{boxedminipage}{\marginparwidth}#1\end{boxedminipage}
}}
\newenvironment{multi}[1]{%
\newlength{\newtextwidth}%
\setlength{\newtextwidth}{\marginparwidth}%
\addtolength{\newtextwidth}{-1cm}%
\addtolength{\headheight}{.5cm}%
\let\oldheadrule\headrule%
\addtolength{\headwidth}{\newtextwidth}%
\begin{adjustwidth}{}{-\newtextwidth}\begin{multicols}{#1}}%
{\end{multicols}\end{adjustwidth}}
\begin{document}
\tableofcontents
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\end{document}
It should be possible to continue single-column on the same page, after "multi", but the headers must be kept like when the page was started within the "multi" environment.
Why would I need single-column after multi-column on the same page with a marginpar? Imagine presenting the source code for the article, with small hints on the margin. (That's what the listing package is there for)
I suspect your last heading box is being constructed after your text finishes making the multicol boxes, so you're out of the scope of your change. It goes back to the old value.
You'd probably do well to add the fancyhdr package and use it. I believe it's well-behaved in multicolumn.
Okay, so it's almost certainly the scope thing. You're doing the adjustwidth in your new multi environment. When your text runs out in the multi envirnment, you haven't filled the last page; headers aren't set up until the page is filled. So your mutlti environment finishes the box, you leave the scope, and THEN the page is finished and emitted. Using the old width.
Set the header width and parameters outside the environment.
I ran your test document. It seems to have a bug in that \newlength{\newtextwidth} has a global effect, and so causes an error. Not sure why that is but I pulled it out of the \newenvironment{multi} with no ill effect.
Charlie's diagnosis is definitely correct. An alternative solution is to end the page after the multicols but before the adjustwidth, thus:
\newenvironment{multi}[1]{%
...}
{\end{multicols}\vfill\break\end{adjustwidth}}
I have tested this solution and on your sample document, it produces good output.

Resources