From f480d6fea44b6a198f0fb24c7e1350be97096f04 Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Sun, 25 Jul 2021 18:45:35 +1000 Subject: [PATCH] Do not show line numbers for listings without references to lines --- assets/packages.tex | 17 +++++++++++------ chapters/1_introduction.tex | 2 +- chapters/2_background.tex | 8 ++++---- chapters/5_incremental.tex | 8 ++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/assets/packages.tex b/assets/packages.tex index 8f47578..1c1fc48 100644 --- a/assets/packages.tex +++ b/assets/packages.tex @@ -128,7 +128,7 @@ \usepackage[many]{tcolorbox} \newtcolorbox{listingbox}[1][]{ - breakable, + % breakable, enhanced, arc=0pt, boxrule=0pt, @@ -155,11 +155,16 @@ \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}} \newenvironment{mzn}{\VerbatimEnvironment{}\begin{minted}[ autogobble=true, @@ -183,7 +188,7 @@ tabsize=2, ]{minizinc}}{\end{minted}} -\newcommand{\plainfile}[1]{\highlightfile{text}{#1}} +\newcommand{\plainfile}[2][n]{\highlightfile[#1]{text}{#2}} \newenvironment{plain}{\VerbatimEnvironment{}\begin{minted}[ autogobble=true, breaklines, @@ -194,7 +199,7 @@ tabsize=2, ]{text}}{\end{minted}} -\newcommand{\amplfile}[1]{\highlightfile{ampl}{#1}} +\newcommand{\amplfile}[2][n]{\highlightfile[#1]{ampl}{#2}} \newenvironment{ampl}{\VerbatimEnvironment{}\begin{minted}[ autogobble=true, breaklines, diff --git a/chapters/1_introduction.tex b/chapters/1_introduction.tex index 1d0043a..7d61402 100644 --- a/chapters/1_introduction.tex +++ b/chapters/1_introduction.tex @@ -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. \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.} \end{listing} diff --git a/chapters/2_background.tex b/chapters/2_background.tex index b299f6f..b3f686c 100644 --- a/chapters/2_background.tex +++ b/chapters/2_background.tex @@ -101,7 +101,7 @@ Its expressive language and extensive library of \glspl{global} allow users to e \end{example} \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.} \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}. \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}.} \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}. \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.} \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}. \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} \end{listing} diff --git a/chapters/5_incremental.tex b/chapters/5_incremental.tex index 8c56bcd..7b60ba5 100644 --- a/chapters/5_incremental.tex +++ b/chapters/5_incremental.tex @@ -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}). \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.} \end{listing} @@ -187,7 +187,7 @@ For adaptive \gls{lns}, a simple strategy is to change the size of the \gls{neig \begin{listing} \mznfile{assets/listing/inc_adaptive.mzn} - \caption{\label{lst:inc-adaptive} A simple adaptive neighbourhood.} + \caption{\label{lst:inc-adaptive}A simple adaptive neighbourhood.} \end{listing} \subsection{Optimization strategies} @@ -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. \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.} \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. \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} \\ \mzninline{basic_lns(uniformNeighbourhood(x,0.2))}.} \end{listing}