fmarotta / kaobook

A LaTeX class for books, reports or theses based on https://github.com/kenohori/thesis and https://github.com/Tufte-LaTeX/tufte-latex.
https://github.com/fmarotta/kaobook
LaTeX Project Public License v1.3c
858 stars 184 forks source link

Issues related to listings #236

Closed pi8027 closed 4 weeks ago

pi8027 commented 2 years ago

Description

I experienced several issues related to listings, such as:

I'm preparing a PR to fix (most of) them. I provide a test case for my fix below.

Minimal Working Example

\documentclass{kaobook}[twoside=true]
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{kaobiblio}
\usepackage{minted}
\usepackage{listings}

\begin{document}

\setchapterstyle{kao}

\chapter{First Chapter}

\begin{listing}[h]
\caption{Hello world in C (minted, normal listing).}
\begin{minted}{c}
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
\end{minted}
\end{listing}

\lipsum[1]

\begin{listing*}[h]
\caption{Hello world in C (minted, wide listing).}
\begin{minted}{c}
#include <stdio.h>
int main() { printf("Hello, World!"); return 0; }
\end{minted}
\end{listing*}

\begin{marginlisting}
\caption{Hello world in C (minted, margin listing).}
\begin{minted}{c}
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
\end{minted}
\end{marginlisting}

\lipsum[1]

\newpage

\begin{listing}[h]
\caption{Hello world in C (minted, normal listing).}
\begin{minted}{c}
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
\end{minted}
\end{listing}

\lipsum[1]

\begin{listing*}[h]
\caption{Hello world in C (minted, wide listing).}
\begin{minted}{c}
#include <stdio.h>
int main() { printf("Hello, World!"); return 0; }
\end{minted}
\end{listing*}

\begin{marginlisting}
\caption{Hello world in C (minted, margin listing).}
\begin{minted}{c}
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
\end{minted}
\end{marginlisting}

\lipsum[1]

\newpage

\begin{listing}[h]
\caption{Hello world in C (listings, normal listing).}
\begin{lstlisting}[language=C]
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
\end{lstlisting}
\end{listing}

\lipsum[1]

\begin{listing*}[h]
\caption{Hello world in C (listings, wide listing).}
\begin{lstlisting}[language=C]
#include <stdio.h>
int main() { printf("Hello, World!"); return 0; }
\end{lstlisting}
\end{listing*}

\begin{marginlisting}
\caption{Hello world in C (listings, margin listing).}
\begin{lstlisting}[language=C]
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
\end{lstlisting}
\end{marginlisting}

\lipsum[1]

\newpage

\begin{listing}[h]
\caption{Hello world in C (listings, normal listing).}
\begin{lstlisting}[language=C]
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
\end{lstlisting}
\end{listing}

\lipsum[1]

\begin{listing*}[h]
\caption{Hello world in C (listings, wide listing).}
\begin{lstlisting}[language=C]
#include <stdio.h>
int main() { printf("Hello, World!"); return 0; }
\end{lstlisting}
\end{listing*}

\begin{marginlisting}
\caption{Hello world in C (listings, margin listing).}
\begin{lstlisting}[language=C]
#include <stdio.h>
int main() {
  printf("Hello, World!");
  return 0;
}
\end{lstlisting}
\end{marginlisting}

\lipsum[1]

\end{document}

Expected behavior:

after.pdf

Actual behavior:

before.pdf