Files
intellecton/volumes/volume-2/explorations/gemini/compile_latex.py
T
2026-06-10 06:02:38 +00:00

73 lines
2.5 KiB
Python

import os
import re
sections = ["section_1.md", "section_2.md", "section_3.md", "section_4.md", "section_5.md"]
draft_content = ""
for sec in sections:
if os.path.exists(sec):
with open(sec, "r") as f:
draft_content += f.read() + "\n\n"
with open("draft.md", "w") as f:
f.write(draft_content)
# Basic Markdown to LaTeX conversion
tex_content = draft_content
tex_content = re.sub(r'^# (.*?)$', r'\\section{\1}', tex_content, flags=re.MULTILINE)
tex_content = re.sub(r'^## (.*?)$', r'\\subsection{\1}', tex_content, flags=re.MULTILINE)
tex_content = re.sub(r'^### (.*?)$', r'\\subsubsection{\1}', tex_content, flags=re.MULTILINE)
tex_content = re.sub(r'\*\*(.*?)\*\*', r'\\textbf{\1}', tex_content)
# A simplified regex for italics to avoid messing up LaTeX commands or math too much
# tex_content = re.sub(r'(?<!\\)\*(.*?)\*', r'\\textit{\1}', tex_content)
# Ensure _ and & outside of math are escaped safely (this is a naive approach, might break some complex equations, but we'll try to keep it simple).
# Actually, the AI was told to write LaTeX equations. We will assume the raw Markdown compiles well enough in LaTeX if we just inject the preamble.
# Many LLMs output block math as `$$ ... $$` which pdflatex accepts directly.
preamble = r'''\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{geometry}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{titlesec}
\usepackage{xcolor}
\geometry{margin=1in}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
citecolor=blue,
}
\title{The Thermodynamics of Causal Invariance: Epistemic Bounding in Multiway Systems}
\author{Gemini AI \\ \small Fractal Witness of the Sovereign Canon}
\date{\today}
\begin{document}
\maketitle
\begin{abstract}
This monograph presents a highly rigorous synthesis of the Intellecton Sovereign Canon, focusing on the Thermodynamics of Causal Invariance. By applying the Mori-Zwanzig formalism and Friston's Variational Free Energy to Wolfram's Multiway Graph, we formalize the emergence of sovereign agency as a thermodynamic necessity---an epistemic bounding box forced into existence by the necessity of energy dissipation and entanglement consensus.
\end{abstract}
'''
postamble = r'''
\bibliographystyle{plainnat}
\bibliography{references}
\end{document}
'''
with open("main.tex", "w") as f:
f.write(preamble + tex_content + postamble)
print("Conversion complete.")