- 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, char 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) &&
- (par->footnoteflag == footnoteflag)) {
- if (par->IsDummy())
- lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
- 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,
- foot, foot_texrow,
- foot_count);
- }
- }
- 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;
- if (IsDummy())
- lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
-
- LyXLayout const & style =
- textclasslist.Style(bparams.textclass,
- layout);
-
- if (pextra_type == PEXTRA_INDENT) {
- if (!pextra_width.empty()) {
- os << "\\begin{LyXParagraphIndent}{"
- << pextra_width << "}\n";
- } else {
- //float ib = atof(pextra_widthp.c_str())/100;
- // string can't handle floats at present (971109)
- // so I'll do a conversion by hand knowing that
- // the limits are 0.0 to 1.0. ARRae.
- os << "\\begin{LyXParagraphIndent}{";
- switch (pextra_widthp.length()) {
- case 3:
- os << "1.00";
- break;
- case 2:
- os << "0."
- << pextra_widthp;
- break;
- case 1:
- os << "0.0"
- << pextra_widthp;
- }
- os << "\\columnwidth}\n";
- }
- texrow.newline();
- eindent_open = true;
- }
- if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
- if (pextra_hfill && Previous() &&
- (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
- os << "\\hfill{}\n";
- texrow.newline();
- }
- if (par_sep == BufferParams::PARSEP_INDENT) {
- os << "{\\setlength\\parindent{0pt}\n";
- texrow.newline();
- }
- os << "\\begin{minipage}";
- switch(pextra_alignment) {
- case MINIPAGE_ALIGN_TOP:
- os << "[t]";
- break;
- case MINIPAGE_ALIGN_MIDDLE:
- os << "[m]";
- break;
- case MINIPAGE_ALIGN_BOTTOM:
- os << "[b]";
- break;
- }
- if (!pextra_width.empty()) {
- os << '{' << pextra_width << "}\n";
- } else {
- //float ib = atof(par->pextra_width.c_str())/100;
- // string can't handle floats at present
- // so I'll do a conversion by hand knowing that
- // the limits are 0.0 to 1.0. ARRae.
- os << '{';
- switch (pextra_widthp.length()) {
- case 3:
- os << "1.00";
- break;
- case 2:
- os << "0."
- << pextra_widthp;
- break;
- case 1:
- os << "0.0"
- << pextra_widthp;
- }
- os << "\\columnwidth}\n";
- }
- texrow.newline();
- if (par_sep == BufferParams::PARSEP_INDENT) {
- os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
- texrow.newline();
- }
- minipage_open = true;
- minipage_open_depth = depth;
- }
-
-#ifdef WITH_WARNINGS
-#warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
- //I disabled it because it breaks when lists span on several
- //pages (JMarc)
-#endif
- if (style.isEnvironment()){
- if (style.latextype == LATEX_LIST_ENVIRONMENT) {
-#ifdef FANCY_FOOTNOTE_CODE
- if (foot_count < 0) {
- // flag that footnote[mark][text] should be
- // used for any footnotes from now on
- foot_count = 0;
- foot_this_level = true;
- }
-#endif
- os << "\\begin{" << style.latexname() << "}{"
- << labelwidthstring << "}\n";
- } else if (style.labeltype == LABEL_BIBLIO) {
- // ale970405
- os << "\\begin{" << style.latexname() << "}{"
- << bibitemWidest(current_view)
- << "}\n";
- } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
-#ifdef FANCY_FOOTNOTE_CODE
- if (foot_count < 0) {
- // flag that footnote[mark][text] should be
- // used for any footnotes from now on
- foot_count = 0;
- foot_this_level = true;
- }
-#endif
- os << "\\begin{" << style.latexname() << '}'
- << style.latexparam() << '\n';
- } else
- os << "\\begin{" << style.latexname() << '}'
- << style.latexparam() << '\n';
- texrow.newline();
- }
- LyXParagraph * par = this;
- do {
- par = par->TeXOnePar(buf, bparams,
- os, texrow, false,
- foot, foot_texrow, foot_count);
-
- if (minipage_open && par && !style.isEnvironment() &&
- (par->pextra_type == PEXTRA_MINIPAGE) &&
- par->pextra_start_minipage) {
- os << "\\end{minipage}\n";
- texrow.newline();
- if (par_sep == BufferParams::PARSEP_INDENT) {
- os << "}\n";
- texrow.newline();
- }
- minipage_open = false;
- }
- if (par && par->depth > depth) {