Do not show line numbers for listings without references to lines

This commit is contained in:
Jip J. Dekker 2021-07-25 18:45:35 +10:00
parent 669ad29176
commit f480d6fea4
No known key found for this signature in database
GPG Key ID: 517DF4A00618C9C3
4 changed files with 20 additions and 15 deletions

View File

@ -128,7 +128,7 @@
\usepackage[many]{tcolorbox} \usepackage[many]{tcolorbox}
\newtcolorbox{listingbox}[1][]{ \newtcolorbox{listingbox}[1][]{
breakable, % breakable,
enhanced, enhanced,
arc=0pt, arc=0pt,
boxrule=0pt, boxrule=0pt,
@ -155,11 +155,16 @@
\newcommand{\ptinline}[1]{{\texttt{\small {#1}}}} \newcommand{\ptinline}[1]{{\texttt{\small {#1}}}}
\newcommand{\highlightfile}[2]{\inputminted[autogobble=true,breaklines,breakindent=4em,frame=leftline,framesep=5pt,numbers=left,escapeinside=@@,fontsize=\scriptsize,tabsize=2]{#1}{#2}} \newcommand{\highlightfile}[3][n]{
\ifx l#1\inputminted[autogobble=true,breaklines,breakindent=4em,frame=leftline,framesep=5pt,numbers=left,escapeinside=@@,fontsize=\scriptsize,tabsize=2]{#2}{#3}
\else \begin{listingbox}\inputminted[autogobble=true,breaklines,breakindent=4em,escapeinside=@@,fontsize=\scriptsize,tabsize=2]{#2}{#3}\end{listingbox}
\fi
}
\newcommand{\pyfile}[1]{\highlightfile{python}{#1}}
\newcommand{\mznfile}[1]{\highlightfile{minizinc}{#1}} \newcommand{\pyfile}[2][n]{\highlightfile[#1]{python}{#2}}
\newcommand{\mznfile}[2][n]{\highlightfile[#1]{minizinc}{#2}}
\newcommand{\mzninline}[1]{\mintinline[fontsize=\small,escapeinside=@@]{minizinc}{#1}} \newcommand{\mzninline}[1]{\mintinline[fontsize=\small,escapeinside=@@]{minizinc}{#1}}
\newenvironment{mzn}{\VerbatimEnvironment{}\begin{minted}[ \newenvironment{mzn}{\VerbatimEnvironment{}\begin{minted}[
autogobble=true, autogobble=true,
@ -183,7 +188,7 @@
tabsize=2, tabsize=2,
]{minizinc}}{\end{minted}} ]{minizinc}}{\end{minted}}
\newcommand{\plainfile}[1]{\highlightfile{text}{#1}} \newcommand{\plainfile}[2][n]{\highlightfile[#1]{text}{#2}}
\newenvironment{plain}{\VerbatimEnvironment{}\begin{minted}[ \newenvironment{plain}{\VerbatimEnvironment{}\begin{minted}[
autogobble=true, autogobble=true,
breaklines, breaklines,
@ -194,7 +199,7 @@
tabsize=2, tabsize=2,
]{text}}{\end{minted}} ]{text}}{\end{minted}}
\newcommand{\amplfile}[1]{\highlightfile{ampl}{#1}} \newcommand{\amplfile}[2][n]{\highlightfile[#1]{ampl}{#2}}
\newenvironment{ampl}{\VerbatimEnvironment{}\begin{minted}[ \newenvironment{ampl}{\VerbatimEnvironment{}\begin{minted}[
autogobble=true, autogobble=true,
breaklines, breaklines,

View File

@ -59,7 +59,7 @@ This \variable{} is made to be our optimization goal on \lref{line:intro:goal}.
Finally, \lrefrange{line:intro:con:start}{line:intro:con:end} express the \constraints{} of our problem in terms of equations bound by logic. Finally, \lrefrange{line:intro:con:start}{line:intro:con:end} express the \constraints{} of our problem in terms of equations bound by logic.
\begin{listing} \begin{listing}
\amplfile{assets/listing/intro_open_shop.mod} \amplfile[l]{assets/listing/intro_open_shop.mod}
\caption{\label{lst:intro-open-shop} An \glsxtrshort{ampl} model of the open shop problem.} \caption{\label{lst:intro-open-shop} An \glsxtrshort{ampl} model of the open shop problem.}
\end{listing} \end{listing}

View File

@ -101,7 +101,7 @@ Its expressive language and extensive library of \glspl{global} allow users to e
\end{example} \end{example}
\begin{listing} \begin{listing}
\mznfile{assets/listing/back_knapsack.mzn} \mznfile[l]{assets/listing/back_knapsack.mzn}
\caption{\label{lst:back-mzn-knapsack} A \minizinc{} model describing a 0-1 knapsack problem.} \caption{\label{lst:back-mzn-knapsack} A \minizinc{} model describing a 0-1 knapsack problem.}
\end{listing} \end{listing}
@ -876,7 +876,7 @@ Different types of \solvers{} can also have access to different types of \constr
A possible \cmodel{} for this problem in \gls{ampl} is shown in \cref{lst:back-ampl-tsp}. A possible \cmodel{} for this problem in \gls{ampl} is shown in \cref{lst:back-ampl-tsp}.
\begin{listing} \begin{listing}
\amplfile{assets/listing/back_tsp.mod} \amplfile[l]{assets/listing/back_tsp.mod}
\caption{\label{lst:back-ampl-tsp} An \gls{ampl} model describing the \gls{tsp}.} \caption{\label{lst:back-ampl-tsp} An \gls{ampl} model describing the \gls{tsp}.}
\end{listing} \end{listing}
@ -949,7 +949,7 @@ When solving a scheduling problem, \gls{opl} makes use of specialized interval \
Abstracting from the \parameter{} declarations, the possible formulation of the \variable{} declarations and \constraints{} for the job shop problem in \gls{opl} is shown in \cref{lst:back-opl-jsp}. Abstracting from the \parameter{} declarations, the possible formulation of the \variable{} declarations and \constraints{} for the job shop problem in \gls{opl} is shown in \cref{lst:back-opl-jsp}.
\begin{listing} \begin{listing}
\plainfile{assets/listing/back_jsp.mod} \plainfile[l]{assets/listing/back_jsp.mod}
\caption{\label{lst:back-opl-jsp} An \gls{opl} model describing the job shop problem, abstracting from \parameter{} declarations.} \caption{\label{lst:back-opl-jsp} An \gls{opl} model describing the job shop problem, abstracting from \parameter{} declarations.}
\end{listing} \end{listing}
@ -1041,7 +1041,7 @@ Partitions are defined for finite types: Booleans, enumerated types, or a restri
A \cmodel{} for the social golfer problem in \gls{essence} can be seen in \cref{lst:back-essence-sgp}. A \cmodel{} for the social golfer problem in \gls{essence} can be seen in \cref{lst:back-essence-sgp}.
\begin{listing} \begin{listing}
\plainfile{assets/listing/back_sgp.essence} \plainfile[l]{assets/listing/back_sgp.essence}
\caption{\label{lst:back-essence-sgp} An \gls{essence} model describing the social golfer problem} \caption{\label{lst:back-essence-sgp} An \gls{essence} model describing the social golfer problem}
\end{listing} \end{listing}

View File

@ -176,7 +176,7 @@ In any following \gls{restart}, \mzninline{select} is incremented modulo \mzninl
This will activate a different \gls{neighbourhood} for each subsequent \gls{restart} (\lref{line:6:roundrobin:post}). This will activate a different \gls{neighbourhood} for each subsequent \gls{restart} (\lref{line:6:roundrobin:post}).
\begin{listing} \begin{listing}
\mznfile{assets/listing/inc_round_robin.mzn} \mznfile[l]{assets/listing/inc_round_robin.mzn}
\caption{\label{lst:inc-round-robin} A predicate providing the round-robin meta-heuristic.} \caption{\label{lst:inc-round-robin} A predicate providing the round-robin meta-heuristic.}
\end{listing} \end{listing}
@ -311,7 +311,7 @@ We can rewrite \instances{} that contain the new functions by extending the \min
It simply replaces the functional form by a predicate \mzninline{status} (declared in \lref{line:6:status}), which constrains its local variable argument \mzninline{stat} to take the status value. It simply replaces the functional form by a predicate \mzninline{status} (declared in \lref{line:6:status}), which constrains its local variable argument \mzninline{stat} to take the status value.
\begin{listing} \begin{listing}
\mznfile{assets/listing/inc_status.mzn} \mznfile[l]{assets/listing/inc_status.mzn}
\caption{\label{lst:inc-status} MiniZinc definition of the \mzninline{status} function.} \caption{\label{lst:inc-status} MiniZinc definition of the \mzninline{status} function.}
\end{listing} \end{listing}
@ -413,7 +413,7 @@ We have omitted the similar code generated for \mzninline{x[2]} to \mzninline{x[
Note that the \flatzinc{} \gls{slv-mod} shown here has been simplified for presentation. Note that the \flatzinc{} \gls{slv-mod} shown here has been simplified for presentation.
\begin{listing} \begin{listing}
\mznfile{assets/listing/inc_basic_complete_transformed.mzn} \mznfile[l]{assets/listing/inc_basic_complete_transformed.mzn}
\caption{\label{lst:inc-flat-pred} The \flatzinc{} \gls{slv-mod} that results from \gls{rewriting} \\ \caption{\label{lst:inc-flat-pred} The \flatzinc{} \gls{slv-mod} that results from \gls{rewriting} \\
\mzninline{basic_lns(uniformNeighbourhood(x,0.2))}.} \mzninline{basic_lns(uniformNeighbourhood(x,0.2))}.}
\end{listing} \end{listing}