def insertSelectionInTemplate(fontSelectionList, fontTemplateFile, outputFile): for fontSelectionEntries in fontSelectionList: # create fontString for output filename for line in fontSelectionEntries: # search for \fontdesc and change its string, if necessary # Example: \renewcommand{\fontdesc}{Charter, Bera Sans, Luxi Mono} match = re.search(r"\\renewcommand{\\fontdesc}{(.+)}", line) if match: fontString = match.group(1) fontString = fontString.replace(', ', '-') fontString = fontString.replace(',', '-') # Open output file with changed font string # Insert all lines of fontSelectionEntries to the template positions outputFileChanged = outputFile + ' - ' + fontString + '.tex' print ('Creating font sample: ' + outputFileChanged) with open(fontTemplateFile, 'r') as parseFileHandle: with open(outputFileChanged, 'w') as outputFileHandle: for lineParse in parseFileHandle: # write line to output if lineParse.startswith('%%?'): # write all lines of fontSelectionEntries to outputFileHandle index = lineParse.find('<*preamblefontcode*>') if index >= 0: for fontline in fontSelectionEntries: outputFileHandle.write(fontline) # write all lines of fontSelectionEntries to outputFileHandle # except the line with 'fontdesc' index = lineParse.find('<*fontcode*>') if index >= 0: for fontline in fontSelectionEntries: index = fontline.find('fontdesc') if index < 0: outputFileHandle.write(fontline) else: outputFileHandle.write(lineParse) # get path and file of full file name newPath, filename = os.path.split(outputFileChanged) # compile file in folder of file oldPath = os.getcwd() os.chdir(newPath) tex.callSystemCommand(['pdflatex', '-interaction=nonstopmode', '-shell-escape', filename]) # executeCode = 'pdflatex.exe -interaction=nonstopmode -shell-escape "' \ # + filename + '"' # os.system(executeCode) # move pdf to different folder "fonts/" filenamepdf = filename.replace('.tex', '.pdf') if os.path.isfile(filenamepdf): shutil.move(filenamepdf, 'fonts/' + filenamepdf) else: print('file ' + filenamepdf + ' not found, aborting!') sys.exit() # remove all aux files tex.cleanupAuxFiles(filename.replace('.tex', '.')) tex.unfailingRemoveFile(filename) tex.unfailingRemoveFile(filename.replace('.tex', '.log')) # change to previous folder os.chdir(oldPath)
def createPackage(package, targetFolder): # change to base path of packages oldPath = os.getcwd() packagesPath = r'..\packages\publish' os.chdir(packagesPath) # string with target directory strTargetDir = targetFolder + "\\" + package # create folder tex.ensureDirectoryExists(strTargetDir) # copy .ins file to folder shutil.copy(package + '.ins', strTargetDir) # rewrite .dtx file in target folder exchangeInputByFile(package, targetFolder) # copy doctools.sty to target folder if it exists if package != 'doctools': doctoolsTargetFile = targetFolder + "\\doctools\\doctools.sty" if os.path.exists(doctoolsTargetFile): shutil.copy(doctoolsTargetFile, strTargetDir) # compile package packageFile = strTargetDir + "\\" + package + ".dtx" compileDTXPackage(packageFile) # remove doctools.sty if package != 'doctools': tex.unfailingRemoveFile(strTargetDir + "\\doctools.sty") # remove package.log tex.unfailingRemoveFile(strTargetDir + "\\" + package + '.log') # remove package.sty # tex.unfailingRemoveFile(strTargetDir + "\\" + package + '.sty') # remove any .tex file tex.unfailingRemoveFile(strTargetDir + "\\" + '*.tex') # copy README readmeOriginFile = package + ".README.txt" readmeTargetFile = strTargetDir + "\\README" if os.path.exists(readmeOriginFile): shutil.copy(readmeOriginFile, readmeTargetFile) print ('copying README file') # zip package folder os.chdir(targetFolder) filename = package + '.zip' executeCode = 'zip -x *.sty -r ' + filename + ' ' + package + '/*' print (executeCode) result = os.system(executeCode) # change folder back to origin os.chdir(oldPath)
def createPackage(package, targetFolder): # change to base path of packages oldPath = os.getcwd() packagesPath = r'..\packages\publish' os.chdir(packagesPath) # string with target directory strTargetDir = targetFolder + "\\" + package # create folder tex.ensureDirectoryExists(strTargetDir) # copy .ins file to folder shutil.copy(package + '.ins', strTargetDir) # rewrite .dtx file in target folder exchangeInputByFile(package, targetFolder) # copy doctools.sty to target folder if it exists if package != 'doctools': doctoolsTargetFile = targetFolder + "\\doctools\\doctools.sty" if os.path.exists(doctoolsTargetFile): shutil.copy(doctoolsTargetFile, strTargetDir) # compile package packageFile = strTargetDir + "\\" + package + ".dtx" compileDTXPackage(packageFile) # remove doctools.sty if package != 'doctools': tex.unfailingRemoveFile(strTargetDir + "\\doctools.sty") # remove package.log tex.unfailingRemoveFile(strTargetDir + "\\" + package + '.log') # remove package.sty # tex.unfailingRemoveFile(strTargetDir + "\\" + package + '.sty') # remove any .tex file tex.unfailingRemoveFile(strTargetDir + "\\" + '*.tex') # copy README readmeOriginFile = package + ".README.txt" readmeTargetFile = strTargetDir + "\\README" if os.path.exists(readmeOriginFile): shutil.copy(readmeOriginFile, readmeTargetFile) print('copying README file') # zip package folder os.chdir(targetFolder) filename = package + '.zip' executeCode = 'zip -x *.sty -r ' + filename + ' ' + package + '/*' print(executeCode) result = os.system(executeCode) # change folder back to origin os.chdir(oldPath)
def main(): print("--- clean up main folder before compilation ---") tex.unfailingRemoveFile('../template/TemplateDocumentation-figure*.log') tex.cleanupRecursiveAuxFiles('../template/', '*.aux') texfile = '../template/LaTeXTemplate.' tex.cleanupAuxFiles(texfile) texfile = '../template/TemplateDocumentation.' tex.cleanupAuxFiles(texfile) # print ("--- Creation of Packages ---") # importCreatePackages.main() # print ("--- Copy Packages ---") # copyPackages() print("--- Create Font Examaples ---") # importFontExamples.main() print("--- fill doc-code.tex ---") # importInsertPrintCode.main() print("--- compiling LaTeXTemplate.tex ---") texfile = '../template/LaTeXTemplate.tex' tex.compileLatexDocument(texfile) copyTeXFile(texfile) print("--- compiling TemplateDocumentation.tex ---") texfile = '../template/TemplateDocumentation.tex' tex.compileLatexDocument(texfile) copyFile(texfile.replace('.tex', '.pdf'), '') tex.cleanupRecursiveAuxFiles('../template/', '*.aux') tex.unfailingRemoveFile('../template/content/demo/democode.tex') tex.unfailingRemoveFile('../template/content/longtable.tex') tex.unfailingRemoveFile('../template/demo-glossaries-*') copyFile('bib/BibtexDatabase.bib', 'bib') copyFile('bib/publications.bib', 'bib') copyFile('content/template/latextutorial.tex', 'content/template/') copyFile('content/*.tex', 'content') copyFile('fonts/*.tex', 'fonts') copyFile('images/*', 'images') copyFile('macros/*', 'macros') copyFile('preamble/commands.tex', 'preamble') copyFile('preamble/makeCommands.tex', 'preamble') copyFile('preamble/fix*.tex', 'preamble') copyFile('preamble/listings*.tex', 'preamble') copyFile('preamble/packages*.tex', 'preamble') copyFile('preamble/style*.tex', 'preamble') copyFile('version.txt', '') copyFile('licence.txt', '') # copyFile('*.sty', '') # zip publish folder oldPath = os.getcwd() os.chdir('../template/') currentDateStr = datetime.datetime.now().strftime("%Y-%m-%d") filename = 'latexthesistemplate-' + currentDateStr + '.zip' executeCode = 'zip -r ' + filename + ' latexthesistemplate/*' print(executeCode) result = os.system(executeCode) os.chdir(oldPath)
def main(): print ("--- clean up main folder before compilation ---") tex.unfailingRemoveFile('../template/TemplateDocumentation-figure*.log') tex.cleanupRecursiveAuxFiles('../template/', '*.aux') texfile = '../template/LaTeXTemplate.' tex.cleanupAuxFiles(texfile) texfile = '../template/TemplateDocumentation.' tex.cleanupAuxFiles(texfile) # sys.exit() print ("--- Creation of Packages ---") # importCreatePackages.main() print ("--- Copy Packages ---") # copyPackages() print ("--- Create Font Examaples ---") # importFontExamples.main() print ("--- fill doc-code.tex ---") importInsertPrintCode.main() print ("--- compiling LaTeXTemplate.tex ---") texfile = '../template/LaTeXTemplate.tex' tex.compileLatexDocument(texfile) copyTeXFile(texfile) print ("--- compiling TemplateDocumentation.tex ---") texfile = '../template/TemplateDocumentation.tex' tex.compileLatexDocument(texfile) copyFile(texfile.replace('.tex', '.pdf'), '') tex.cleanupRecursiveAuxFiles('../template/', '*.aux') tex.unfailingRemoveFile('../template/content/demo/democode.tex') tex.unfailingRemoveFile('../template/content/longtable.tex') tex.unfailingRemoveFile('../template/demo-glossaries-*') copyFile('bib/BibtexDatabase.bib', 'bib') copyFile('bib/publications.bib', 'bib') copyFile('content/template/latextutorial.tex', 'content/template/') copyFile('content/*.tex', 'content') copyFile('fonts/*.tex', 'fonts') copyFile('images/*', 'images') copyFile('macros/*', 'macros') copyFile('preamble/commands.tex', 'preamble') copyFile('preamble/makeCommands.tex', 'preamble') copyFile('preamble/fix*.tex', 'preamble') copyFile('preamble/listings*.tex', 'preamble') copyFile('preamble/packages*.tex', 'preamble') copyFile('preamble/style*.tex', 'preamble') copyFile('version.txt', '') copyFile('licence.txt', '') # copyFile('*.sty', '') # zip publish folder oldPath = os.getcwd() os.chdir('../template/') currentDateStr = datetime.datetime.now().strftime("%Y-%m-%d") filename = 'latexthesistemplate-' + currentDateStr + '.zip' executeCode = 'zip -r ' + filename + ' latexthesistemplate/*' print (executeCode) result = os.system(executeCode) os.chdir(oldPath)
def insertSelectionInTemplate(fontSelectionList, fontTemplateFile, outputFile): for fontSelectionEntries in fontSelectionList: # create fontString for output filename for line in fontSelectionEntries: # search for \fontdesc and change its string, if necessary # Example: \renewcommand{\fontdesc}{Charter, Bera Sans, Luxi Mono} match = re.search(r"\\renewcommand{\\fontdesc}{(.+)}", line) if match: fontString = match.group(1) fontString = fontString.replace(', ', '-') fontString = fontString.replace(',', '-') # Open output file with changed font string # Insert all lines of fontSelectionEntries to the template positions outputFileChanged = outputFile + ' - ' + fontString + '.tex' print('Creating font sample: ' + outputFileChanged) with open(fontTemplateFile, 'r') as parseFileHandle: with open(outputFileChanged, 'w') as outputFileHandle: for lineParse in parseFileHandle: # write line to output if lineParse.startswith('%%?'): # write all lines of fontSelectionEntries to outputFileHandle index = lineParse.find('<*preamblefontcode*>') if index >= 0: for fontline in fontSelectionEntries: outputFileHandle.write(fontline) # write all lines of fontSelectionEntries to outputFileHandle # except the line with 'fontdesc' index = lineParse.find('<*fontcode*>') if index >= 0: for fontline in fontSelectionEntries: index = fontline.find('fontdesc') if index < 0: outputFileHandle.write(fontline) else: outputFileHandle.write(lineParse) # get path and file of full file name newPath, filename = os.path.split(outputFileChanged) # compile file in folder of file oldPath = os.getcwd() os.chdir(newPath) tex.callSystemCommand([ 'pdflatex', '-interaction=nonstopmode', '-shell-escape', filename ]) # executeCode = 'pdflatex.exe -interaction=nonstopmode -shell-escape "' \ # + filename + '"' # os.system(executeCode) # move pdf to different folder "fonts/" filenamepdf = filename.replace('.tex', '.pdf') if os.path.isfile(filenamepdf): shutil.move(filenamepdf, 'fonts/' + filenamepdf) else: print('file ' + filenamepdf + ' not found, aborting!') sys.exit() # remove all aux files tex.cleanupAuxFiles(filename.replace('.tex', '.')) tex.unfailingRemoveFile(filename) tex.unfailingRemoveFile(filename.replace('.tex', '.log')) # change to previous folder os.chdir(oldPath)