#!/usr/bin/env python """ This python script takes one argument as number of directories(for the corresponing chapters). Execution (example for 4 dirs): python3 setup.py 4 It also creates a main tex file called thesis.tex with some basic setup defined below. date: 12.04.2023 author: Tamasi Kar """ ############################## # IMPORTS ############################## import os, sys import subprocess as sub ############################## NDirs = int(sys.argv[1]) PWD = os.getcwd() MainFile = PWD + "/thesis.tex" sub.run(["touch",MainFile]) HeaderFile= PWD + "/etc/header.tex" if not (os.path.exists(PWD + "/etc")): sub.run(["mkdir", PWD + "/etc"]) sub.run(["touch", HeaderFile]) if not (os.path.exists(PWD + "/images")): sub.run(["mkdir", PWD + "/images"]) FileList = [] DirList = [] for i in range(NDirs): DirName = PWD + "/chapter" + str(i+1) FileName = DirName + "/chapter" + str(i+1) +".tex" FileList.append(os.path.splitext(os.path.basename(FileName))[0]) DirList.append(os.path.basename(DirName)) if not (os.path.exists(DirName)): sub.run(["mkdir", DirName]) sub.run(["touch", FileName]) with open(FileName, "w") as f: f.write("\\chapter["+ DirList[i]+"]{"+DirList[i]+"}\n") f.write("\\label{chap:"+DirList[i]+"}\n") #print(FileName) with open(HeaderFile, "w") as hfile: hfile.write("\\documentclass[fontsize=12pt, twoside, headings=big, open=right]{scrreprt}\n") hfile.write('%%%%%%%%%% PACKAGES %%%%%%%%%%%%%\n') hfile.write("\\usepackage{blindtext}\n") hfile.write("\\usepackage{graphicx}\n") hfile.write("\\graphicspath{{images/}} % setting graphics path\n") hfile.write("\\usepackage{subfig}\n") hfile.write("\\usepackage{enumitem}\n") hfile.write("%\\usepackage[top=2cm, bottom=3cm, inner=1cm, outer=1.5cm]{geometry}\n") hfile.write("\\usepackage[protrusion=true,expansion=true]{microtype}\n") hfile.write("\\usepackage{amsmath}\n") hfile.write("\\usepackage[per-mode=symbol,exponent-product = \cdot]{siunitx}\n") hfile.write("%\\sisetup{locale=DE}\n") hfile.write("\\usepackage[colorlinks = true,linkcolor = green,\n") hfile.write("urlcolor = blue,\n") hfile.write("citecolor = red,\n") hfile.write("anchorcolor = green]{hyperref}\n") hfile.write("\\usepackage{scrlayer-scrpage}\n") hfile.write("\\pagestyle{scrheadings}\n") hfile.write("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n") with open(MainFile, "w") as file: file.write("% !TeX root = " + os.path.basename(MainFile) + "\n") file.write("\\input{etc/"+os.path.splitext(os.path.basename(HeaderFile))[0]+"}\n") file.write('%%%%%%%%%% DEFINITIONS %%%%%%%%%%\n') file.write("\\newcommand*{\\Dif}{\\mathop{}\\!\\mathrm{d}}\n") file.write("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n") file.write("%%%%%%%%% FRONTMATTER %%%%%%%%%%\n") file.write("\\author{Tamasi Kar}\n") file.write("\\title{My \\LaTeX Document}\n") file.write("\\subtitle{\\LaTeX Basics}\n") file.write("\\date{\\today} %\\date{14 April, 2023}\n") file.write("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n") file.write("\\begin{document}\n") file.write("\\maketitle\n") file.write("\\setcounter{tocdepth}{3} % display depth in toc\n") file.write("\\setcounter{secnumdepth}{3} % sub-sub section is now numbered (is not by default)\n") file.write("{\\hypersetup{hidelinks} \\tableofcontents} % displays the toc\n") file.write("\\thispagestyle{empty} % toc page set to style empty\n") file.write("\\setcounter{page}{0} % reset pagenumber to 0 for the toc page\n") file.write("\\setpartpreamble{\n") file.write("\\begin{center}\n") file.write("You can add a preamble to this part here..\n") file.write("\\end{center}}\n") file.write("\\part{Introduction}\n") for f in range(len(FileList)): file.write("\\include{" +DirList[f] + "/" + FileList[f] + "}\n") file.write("\\end{document}\n") print("done")