Back to index

texmacs  1.0.7.15
nested.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : nested.cpp
00004 * DESCRIPTION: A plugin which demonstrates nested DATA_BEGIN/DATA_END blocks
00005 * COPYRIGHT  : (C) 2003  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 <iostream>
00013 using namespace std;
00014 
00015 #define DATA_BEGIN   ((char) 2)
00016 #define DATA_END     ((char) 5)
00017 #define DATA_ESCAPE  ((char) 27)
00018 
00019 void
00020 f (int i, int nr) {
00021   if (i >= nr) cout << nr;
00022   else {
00023     cout << "\\frac{1}{" << i << "+";
00024     f (i+1, nr);
00025     cout << "}\n";
00026   }
00027 }
00028 
00029 int
00030 main () {
00031   cout << DATA_BEGIN << "verbatim:";
00032   cout << "Please enter a positive integer at each input";
00033   cout << DATA_END;
00034   cout.flush ();
00035 
00036   while (true) {
00037     int i, nr;
00038     cin >> nr;
00039     cout << DATA_BEGIN << "verbatim:";
00040 
00041     cout << "A first formula\n";
00042     cout << DATA_BEGIN << "latex:";
00043     cout << "$";
00044     for (i=1; i<nr; i++)
00045       cout << "x_{" << i << "}+";
00046     cout << "x_{" << i << "}$";
00047     cout << DATA_END;
00048 
00049     cout << "\nA second formula\n";
00050     cout << DATA_BEGIN << "latex:";
00051     cout << "$\\displaystyle ";
00052     f (1, nr);
00053     cout << "$";
00054     cout << DATA_END;
00055 
00056     cout << DATA_END;
00057     cout.flush ();
00058   }
00059   return 0;
00060 }