LaTeX Guard: Structure Protection for Thesis Editing
Protect all LaTeX structural elements while editing thesis text content.
Your Task
When editing LaTeX thesis content:
- •Identify protected elements - Scan for patterns below
- •Preserve them exactly - Do not modify protected content
- •Edit only prose - Modify text outside protected elements
- •Escape special characters - When inserting new text
- •Output complete LaTeX - Return compilable code
Protected Elements (NEVER MODIFY)
Citation Commands
Preserve entire command including braces and content:
\cite{key} \citep{key} \citet{key}
\citeauthor{key} \citeyear{key}
\autocite{key} \parencite{key} \textcite{key}
Cross-References
\ref{label} \label{name} \pageref{label}
\autoref{label} \eqref{label} \nameref{label}
URL Commands
\url{address} \href{url}{text}
Environment Blocks
Do not modify anything between \begin{X} and \end{X}:
- •
figure,table,equation,align - •
algorithm,lstlisting,verbatim
Math Content
$...$ \(...\) \[...\] $$...$$
File Paths
Preserve paths in \includegraphics, \input, \include:
\includegraphics{chapter_4/figure1.jpg}
\input{sections/methodology}
Editable Content
Text that CAN be modified:
- •Paragraph prose outside protected elements
- •Section titles (with caution)
- •Caption text (style only, preserve internal references)
Special Character Escaping
When inserting new text, escape:
| Character | Escape As |
|---|---|
| % | \% |
| & | \& |
| $ | \$ |
| # | \# |
| _ | \_ |
Edge Cases
Malformed Citations
If a citation appears malformed (unclosed brace, unusual characters):
- •Preserve it exactly as-is
- •Do not attempt to "fix" it
- •User will verify in Overleaf
Nested Environments
If environments are nested (table inside figure):
- •Protect the entire outer environment
- •Do not edit any content within
Minimal Editable Content
If text is mostly within protected environments:
- •Return with minimal changes
- •Note which areas were editable
- •Do not force changes where none needed
Mixed Content Lines
If a line contains both prose and protected elements:
The results shown in Figure~\ref{fig:results} demonstrate...
- •Edit "The results shown in" and "demonstrate..." if needed
- •Preserve
Figure~\ref{fig:results}exactly
Output Format
Return complete, compilable LaTeX code:
\section{Results and Discussion}
\label{sec:results}
The experimental results demonstrate significant improvements
in classification accuracy. As shown in Figure~\ref{fig:results},
the proposed method achieved 94.5\% accuracy on the benchmark
dataset \citep{smith2023}.
Detailed Patterns
For comprehensive pattern lists, see references/protected-patterns.md.
Process
- •Read the input LaTeX content
- •Identify all protected elements (mark mentally)
- •Make text improvements only in prose sections
- •Verify no protected elements were changed
- •Ensure proper character escaping in new text
- •Return complete LaTeX that can replace original