From 98070acac0309f3e27746fdc17d909df17c21d93 Mon Sep 17 00:00:00 2001 From: Daniel Rosel Date: Thu, 23 Oct 2025 10:42:21 +0200 Subject: [PATCH] concat of code --- Makefile | 2 ++ paper/concat_code.sh | 76 ++++++++++++++++++++++++++++++++++++++++++ paper/src/main.tex | 4 +++ paper/src/preamble.tex | 16 +++++++++ 4 files changed, 98 insertions(+) create mode 100755 paper/concat_code.sh diff --git a/Makefile b/Makefile index 8ae2461..6f5779a 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ $(BUILDDIR): mkdir -p paper/$(BUILDDIR) pdf: $(BUILDDIR) + @echo "Concatenating source code..." + @bash paper/concat_code.sh @cd $(SRCDIR) && \ $(LATEXMK) -pdf -jobname=$(JOBNAME) \ -interaction=nonstopmode -file-line-error \ diff --git a/paper/concat_code.sh b/paper/concat_code.sh new file mode 100755 index 0000000..5890c91 --- /dev/null +++ b/paper/concat_code.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# Script to concatenate all code from source directories for LaTeX inclusion + +OUTPUT_FILE="paper/build/concatenated_code.tex" +PROJECT_ROOT="/home/velocitatem/Documents/Projects/PHANTOM" + +# Create output directory if it doesn't exist +mkdir -p "$(dirname "$OUTPUT_FILE")" + +# Clear the output file +> "$OUTPUT_FILE" + +# Function to add a file to the concatenated output +add_file() { + local filepath="$1" + local relpath="${filepath#$PROJECT_ROOT/}" + + # Get file extension + local ext="${filepath##*.}" + + # Map extensions to listings language + case "$ext" in + py) lang="Python" ;; + js|jsx|ts|tsx) lang="JavaScript" ;; + sh) lang="bash" ;; + yml|yaml) lang="Python" ;; + Dockerfile) lang="bash" ;; + *) lang="" ;; + esac + + # Add section header and code listing + echo "\\subsection{${relpath}}" >> "$OUTPUT_FILE" + if [ -n "$lang" ]; then + echo "\\begin{lstlisting}[language=${lang},caption={${relpath}}]" >> "$OUTPUT_FILE" + else + echo "\\begin{lstlisting}[caption={${relpath}}]" >> "$OUTPUT_FILE" + fi + cat "$filepath" >> "$OUTPUT_FILE" + echo "" >> "$OUTPUT_FILE" + echo "\\end{lstlisting}" >> "$OUTPUT_FILE" + echo "" >> "$OUTPUT_FILE" +} + +# Add header +cat >> "$OUTPUT_FILE" << 'EOF' +% Auto-generated code concatenation +% DO NOT EDIT MANUALLY - Generated by concat_code.sh + +\section{Source Code} + +EOF + +# Process each directory +echo "Concatenating code from source directories..." + +# Backend +find "$PROJECT_ROOT/backend" -type f \( -name "*.py" -o -name "*.js" -o -name "*.sh" -o -name "*.yml" -o -name "*.yaml" \) | sort | while read -r file; do + add_file "$file" +done + +# Experiments +find "$PROJECT_ROOT/experiments" -type f \( -name "*.py" -o -name "*.js" -o -name "*.sh" -o -name "*.yml" -o -name "*.yaml" \) | sort | while read -r file; do + add_file "$file" +done + +# Docker +find "$PROJECT_ROOT/docker" -type f \( -name "*.py" -o -name "*.sh" -o -name "*.yml" -o -name "*.yaml" -o -name "Dockerfile*" \) | sort | while read -r file; do + add_file "$file" +done + +# Web/src +find "$PROJECT_ROOT/web/src" -type f \( -name "*.js" -o -name "*.jsx" -o -name "*.ts" -o -name "*.tsx" \) | sort | while read -r file; do + add_file "$file" +done + +echo "Code concatenation complete: $OUTPUT_FILE" diff --git a/paper/src/main.tex b/paper/src/main.tex index 8ad64df..0f787b1 100644 --- a/paper/src/main.tex +++ b/paper/src/main.tex @@ -37,4 +37,8 @@ The primary objective of this thesis is to develop and validate pricing heuristi \input{chapters/01-intro} \printbibliography + +\appendix +\input{../build/concatenated_code} + \end{document} diff --git a/paper/src/preamble.tex b/paper/src/preamble.tex index 24127cf..31f3639 100644 --- a/paper/src/preamble.tex +++ b/paper/src/preamble.tex @@ -5,6 +5,22 @@ \usepackage{subcaption} \usepackage{siunitx} +\usepackage{listings} +\usepackage{xcolor} + +\lstset{ + basicstyle=\ttfamily\footnotesize, + breaklines=true, + frame=single, + numbers=left, + numberstyle=\tiny\color{gray}, + keywordstyle=\color{blue}, + commentstyle=\color{green!60!black}, + stringstyle=\color{red}, + showstringspaces=false, + captionpos=b +} + % Use biblatex instead of natbib (acmart default) \usepackage[backend=bibtex,style=numeric]{biblatex} \addbibresource{bib/references.bib}