Example #1
0
    def makeCatalogue(self):
        """Creates a pdf containing all exercises. Each exercise is always followed by its solution"""
        afile = "/tmp/catalogue.tex"
        self.__serie=0
        if os.path.isdir("Catalogue"):
            shutil.rmtree("Catalogue")
        os.mkdir("Catalogue")
        catalogue = open(afile, 'w') #use open(file 'a') for appending to a given file
        latex = LaTeX(self.__serie)
        latex.createHeader(catalogue, [])
        catalogue.write(r'\renewcommand{\exercice}[1]{\subsection*{Problem: #1}}'+"\n")
        catalogue.write(r'\renewcommand{\solution}[1]{\subsection*{Solution: #1}}'+"\n")
        catalogue.write(r'\renewcommand{\question}[1]{\subsubsection*{#1}}'+"\n")
        catalogue.write(r''+"\n")
        catalogue.write(r'\makeatletter'+"\n")
        catalogue.write(r'\renewcommand{\section}{\@startsection{section}{3}{2pt}{12pt}{10pt}{\center \huge \sffamily \bfseries}}'+"\n")
        catalogue.write(r'\renewcommand{\thesection}{(\roman{section})}'+"\n")
        catalogue.write(r'\renewcommand{\thesubsection}{(\roman{subsection})}'+"\n")
        exos = os.listdir(self.__exoDirName)
        #exos.sort()
        exos = Utils.natsort(exos)
        for exo in exos:
            if exo.find("ex") != -1:
                number = exo[2:]
                catalogue.write(r'\section*{Exercise '+number+'}'+"\n")
                catalogue.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exoDirName+'/ex'+number+'/latex/resources}'+'\n')
                exo = open(os.path.join(os.path.join(self.__exoDirName, "ex"+number),"latex/exo.tex"), 'r')
                for line in exo:
                    catalogue.write(line)
                exo.close()
                catalogue.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exoDirName+'/ex'+number+'/latex/resources}'+'\n')
                solution = open(os.path.join(os.path.join(self.__exoDirName, "ex"+number),"latex/exosol.tex"), 'r')
                for line in solution:
                    catalogue.write(line)
                solution.close()
                if self.__smscaddClearPage:
                    catalogue.write("\clearpage")


        latex.createFooter(catalogue)
        catalogue.close()
        outputDir = "Catalogue"
        Utils.doLatex(afile, outputDir, True)
        basename = os.path.split(afile)[1].split(".")[0]
        shutil.move(os.path.join(outputDir, basename+".pdf"), basename+".pdf")
        shutil.rmtree(outputDir)
Example #2
0
    def __doCreateSolution(self, _titles, _numbers, _outputDir, filename = None):
        filename = filename or "solution"+str(self.__serie)
        texfile = os.path.join("/tmp/", filename+".tex")
        solution = open(texfile, 'w')
        latex = LaTeX(self.__serie)
        latex.createHeader(solution, _titles, True)

        for number in _numbers:
            solution.write(r'\setcounter{section}{'+number+'}\n')
            solution.write(r'\addtocounter{section}{-1}'+'\n')
            solution.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exoDirName+'/ex'+number+'/latex/ressources}'+'\n')
            exo = open(self.__exoDirName+"/"+"ex"+number+"/latex/exosol.tex", 'r')
            for line in exo:
                solution.write(line)

        latex.createFooter(solution)
        solution.close()

        Utils.doLatex(texfile, _outputDir)
        return os.path.join(_outputDir, filename+".pdf")
Example #3
0
    def __doCreateSerie(self, _titles, _numbers, _outputDir, filename = None):
        filename = filename or "serie"+str(self.__serie)
        texfile = os.path.join("/tmp/", filename+".tex")
        serie = open(texfile, 'w') #use open(file 'a') for appending to a given file
        self.__smscsolutiontext = ''
        latex = LaTeX(self.__serie)
        latex.createHeader(serie, _titles)

        for number in _numbers:
            serie.write(r'\setcounter{section}{'+number+'}\n')
            serie.write(r'\addtocounter{section}{-1}'+'\n')
            serie.write(r'\renewcommand{\includepath}{\compilationpath/'+self.__exoDirName+'/ex'+number+'/latex/ressources}'+'\n')
            exo = open(self.__exoDirName+"/"+"ex"+number+"/latex/exo.tex", 'r')
            for line in exo:
                serie.write(line)

        latex.createFooter(serie)
        serie.close()

        Utils.doLatex(texfile, _outputDir)
        return os.path.join(_outputDir, filename+".pdf")
Example #4
0
 def __makeWorkBookTitlePage(self, _outputDir):
     texfile = "/tmp/0wbtitlepage.tex"
     wbtitle = open(texfile, 'w')
     latex = LaTeX(self.__serie)
     latex.makeWorkBookTitlePageHeader(wbtitle)
     seriesConfigFiles = os.listdir(self.__seriesConfigDir)
     #seriesConfigFiles.sort()
     seriesConfigFiles = Utils.natsort(seriesConfigFiles)
     for config in seriesConfigFiles:
         seriesConfig = ConfigParser.SafeConfigParser()
         seriesConfig.read(self.__seriesConfigDir+"/"+config)
         titles = seriesConfig.get('Serie', 'titles')
         numbers = seriesConfig.get('Serie', 'exo-numbers')
         serienumber = config.split(".")[0].partition("serie")[2]
         wbtitle.write(r"\textsf{ \textbf{S{\'e}rie "+serienumber+"}} \dotfill"+"\n")
         for number in numbers.split(","):
             wbtitle.write(number+"\n")
         wbtitle.write(r"\begin{itemize}"+"\n")
         for title in titles.split(","):
             wbtitle.write(r"\item "+title+"\n")
         wbtitle.write(r"\end{itemize}"+"\n")
     latex.printWorkBookTitlePageFooter(wbtitle)
     wbtitle.close()
     Utils.doLatex(texfile, _outputDir, True)