4242#include " importdata.h"
4343#include " reformat.h"
4444
45+
4546class SpLatex
4647{
4748public:
@@ -89,7 +90,12 @@ class SpLatex
8990 void multiplot (size_t ln, size_t indent, const std::string& cmdline);
9091
9192 // ! Process % TABULAR commands
92- void tabular (size_t ln, size_t indent, const std::string& cmdline);
93+ void tabular (size_t ln,
94+ size_t indent,
95+ const std::string& cmdline,
96+ const std::string & op_name,
97+ const std::string& separator,
98+ const std::string& endline);
9399
94100 // ! Process % tab separated (TABSEP) commands
95101 void tabsep (size_t ln, size_t indent, const std::string& cmdline);
@@ -384,7 +390,13 @@ void SpLatex::multiplot(size_t ln, size_t indent, const std::string& cmdline)
384390}
385391
386392// ! Process % TABULAR commands
387- void SpLatex::tabular (size_t ln, size_t indent, const std::string& cmdline)
393+ void SpLatex::tabular (
394+ size_t ln,
395+ size_t indent,
396+ const std::string& cmdline,
397+ const std::string& op_name,
398+ const std::string& separator,
399+ const std::string& endline)
388400{
389401 std::string query = cmdline;
390402
@@ -421,11 +433,11 @@ void SpLatex::tabular(size_t ln, size_t indent, const std::string& cmdline)
421433 std::ostringstream out;
422434 for (unsigned j = 0 ; j < sql->num_cols (); ++j)
423435 {
424- if (j != 0 ) out << " & " ;
436+ if (j != 0 ) out << separator ;
425437 out << std::setw (cwidth[j])
426438 << reformat.format (i, j, sql->text (i,j));
427439 }
428- out << " \\\\ " ;
440+ out << endline ;
429441 tlines.push_back (out.str ());
430442 }
431443
@@ -435,7 +447,7 @@ void SpLatex::tabular(size_t ln, size_t indent, const std::string& cmdline)
435447 ++eln;
436448
437449 static const boost::regex
438- re_endtabular (" [[:blank:]]*% END TABULAR .*" );
450+ re_endtabular (" [[:blank:]]*% END " + op_name + " .*" );
439451
440452 if (eln < m_lines.size () &&
441453 boost::regex_match (m_lines[eln], re_endtabular))
@@ -455,14 +467,14 @@ void SpLatex::tabular(size_t ln, size_t indent, const std::string& cmdline)
455467 ++rln;
456468 }
457469
458- tlines.push_back (shorten (" % END TABULAR " + query));
459- m_lines.replace (ln, eln+1 , indent, tlines, " TABULAR " );
470+ tlines.push_back (shorten (" % END " + op_name + " " + query));
471+ m_lines.replace (ln, eln+1 , indent, tlines, op_name );
460472 }
461473 else
462474 {
463475 // could not find END TABULAR: insert whole table.
464- tlines.push_back (shorten (" % END TABULAR " + query));
465- m_lines.replace (ln, ln, indent, tlines, " TABULAR " );
476+ tlines.push_back (shorten (" % END " + op_name + " " + query));
477+ m_lines.replace (ln, ln, indent, tlines, op_name );
466478 }
467479}
468480
@@ -649,7 +661,12 @@ SpLatex::SpLatex(TextLines& lines)
649661 else if (first_word == " TABULAR" )
650662 {
651663 OUT (ln << " % " << cmd);
652- tabular (ln, indent, cmd.substr (space_pos+1 ));
664+ tabular (ln, indent, cmd.substr (space_pos+1 ), " TABULAR" , " & " , " \\\\ " );
665+ }
666+ else if (first_word == " TABTABLE" )
667+ {
668+ OUT (ln << " % " << cmd);
669+ tabular (ln, indent, cmd.substr (space_pos+1 ), " TABTABLE" , " \t " , " " );
653670 }
654671 else if (first_word == " TABSEP" )
655672 {
0 commit comments