How to include source code into your dissertation

Abstract: Solves formatting and referencing source code in dissertations using LaTeX listings or Word features for academic clarity.

Created: 2026-10-23 by
Including source code in your dissertation requires balancing technical accuracy with academic readability. You should use LaTeX listings or Word’s built-in formatting to ensure consistent syntax highlighting and proper referencing. This approach allows examiners to review your logic without being distracted by poor presentation, ensuring the code serves as evidence for your methodology rather than cluttering the narrative.

Choosing the Right Tool

The method you choose depends heavily on the document preparation system your university mandates. Most computer science and engineering dissertations are written in LaTeX because it handles large blocks of code more elegantly than word processors. If you are using Overleaf or a local TeX distribution, the listings or minted packages are standard. These tools allow you to define styles for various programming languages, controlling font size, background colors, and line numbers automatically. For those using Microsoft Word, manual formatting is often insufficient for long scripts. Instead, utilize the built-in "Insert > Object" feature or copy-paste from an IDE like Visual Studio Code while preserving rich text formatting. However, be cautious; rich text can break when moving between sections. A safer alternative in Word is to use a monospaced font like Consolas or Courier New, indented with a hanging indent style. This creates a visual distinction from the main body text without requiring complex plugin installations.

Structuring Your Code Listings

Academic writing demands that every piece of evidence be referenced. When you include a block of code, it must have a caption and a reference number, just like a figure or table. In LaTeX, wrapping your code in a listing environment allows you to use \caption{} and \label{}. This ensures that cross-references in your text, such as "as shown in Listing 3.1," resolve correctly during compilation. In Word, treat code blocks as figures. Go to the References tab and select "Insert Caption." Choose "Figure" as the label, but change the text to describe the code snippet. This integrates the code into your table of figures, making navigation easier for readers who want to jump directly to specific implementations. Ensure that the caption explains what the code does, not just its filename. For example, instead of "Listing: main.py," write "Listing: The main entry point handling user authentication."

Selecting Relevant Snippets

A common mistake students make is pasting entire files into their dissertation. Examiners rarely read every line of code. Instead, include only the critical algorithms, unique functions, or complex data structures that demonstrate your contribution. If a function is standard boilerplate, refer to the appendix or provide a link to a public repository if allowed by your institution. Break down large files into logical chunks. If you have a 500-line script, extract the core logic into the main body and move the supporting utilities to an appendix. Use ellipses (...) within the code block to indicate omitted lines, but ensure the surrounding context remains clear. This technique keeps the reader focused on the novel aspects of your work. Remember that clarity trumps completeness; the goal is to prove your method works, not to archive your entire project history.

Formatting for Readability

Readability is paramount. Code in a dissertation is often printed in black and white, so relying solely on color coding for syntax highlighting is risky. Use line numbers extensively; they help examiners locate specific parts of the code when discussing errors or optimizations. Keep the font size small enough to fit the block on one page but large enough to be legible. A 9pt or 10pt monospaced font is typically appropriate. Avoid horizontal scrolling. If a line of code is too long, wrap it manually at a logical breakpoint, such as after a comma or operator. In LaTeX, the listings package has a breaklines=true option that handles this automatically. In Word, ensure your paragraph settings do not force single-line breaks that push code onto new pages awkwardly. Consistent indentation is also crucial; maintain four-space or two-space indentation throughout all snippets to preserve the structure of nested loops and conditionals.

Referencing External Repositories

Modern dissertations often accompany a GitHub or GitLab repository. You should explicitly mention this in your introduction or methodology chapter. Provide a persistent URL, such as a DOI or a tagged release link, to ensure reproducibility. Do not rely on dynamic links that may change over time. When referring to the repository, clarify which version corresponds to the dissertation. If you update the code after submission, the examiner might not find the exact same implementation. Tagging your repository with the submission date or a specific version number mitigates this risk. This practice aligns with open science principles and adds credibility to your work, showing that your results are verifiable.

Common Pitfalls to Avoid

One frequent error is failing to compile the code before inclusion. Always verify that the snippets you paste actually run. Typos in included code can undermine your authority, suggesting carelessness in your research process. Additionally, avoid including proprietary or sensitive information. If your code contains API keys, passwords, or personal data, remove them before publication. Use placeholder variables like YOUR_API_KEY and explain how they were configured in your development environment. Another pitfall is inconsistent naming conventions. Ensure that variable names in your code match those described in your text. If you discuss "the learning rate parameter" in prose, the code should ideally use learning_rate or similar, rather than an obscure abbreviation like lr. This consistency reduces cognitive load for the reader, allowing them to connect your theoretical explanation with the practical implementation seamlessly.

Frequently Asked Questions

Can I include my entire source code file?

No, you should never include entire files unless they are extremely short. Examiners expect concise, relevant snippets that demonstrate your specific contributions. Long files distract from your analysis and waste valuable page space.

How do I handle code that exceeds one page?

In LaTeX, enable line breaking options to allow continuous flow across pages. In Word, split the code into multiple logical sections, each with its own caption. Never let a code block split awkwardly between paragraphs without context.

Is it necessary to highlight syntax colors?

Syntax highlighting aids readability but is not strictly mandatory if printed in black and white. Rely on line numbers and clear variable names to compensate for the lack of color differentiation in print formats.

Should I put all code in an appendix?

Critical code that supports your main arguments belongs in the body. Boilerplate, utility functions, or extensive configuration scripts are better suited for appendices. This keeps the main narrative focused on your unique methodology.

How do I reference code in my bibliography?

Treat code repositories similarly to software documentation. Include the author, title, version, URL, and access date. Use citation styles like APA or IEEE, which have specific guidelines for citing digital objects and software sources.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More