Modelib: latexFile.h Source File

Page principale | Hiérarchie des classes | Liste des composants | Liste des fichiers | Composants

# latexFile.h

    00001 #ifndef __LATEXFILE_H
    00002 #define __LATEXFILE_H
    00003
    00004 #include "Model.h"
    00005 #include <string>
    00006 #include <fstream>
    00007
    00013 class LATEXFile
    00014 {
    00015         std::string      nom;
    00016         std::string    titre;
    00017         std::ofstream  latex;
    00018
    00019         bool          beauty;
    00020         bool       openLater;
    00021
    00022         // making a fluent LaTeX file with great section/subsection
    00023         bool     isInSection;
    00024         bool  isInSubsection;
    00025
    00026         protected:
    00027
    00030         void BuildHeader()
    00031         {
    00032           latex << "% Les packages ci-dessous sont tous trouvables sur la ctan" << std::endl;
    00033           latex << "\\documentclass[11pt,a4paper]{article}" << std::endl;
    00034       latex << "\\usepackage[latin1]{inputenc}" << std::endl;
    00035       latex << "\\usepackage [francais] {babel}" << std::endl;
    00036       latex << "\\usepackage{color}" << std::endl;
    00037       latex << "\\usepackage{listings}" << std::endl;
    00038       latex << "%\\usepackage{fancyhdr}" << std::endl;
    00039       latex << "%\\input{epsf}" << std::endl;
    00040       latex << "\\usepackage{rawfonts}" << std::endl;
    00041
    00042       latex << "\\setlength{\\hoffset}{-18pt}" << std::endl;
    00043       latex << "\\setlength{\\oddsidemargin}{0pt}     % Marge gauche sur pages impaires" << std::endl;
    00044       latex << "\\setlength{\\evensidemargin}{9pt}    % Marge gauche sur pages paires" << std::endl;
    00045       latex << "\\setlength{\\marginparwidth}{54pt}   % Largeur de note dans la marge" << std::endl;
    00046       latex << "\\setlength{\\textwidth}{481pt}   % Largeur de la zone de texte (17cm)" << std::endl;
    00047       latex << "\\setlength{\\voffset}{-18pt}     % Bon pour DOS" << std::endl;
    00048       latex << "\\setlength{\\marginparsep}{7pt}  % Séparation de la marge" << std::endl;
    00049       latex << "\\setlength{\\topmargin}{10pt}     % Pas de marge en haut" << std::endl;
    00050       latex << "\\setlength{\\headheight}{15pt}   % Haut de page" << std::endl;
    00051       latex << "\\setlength{\\headsep}{10pt}  % Entre le haut de page et le texte" << std::endl;
    00052       latex << "\\setlength{\\footskip}{27pt}     % Bas de page + séparation" << std::endl;
    00053       latex << "\\setlength{\\textheight}{708pt}  % Hauteur de la zone de texte (25cm)" << std::endl;
    00054       latex << "\\newlength{\\larg}" << std::endl;
    00055       latex << "\\setlength{\\larg}{14cm}" << std::endl;
    00056       latex << "\\title{" << titre << "}" << std::endl;
    00057       latex << "\\begin{document}" << std::endl;
    00058       latex << "\\maketitle" << std::endl;
    00059       latex.flush();
    00060         }
    00061
    00063         void BuildFooter()
    00064         {
    00065                 latex << "\\end{document}" << std::endl;;
    00066                 latex.flush();
    00067         }
    00068
    00070         LATEXFile() {};
    00071
    00072         public:
    00073
    00081         LATEXFile(const std::string& _nom, const std::string& _titre="Programme linéaire", bool _beauty=false, bool _openLater=false)
    00082          : nom(_nom),titre(_titre), beauty(_beauty), openLater(_openLater)
    00083         {
    00084                 isInSection    = false;
    00085                 isInSubsection = false;
    00086
    00087                 if (openLater==false)
    00088                 {
    00089                         latex.open(nom.c_str());
    00090                         if( !latex.is_open() )
    00091                          throw runtime_error("LATEXFile::LATEXFile() : I/O Erreur");
    00092                         BuildHeader();
    00093                 }
    00094         }
    00095
    00097         ~LATEXFile() { latex.close(); }
    00098
    00100         void Open()
    00101         {
    00102                 latex.open(nom.c_str());
    00103                 BuildHeader();
    00104                 latex.flush();
    00105         }
    00106
    00108         void Close()
    00109         {
    00110                 if (isInSubsection == true) latex << "\t\\end{subsection}" << std::endl;
    00111                 if (isInSection    == true) latex << "\\end{section}" << std::endl;
    00112                 BuildFooter();
    00113                 latex.flush();
    00114                 latex.close();
    00115         }
    00116
    00117         // Diverses surcharges d'operateur pour faciliter l'ecriture
    00118
    00119         LATEXFile& operator<<(const Model& _m);                         //< using <pre> keyword for latex rendering
    00120         LATEXFile& operator<<(const std::string& _s);
    00121         LATEXFile& operator<<(const float _f);
    00122         LATEXFile& operator<<(const char  _c);
    00123         LATEXFile& operator<<(const int   _i);
    00124
    00126     void MakeSection(const std::string& _section)
    00127     {
    00128       if (isInSection == false)
    00129       {
    00130         latex << "\\begin{section}{" << _section << "}" << std::endl;
    00131         isInSection = true;
    00132       }
    00133       else
    00134       {
    00135         isInSubsection = true;
    00136         latex << "\t\\begin{subsection}{" << _section << "}" << std::endl;
    00137       }
    00138     }
    00139
    00141     void EndSection()
    00142     {
    00143       if (isInSubsection == true)
    00144       {
    00145         latex << "\t\\end{subsection}" << std::endl;
    00146         isInSubsection = false;
    00147       }
    00148       else
    00149       {
    00150         latex << "\\end{section}" << std::endl;
    00151         isInSection = false; isInSubsection = false;
    00152       }
    00153     }
    00154
    00156         void NewLine()
    00157         {
    00158                 latex << std::endl << "\\newline" << std::endl;
    00159                 latex.flush();
    00160         }
    00161
    00163     std::ostream & getStream() {return latex;}
    00164
    00165 };
    00166
    00167 #endif