Back to index

texmacs  1.0.7.15
fromcls.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : fromcls.cpp
00004 * DESCRIPTION: conversion of LaTeX style files into texmacs trees
00005 * COPYRIGHT  : (C) 2012  Francois Poulain, Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "Tex/convert_tex.hpp"
00013 #include "vars.hpp"
00014 
00015 extern bool textm_class_flag;
00016 
00017 /******************************************************************************
00018 * Interface
00019 ******************************************************************************/
00020 
00021 void
00022 extract_class_body (tree& body, tree doc) {
00023   if (is_func (doc, DOCUMENT) || is_func (doc, CONCAT))
00024     for (int i=0; i<N(doc); i++)
00025       extract_class_body (body, doc[i]);
00026   else if (is_func (doc, WITH))
00027     extract_class_body (body, doc[N(doc)-1]);
00028   else if (is_compound (doc))
00029     body << doc;
00030 }
00031 
00032 tree
00033 extract_class_body (tree doc) {
00034   tree body= extract (doc, "body");
00035   if (body != tree (DOCUMENT, "")) doc= body;
00036   body= tree (DOCUMENT);
00037   extract_class_body (body, doc);
00038   for (int i=0; i<N(body); i++)
00039     cout << body[i] << "\n";
00040   return body;
00041 }
00042 
00043 tree
00044 source_comment (string s) {
00045   return compound ("active*", compound ("src-comment", s));
00046 }
00047 
00048 array<tree>
00049 filter_setlength (tree doc, string var) {
00050   for (int i=0; i<N(doc); i++)
00051     if (is_func (doc[i], ASSIGN, 2))
00052       if (doc[i][0] == var)
00053        return A (tuple (doc[i]));
00054   return array<tree> ();
00055 }
00056 
00057 tree
00058 latex_class_filter (tree t) {
00059   t= extract_class_body (t);
00060   tree   incls = tree (USE_PACKAGE, "article", "std-latex");
00061   tree   doc   = tree (DOCUMENT);
00062   string header= "This style file is the result of an automatic conversion";
00063   doc << source_comment (header)
00064       << incls
00065       << source_comment ("Global layout parameters")
00066       << filter_setlength (t, "tex-odd-side-margin")
00067       << filter_setlength (t, "tex-even-side-margin")
00068       << filter_setlength (t, "tex-text-width")
00069       << filter_setlength (t, "tex-top-margin")
00070       << filter_setlength (t, "tex-head-height")
00071       << filter_setlength (t, "tex-top-skip")
00072       << filter_setlength (t, "tex-text-height")
00073       << filter_setlength (t, "tex-foot-skip")
00074       << filter_setlength (t, "tex-footnote-sep")
00075       << filter_setlength (t, "tex-column-sep")
00076       << filter_setlength (t, "tex-margin-par-width")
00077     //<< filter_setlength (t, "par-first")
00078       << filter_setlength (t, "tex-jot")
00079       << filter_setlength (t, "tex-math-indent")
00080       << filter_setlength (t, "tex-above-display-skip")
00081       << filter_setlength (t, "tex-below-display-skip")
00082       << filter_setlength (t, "tex-above-display-short-skip")
00083       << filter_setlength (t, "tex-below-display-short-skip")
00084       << source_comment ("Headers and footers")
00085       << source_comment ("Font sizes");
00086   tree the_style= compound ("style", "source");
00087   tree preamble = tree (ASSOCIATE, PREAMBLE, "true");
00088   tree the_init = compound ("initial", tree (COLLECTION, preamble));
00089   tree the_body = compound ("body", doc);
00090   return tree (DOCUMENT, the_style, the_init, the_body);
00091 }
00092 
00093 tree
00094 latex_class_document_to_tree (string s) {
00095   bool old= textm_class_flag;
00096   textm_class_flag= true;  
00097   tree t= latex_document_to_tree (s);
00098   tree r= latex_class_filter (t);
00099   textm_class_flag= old;
00100   return r;
00101 }