00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __LATEXFILE_H
00033 #define __LATEXFILE_H
00034
00035 #include "Model.h"
00036 #include <string>
00037 #include <fstream>
00038
00039 namespace Modelib {
00040
00046 class LATEXFile
00047 {
00048 std::string nom;
00049 std::string titre;
00050 std::ofstream latex;
00051
00052 bool beauty;
00053 bool openLater;
00054
00055
00056 bool isInSection;
00057 bool isInSubsection;
00058
00059 protected:
00060
00063 void BuildHeader()
00064 {
00065 latex << "% Les packages ci-dessous sont tous trouvables sur la ctan" << std::endl;
00066 latex << "\\documentclass[11pt,a4paper]{article}" << std::endl;
00067 latex << "\\usepackage[latin1]{inputenc}" << std::endl;
00068 latex << "\\usepackage [francais] {babel}" << std::endl;
00069 latex << "\\usepackage{color}" << std::endl;
00070 latex << "\\usepackage{listings}" << std::endl;
00071 latex << "%\\usepackage{fancyhdr}" << std::endl;
00072 latex << "%\\input{epsf}" << std::endl;
00073 latex << "\\usepackage{rawfonts}" << std::endl;
00074
00075 latex << "\\setlength{\\hoffset}{-18pt}" << std::endl;
00076 latex << "\\setlength{\\oddsidemargin}{0pt} % Marge gauche sur pages impaires" << std::endl;
00077 latex << "\\setlength{\\evensidemargin}{9pt} % Marge gauche sur pages paires" << std::endl;
00078 latex << "\\setlength{\\marginparwidth}{54pt} % Largeur de note dans la marge" << std::endl;
00079 latex << "\\setlength{\\textwidth}{481pt} % Largeur de la zone de texte (17cm)" << std::endl;
00080 latex << "\\setlength{\\voffset}{-18pt} % Bon pour DOS" << std::endl;
00081 latex << "\\setlength{\\marginparsep}{7pt} % Séparation de la marge" << std::endl;
00082 latex << "\\setlength{\\topmargin}{10pt} % Pas de marge en haut" << std::endl;
00083 latex << "\\setlength{\\headheight}{15pt} % Haut de page" << std::endl;
00084 latex << "\\setlength{\\headsep}{10pt} % Entre le haut de page et le texte" << std::endl;
00085 latex << "\\setlength{\\footskip}{27pt} % Bas de page + séparation" << std::endl;
00086 latex << "\\setlength{\\textheight}{708pt} % Hauteur de la zone de texte (25cm)" << std::endl;
00087 latex << "\\newlength{\\larg}" << std::endl;
00088 latex << "\\setlength{\\larg}{14cm}" << std::endl;
00089 latex << "\\title{" << titre << "}" << std::endl;
00090 latex << "\\begin{document}" << std::endl;
00091 latex << "\\maketitle" << std::endl;
00092 latex.flush();
00093 }
00094
00096 void BuildFooter()
00097 {
00098 latex << "\\end{document}" << std::endl;;
00099 latex.flush();
00100 }
00101
00103 LATEXFile() {};
00104
00105 public:
00106
00114 LATEXFile(const std::string& _nom, const std::string& _titre="Programme linéaire", bool _beauty=false, bool _openLater=false)
00115 : nom(_nom),titre(_titre), beauty(_beauty), openLater(_openLater)
00116 {
00117 isInSection = false;
00118 isInSubsection = false;
00119
00120 if (openLater==false)
00121 {
00122 latex.open(nom.c_str());
00123 if( !latex.is_open() )
00124 throw runtime_error("LATEXFile::LATEXFile() : I/O Erreur");
00125 BuildHeader();
00126 }
00127 }
00128
00130 ~LATEXFile() { latex.close(); }
00131
00133 void Open()
00134 {
00135 latex.open(nom.c_str());
00136 BuildHeader();
00137 latex.flush();
00138 }
00139
00141 void Close()
00142 {
00143 if (isInSubsection == true) latex << "\t\\end{subsection}" << std::endl;
00144 if (isInSection == true) latex << "\\end{section}" << std::endl;
00145 BuildFooter();
00146 latex.flush();
00147 latex.close();
00148 }
00149
00150
00151
00152 LATEXFile& operator<<(const Model& _m);
00153 LATEXFile& operator<<(const std::string& _s);
00154 LATEXFile& operator<<(const float _f);
00155 LATEXFile& operator<<(const char _c);
00156 LATEXFile& operator<<(const int _i);
00157
00159 void MakeSection(const std::string& _section)
00160 {
00161 if (isInSection == false)
00162 {
00163 latex << "\\begin{section}{" << _section << "}" << std::endl;
00164 isInSection = true;
00165 }
00166 else
00167 {
00168 isInSubsection = true;
00169 latex << "\t\\begin{subsection}{" << _section << "}" << std::endl;
00170 }
00171 }
00172
00174 void EndSection()
00175 {
00176 if (isInSubsection == true)
00177 {
00178 latex << "\t\\end{subsection}" << std::endl;
00179 isInSubsection = false;
00180 }
00181 else
00182 {
00183 latex << "\\end{section}" << std::endl;
00184 isInSection = false; isInSubsection = false;
00185 }
00186 }
00187
00189 void NewLine()
00190 {
00191 latex << std::endl << "\\newline" << std::endl;
00192 latex.flush();
00193 }
00194
00196 std::ostream & getStream() {return latex;}
00197
00198 };
00199
00200 }
00201
00202 #endif