- BufferParams const & bparams = buffer->params;
- if (!table) return;
- lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
- int column = 0;
- LyXFont font1, font2;
- char c;
- Inset * inset;
- size_type main_body;
- bool emph_flag = false;
-
- LyXLayout const & style =
- textclasslist.Style(bparams.textclass,
- GetLayout());
-
- if (style.labeltype != LABEL_MANUAL)
- main_body = 0;
- else
- main_body = BeginningOfMainBody();
-
- // Gets paragraph main font.
- if (main_body > 0)
- font1 = style.labelfont;
- else
- font1 = style.font;
-
- int char_line_count = depth;
- os << newlineAndDepth(depth);
-#ifndef NEW_INSETS
- if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
- os << "<INFORMALTABLE>"
- << newlineAndDepth(++depth);
- }
-#else
- os << "<INFORMALTABLE>"
- << newlineAndDepth(++depth);
-#endif
- int current_cell_number = -1;
- int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
-
- // Parsing main loop.
- for (size_type i = 0; i < size(); ++i) {
- c = GetChar(i);
- if (table->IsContRow(current_cell_number+1)) {
- if (c == LyXParagraph::META_NEWLINE)
- ++current_cell_number;
- continue;
- }
- ++column;
-
- // Fully instantiated font
- font2 = getFont(bparams, i);
-
- // Handle <emphasis> tag.
- if (font1.emph() != font2.emph() && i) {
- if (font2.emph() == LyXFont::ON) {
- os << "<emphasis>";
- emph_flag= true;
- } else if (emph_flag) {
- os << "</emphasis>";
- emph_flag= false;
- }
- }
- if (c == LyXParagraph::META_NEWLINE) {
- // We have only to control for emphasis open here!
- if (emph_flag) {
- os << "</emphasis>";
- emph_flag= false;
- }
- font1 = font2 = getFont(bparams, -1);
- ++current_cell_number;
- if (table->CellHasContRow(current_cell_number) >= 0) {
- DocBookContTableRows(buffer,
- os, extra, desc_on, i + 1,
- current_cell_number,
- column);
- }
- // if this cell follow only ContRows till end don't
- // put the EndOfCell because it is put after the
- // for(...)
- if (table->ShouldBeVeryLastCell(current_cell_number)) {
- --current_cell_number;
- break;
- }
- tmp = table->DocBookEndOfCell(os,
- current_cell_number,
- depth);
-
- if (tmp > 0)
- column = 0;
- } else if (c == LyXParagraph::META_INSET) {
- inset = GetInset(i);
-#ifdef HAVE_SSTREAM
- std::ostringstream ost;
- inset->DocBook(buffer, ost);
- string tmp_out = ost.str().c_str();
-#else
- ostrstream ost;
- inset->DocBook(buffer, ost);
- ost << '\0';
- char * ctmp = ost.str();
- string tmp_out(ctmp);
- delete [] ctmp;
-#endif
- //
- // This code needs some explanation:
- // Two insets are treated specially
- // label if it is the first element in a
- // command paragraph
- // desc_on == 3
- // graphics inside tables or figure floats
- // can't go on
- // title (the equivalente in latex for this
- // case is caption
- // and title should come first
- // desc_on == 4
- //
- if(desc_on != 3 || i != 0) {
- if(tmp_out[0] == '@') {
- if(desc_on == 4)
- extra += frontStrip(tmp_out,
- '@');
- else
- os << frontStrip(tmp_out,
- '@');
- } else
- os << tmp_out;
- }
- } else if (font2.latex() == LyXFont::ON) {
- // "TeX"-Mode on == > SGML-Mode on.
- if (c != '\0')
- os << c;
- ++char_line_count;
- } else {
- string sgml_string;
- if (linuxDocConvertChar(c, sgml_string)
- && !style.free_spacing) {
- // in freespacing mode, spaces are
- // non-breaking characters
- // char is ' '
- if (desc_on == 1) {
- ++char_line_count;
- os << '\n'
- << "</term><listitem><para>";
- desc_on = 2;
- } else {
- os << c;
- }
- } else {
- os << sgml_string;
- }
- }
- font1 = font2;
- }
-
- // Needed if there is an optional argument but no contents.
- if (main_body > 0 && main_body == size()) {
- font1 = style.font;
- }
-
- if (emph_flag) {
- os << "</emphasis>";
- }
-
- ++current_cell_number;
- tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
- // Resets description flag correctly.
- switch(desc_on){
- case 1:
- // <term> not closed...
- os << "</term>";
- break;
- }
-#ifndef NEW_INSETS
- if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
-#endif
- os << "</INFORMALTABLE>";
- os << '\n';
- lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
- << this << endl;
-}
-
-
-void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
- ostream & os, string & extra,
- int & desc_on,
- LyXParagraph::size_type i,
- int current_cell_number, int &column)
-
-{
- if (!table) return;
-
- BufferParams const & bparams = buffer->params;
-
- lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
-
- LyXFont font2;
- char c;
- Inset * inset;
- //string emph = "emphasis";
- bool emph_flag = false;
- int char_line_count = 0;
-
- LyXLayout const & style =
- textclasslist.Style(bparams.textclass,
- GetLayout());
-
- size_type main_body;
- if (style.labeltype != LABEL_MANUAL)
- main_body = 0;
- else
- main_body = BeginningOfMainBody();
-
- // Gets paragraph main font.
- LyXFont font1;
- if (main_body > 0)
- font1 = style.labelfont;
- else
- font1 = style.font;
-
- size_type lastpos = i;
- int cell = table->CellHasContRow(current_cell_number);
- ++current_cell_number;
- while(cell >= 0) {
- // first find the right position
- i = lastpos;
- for (; i < size() && current_cell_number < cell; ++i) {
- c = GetChar(i);
- if (c == LyXParagraph::META_NEWLINE)
- ++current_cell_number;
- }
- lastpos = i;
- c = GetChar(i);
- // I don't know how to handle this so I comment it
- // for the moment (Jug)
-// if (table->Linebreaks(table->FirstVirtualCell(cell))) {
-// file += " \\\\\n";
-// column = 0;
-// } else
- if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
- os << ' ';
- }
-
- for (; i < size()
- && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
- ++i) {
- ++column;
-
- // Fully instantiated font
- font2 = getFont(bparams, i);
-
- // Handle <emphasis> tag.
- if (font1.emph() != font2.emph() && i) {
- if (font2.emph() == LyXFont::ON) {
- os << "<emphasis>";
- emph_flag= true;
- } else if (emph_flag) {
- os << "</emphasis>";
- emph_flag= false;
- }
- }
- if (c == LyXParagraph::META_INSET) {
- inset = GetInset(i);
-#ifdef HAVE_SSTREAM
- std::ostringstream ost;
- inset->DocBook(buffer, ost);
- string tmp_out = ost.str().c_str();
-#else
- ostrstream ost;
- inset->DocBook(buffer, ost);
- ost << '\0';
- char * ctmp = ost.str();
- string tmp_out(ctmp);
- delete [] ctmp;
-#endif
- //
- // This code needs some explanation:
- // Two insets are treated specially
- // label if it is the first element in a
- // command paragraph
- // desc_on == 3
- // graphics inside tables or figure floats
- // can't go on title (the equivalente in
- // latex for this case is caption and title
- // should come first
- // desc_on == 4
- //
- if(desc_on != 3 || i != 0) {
- if(tmp_out[0] == '@') {
- if(desc_on == 4)
- extra += frontStrip(tmp_out, '@');
- else
- os << frontStrip(tmp_out, '@');
- } else
- os << tmp_out;
- }
- } else if (font2.latex() == LyXFont::ON) {
- // "TeX"-Mode on == > SGML-Mode on.
- if (c!= '\0')
- os << c;
- ++char_line_count;
- } else {
- string sgml_string;
- if (linuxDocConvertChar(c, sgml_string)
- && !style.free_spacing) {
- // in freespacing mode, spaces are
- // non-breaking characters
- // char is ' '
- if (desc_on == 1) {
- ++char_line_count;
- os << '\n'
- << "</term><listitem><para>";
- desc_on = 2;
- } else {
- os << c;
- }
- } else {
- os << sgml_string;
- }
- }
- }
- // we have only to control for emphasis open here!
- if (emph_flag) {
- os << "</emphasis>";
- emph_flag= false;
- }
- font1 = font2 = getFont(bparams, -1);
- cell = table->CellHasContRow(current_cell_number);
- }
- lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
-}
-
-
-void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
- LyXParagraph::size_type const i,
- int & column, LyXFont const & font,
- LyXLayout const & style)
-{
- if (column > tex_code_break_column
- && i
- && GetChar(i - 1) != ' '
- && (i < size() - 1)
- // In LaTeX mode, we don't want to
- // break lines since some commands
- // do not like this
- && ! (font.latex() == LyXFont::ON)
- // same in FreeSpacing mode
- && !style.free_spacing
- // In typewriter mode, we want to avoid
- // ! . ? : at the end of a line
- && !(font.family() == LyXFont::TYPEWRITER_FAMILY
- && (GetChar(i-1) == '.'
- || GetChar(i-1) == '?'
- || GetChar(i-1) == ':'
- || GetChar(i-1) == '!'))) {
- if (tex_code_break_column == 0) {
- // in batchmode we need LaTeX to still
- // see it as a space not as an extra '\n'
- os << " %\n";
- } else {
- os << '\n';
- }
- texrow.newline();
- texrow.start(this, i + 1);
- column = 0;
- } else if (font.latex() == LyXFont::OFF) {
- if (style.free_spacing) {
- os << '~';
- } else {
- os << ' ';
- }
- }
-}
-
-
-void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
- BufferParams const & bparams,
- ostream & os, TexRow & texrow,
- bool moving_arg,
- LyXFont & font,
- LyXFont & running_font,
- LyXFont & basefont,
- bool & open_font,
- LyXLayout const & style,
- LyXParagraph::size_type & i,
- int & column,
- LyXParagraph::value_type const c)
-{
- // Two major modes: LaTeX or plain
- // Handle here those cases common to both modes
- // and then split to handle the two modes separately.
- switch (c) {
- case LyXParagraph::META_INSET: {
- Inset * inset = GetInset(i);
- if (inset) {
- bool close = false;
- int len = os.tellp();
- if ((inset->LyxCode() == Inset::GRAPHICS_CODE
- || inset->LyxCode() == Inset::MATH_CODE
- || inset->LyxCode() == Inset::URL_CODE)
- && running_font.isRightToLeft()) {
- os << "\\L{";
- close = true;
- }
-
- int tmp = inset->Latex(buf, os, moving_arg,
- style.free_spacing);
-
- if (close)
- os << "}";
-
- if (tmp) {
- column = 0;
- } else {
- column += os.tellp() - len;
- }
- for (; tmp--;) {
- texrow.newline();
- }
- }
- }
- break;
-
- case LyXParagraph::META_NEWLINE:
- if (open_font) {
- column += running_font.latexWriteEndChanges(os,
- basefont,
- basefont);
- open_font = false;
- }
- basefont = getFont(bparams, -1);
- running_font = basefont;
- break;
-
- case LyXParagraph::META_HFILL:
- os << "\\hfill{}";
- column += 7;
- break;
-
- default:
- // And now for the special cases within each mode
- // Are we in LaTeX mode?
- if (font.latex() == LyXFont::ON) {
- // at present we only have one option
- // but I'll leave it as a switch statement
- // so its simpler to extend. (ARRae)
- switch (c) {
- default:
- // make sure that we will not print
- // error generating chars to the tex
- // file. This test would not be needed
- // if it were done in the buffer
- // itself.
- if (c != '\0') {
- os << c;
- }
- break;
- }
- } else {
- // Plain mode (i.e. not LaTeX)
- switch (c) {
- case '\\':
- os << "\\textbackslash{}";
- column += 15;
- break;
-
- case '°': case '±': case '²': case '³':
- case '×': case '÷': case '¹': case 'ª':
- case 'º': case '¬': case 'µ':
- if (bparams.inputenc == "latin1" ||
- (bparams.inputenc == "auto" &&
- font.language()->encoding()->LatexName()
- == "latin1")) {
- os << "\\ensuremath{"
- << c
- << '}';
- column += 13;
- } else {
- os << c;
- }
- break;
-
- case '|': case '<': case '>':
- // In T1 encoding, these characters exist
- if (lyxrc.fontenc == "T1") {
- os << c;
- //... but we should avoid ligatures
- if ((c == '>' || c == '<')
- && i <= size() - 2
- && GetChar(i + 1) == c) {
- //os << "\\textcompwordmark{}";
- // Jean-Marc, have a look at
- // this. IÂ think this works
- // equally well:
- os << "\\,{}";
- // Lgb
- column += 19;
- }
- break;
- }
- // Typewriter font also has them
- if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
- os << c;
- break;
- }
- // Otherwise, we use what LaTeX
- // provides us.
- switch(c) {
- case '<':
- os << "\\textless{}";
- column += 10;
- break;
- case '>':
- os << "\\textgreater{}";
- column += 13;
- break;
- case '|':
- os << "\\textbar{}";
- column += 9;
- break;
- }
- break;
-
- case '-': // "--" in Typewriter mode -> "-{}-"
- if (i <= size() - 2
- && GetChar(i + 1) == '-'
- && font.family() == LyXFont::TYPEWRITER_FAMILY) {
- os << "-{}";
- column += 2;
- } else {
- os << '-';
- }
- break;
-
- case '\"':
- os << "\\char`\\\"{}";
- column += 9;
- break;
-
- case '£':
- if (bparams.inputenc == "default") {
- os << "\\pounds{}";
- column += 8;
- } else {
- os << c;
- }
- break;
-
- case '$': case '&':
- case '%': case '#': case '{':
- case '}': case '_':
- os << '\\' << c;
- column += 1;
- break;
-
- case '~':
- os << "\\textasciitilde{}";
- column += 16;
- break;
-
- case '^':
- os << "\\textasciicircum{}";
- column += 17;
- break;
-
- case '*': case '[': case ']':
- // avoid being mistaken for optional arguments
- os << '{' << c << '}';
- column += 2;
- break;
-
- case ' ':
- // Blanks are printed before font switching.
- // Sure? I am not! (try nice-latex)
- // I am sure it's correct. LyX might be smarter
- // in the future, but for now, nothing wrong is
- // written. (Asger)
- break;
-
- default:
- /* idea for labels --- begin*/
- // Check for "LyX"
- if (c == 'L'
- && i <= size() - 3
- && font.family() != LyXFont::TYPEWRITER_FAMILY
- && GetChar(i + 1) == 'y'
- && GetChar(i + 2) == 'X') {
- os << "\\LyX{}";
- i += 2;
- column += 5;
- }
- // Check for "TeX"
- else if (c == 'T'
- && i <= size() - 3
- && font.family() != LyXFont::TYPEWRITER_FAMILY
- && GetChar(i + 1) == 'e'
- && GetChar(i + 2) == 'X') {
- os << "\\TeX{}";
- i += 2;
- column += 5;
- }
- // Check for "LaTeX2e"
- else if (c == 'L'
- && i <= size() - 7
- && font.family() != LyXFont::TYPEWRITER_FAMILY
- && GetChar(i + 1) == 'a'
- && GetChar(i + 2) == 'T'
- && GetChar(i + 3) == 'e'
- && GetChar(i + 4) == 'X'
- && GetChar(i + 5) == '2'
- && GetChar(i + 6) == 'e') {
- os << "\\LaTeXe{}";
- i += 6;
- column += 8;
- }
- // Check for "LaTeX"
- else if (c == 'L'
- && i <= size() - 5
- && font.family() != LyXFont::TYPEWRITER_FAMILY
- && GetChar(i + 1) == 'a'
- && GetChar(i + 2) == 'T'
- && GetChar(i + 3) == 'e'
- && GetChar(i + 4) == 'X') {
- os << "\\LaTeX{}";
- i += 4;
- column += 7;
- /* idea for labels --- end*/
- } else if (c != '\0') {
- os << c;
- }
- break;
- }
- }
- }
-}
-
-
-LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
- BufferParams const & bparams,
- ostream & os, TexRow & texrow,
- ostream & foot,
- TexRow & foot_texrow,
- int & foot_count)
-{
- lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
- LyXParagraph * par = this;
-
- while (par &&
- (par->depth == depth)
-#ifndef NEW_INSETS
- && (par->footnoteflag == footnoteflag)
-#endif
- ) {
-#ifndef NEW_INSETS
- if (par->IsDummy())
- lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
-#endif
- if (textclasslist.Style(bparams.textclass,
- par->layout).isEnvironment()
- || par->pextra_type != PEXTRA_NONE) {
- par = par->TeXEnvironment(buf, bparams,
- os, texrow,
- foot, foot_texrow,
- foot_count);
- } else {
- par = par->TeXOnePar(buf, bparams,
- os, texrow, false
-#ifndef NEW_INSETS
- ,
- foot, foot_texrow,
- foot_count
-#endif
- );
- }
- }
- lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
-
- return par;
-}
-
-
-LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
- BufferParams const & bparams,
- ostream & os, TexRow & texrow,
- ostream & foot,
- TexRow & foot_texrow,
- int & foot_count)
-{
- bool eindent_open = false;
- bool foot_this_level = false;
- // flags when footnotetext should be appended to file.
- static bool minipage_open = false;
- static int minipage_open_depth = 0;
- char par_sep = bparams.paragraph_separation;
-
- lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
-#ifndef NEW_INSETS
- if (IsDummy())
- lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
-#endif
-