- 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
-#ifndef NEW_INSETS
- ,ostream & foot,
- TexRow & foot_texrow,
- int & foot_count
-#endif
- )
-{
- lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
- LyXParagraph * par = this;
-
- while (par &&
- (par->params.depth() == params.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()
-#ifndef NO_PEXTRA
- || par->params.pextraType() != PEXTRA_NONE
-#endif
- ) {
- par = par->TeXEnvironment(buf, bparams,
- os, texrow
-#ifndef NEW_INSETS
- ,foot, foot_texrow,
- foot_count
-#endif
- );
- } 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
-#ifndef NEW_INSETS
- ,ostream & foot,
- TexRow & foot_texrow,
- int & foot_count
-#endif
- )
-{
-#ifndef NO_PEXTRA
- bool eindent_open = false;
-#endif
-#ifndef NEW_INSETS
- bool foot_this_level = false;
-#endif
-#ifndef NO_PEXTRA
- // 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;
-#endif
-
- lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
-#ifndef NEW_INSETS
- if (IsDummy())
- lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
-#endif
-
- LyXLayout const & style =
- textclasslist.Style(bparams.textclass,
- layout);
-
-#ifndef NO_PEXTRA
- if (params.pextraType() == PEXTRA_INDENT) {
- if (!params.pextraWidth().empty()) {
- os << "\\begin{LyXParagraphIndent}{"
- << params.pextraWidth() << "}\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 (params.pextraWidthp().length()) {
- case 3:
- os << "1.00";
- break;
- case 2:
- os << "0."
- << params.pextraWidthp();
- break;
- case 1:
- os << "0.0"
- << params.pextraWidthp();
- }
- os << "\\columnwidth}\n";
- }
- texrow.newline();
- eindent_open = true;
- }
- if ((params.pextraType() == PEXTRA_MINIPAGE) && !minipage_open) {
- if (params.pextraHfill() && previous() &&
- (previous()->params.pextraType() == PEXTRA_MINIPAGE)) {
- os << "\\hfill{}\n";
- texrow.newline();
- }
- if (par_sep == BufferParams::PARSEP_INDENT) {
- os << "{\\setlength\\parindent{0pt}\n";
- texrow.newline();
- }
- os << "\\begin{minipage}";
- switch (params.pextraAlignment()) {
- case MINIPAGE_ALIGN_TOP:
- os << "[t]";
- break;
- case MINIPAGE_ALIGN_MIDDLE:
- os << "[m]";
- break;
- case MINIPAGE_ALIGN_BOTTOM:
- os << "[b]";
- break;
- }
- if (!params.pextraWidth().empty()) {
- os << '{' << params.pextraWidth() << "}\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 (params.pextraWidthp().length()) {
- case 3:
- os << "1.00";
- break;
- case 2:
- os << "0."
- << params.pextraWidthp();
- break;
- case 1:
- os << "0.0"
- << params.pextraWidthp();
- }
- os << "\\columnwidth}\n";
- }
- texrow.newline();
- if (par_sep == BufferParams::PARSEP_INDENT) {
- os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
- texrow.newline();
- }
- minipage_open = true;
- minipage_open_depth = params.depth();
- }
-#endif
-#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() << "}{"
- << params.labelWidthString() << "}\n";
- } else if (style.labeltype == LABEL_BIBLIO) {
- // ale970405
- os << "\\begin{" << style.latexname() << "}{"
- << bibitemWidest(buf)
- << "}\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
-#ifndef NEW_INSETS
- ,
- foot, foot_texrow, foot_count
-#endif
- );
-#ifndef NO_PEXTRA
- if (minipage_open && par && !style.isEnvironment() &&
- (par->params.pextraType() == PEXTRA_MINIPAGE) &&
- par->params.pextraStartMinipage()) {
- os << "\\end{minipage}\n";
- texrow.newline();
- if (par_sep == BufferParams::PARSEP_INDENT) {
- os << "}\n";
- texrow.newline();
- }
- minipage_open = false;
- }
-#endif
- if (par && par->params.depth() > params.depth()) {