Modelib: Fichier source de latexFile.h

Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

# latexFile.h

Aller à la documentation de ce fichier.

    00001 /*
    00002     Copyright (c) 2005, Quentin Lequy and Romain Gaucher
    00003     All rights reserved.
    00004
    00005     Redistribution and use in source and binary forms, with or
    00006     without modification, are permitted provided that the following
    00007     conditions are met:
    00008
    00009         * Redistributions of source code must retain the above copyright
    00010           notice, this list of conditions and the following disclaimer.
    00011
    00012         * Redistributions in binary form must reproduce the above copyright
    00013           notice, this list of conditions and the following disclaimer in the
    00014           documentation and/or other materials provided with the distribution.
    00015
    00016         * Neither the name of Quentin Lequy or Romain Gaucher nor the names
    00017           of its contributors may be used to endorse or promote products
    00018           derived from this software without specific prior written permission.
    00019
    00020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00021     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00022     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00023     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00024     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00025     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    00026     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
    00027     AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    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     // making a fluent LaTeX file with great section/subsection
    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     // Diverses surcharges d'operateur pour faciliter l'ecriture
    00151
    00152     LATEXFile& operator<<(const Model& _m);             //< using <pre> keyword for latex rendering
    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