I'm trying to add an environment for code listings to stay on one page as described in "How to prevent lstlisting from splitting code between pages?".
When my listing is at the bottom of the page, the page number will appear within the environment. How do I force the page number to display outside of the environment?
An example follows. In this case the environment takes up the entire page. If possible I would like to remove page numbers entirely when it would cause a page boundary to be reached.
\documentclass{scrreprt}
\usepackage{bera}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{xcolor}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}
\lstset{
basicstyle=\normalfont\ttfamily,
numbers=left,
numberstyle=\scriptsize,
stepnumber=1,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frame=lines,
backgroundcolor=\color{background},
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
breakatwhitespace=true,
commentstyle=\color{pgreen},
keywordstyle=\color{pblue},
stringstyle=\color{pred},
basicstyle=\ttfamily,
moredelim=[il][\textcolor{pgrey}]{$$},
moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%}
}
\lstnewenvironment{code}[1][]%
{
\noindent
\minipage{\linewidth}
\vspace{0.5\baselineskip}
\lstset{basicstyle=\ttfamily\footnotesize,frame=single,#1}}
{\endminipage}
\begin{document}
\begin{figure}[H]
\begin{code}[language=Java]
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
public class SesSmtpCredentialGenerator {
private static final String KEY_ENV_VARIABLE = "AWS_SECRET_ACCESS_KEY"; // Put your AWS secret access key in this environment variable.
private static final String MESSAGE = "SendRawEmail"; // Used to generate the HMAC signature. Do not modify.
private static final byte VERSION = 0x02; // Version number. Do not modify.
public static void main(String[] args) {
// Get the AWS secret access key from environment variable AWS_SECRET_ACCESS_KEY.
String key = System.getenv(KEY_ENV_VARIABLE);
if (key == null)
{
System.out.println("Error: Cannot find environment variable AWS_SECRET_ACCESS_KEY.");
System.exit(0);
}
// Create an HMAC-SHA256 key from the raw bytes of the AWS secret access key.
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "HmacSHA256");
try {
// Get an HMAC-SHA256 Mac instance and initialize it with the AWS secret access key.
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(secretKey);
// Compute the HMAC signature on the input data bytes.
byte[] rawSignature = mac.doFinal(MESSAGE.getBytes());
// Prepend the version number to the signature.
byte[] rawSignatureWithVersion = new byte[rawSignature.length + 1];
byte[] versionArray = {VERSION};
System.arraycopy(versionArray, 0, rawSignatureWithVersion, 0, 1);
System.arraycopy(rawSignature, 0, rawSignatureWithVersion, 1, rawSignature.length);
// To get the final SMTP password, convert the HMAC signature to base 64.
String smtpPassword = DatatypeConverter.printBase64Binary(rawSignatureWithVersion);
System.out.println(smtpPassword);
}
catch (Exception ex) {
System.out.println("Error generating SMTP password: " + ex.getMessage());
}
}
}
\end{code}
\caption{Java implementation of SES password algorithm\label{fig:ses-password}}
\end{figure}
\end{document}
\documentclass{...}and ending with\end{document}. – Oct 01 '14 at 19:45\thispagestyle{empty}– Oct 01 '14 at 23:41