- if (!lyxrc.language_auto_begin) {
- os << subst(lyxrc.language_command_begin, "$$lang",
- params.language->babel())
- << endl;
- texrow.newline();
- }
-
- latexParagraphs(this, paragraphs, os, texrow, false);
-
- // add this just in case after all the paragraphs
- os << endl;
- texrow.newline();
-
- if (!lyxrc.language_auto_end) {
- os << subst(lyxrc.language_command_end, "$$lang",
- params.language->babel())
- << endl;
- texrow.newline();
- }
-
- if (!only_body) {
- os << "\\end{document}\n";
- texrow.newline();
-
- lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
- } else {
- lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
- << endl;
- }
-
- // Just to be sure. (Asger)
- texrow.newline();
-
- lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
- lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
- << '.' << endl;
-
- // we want this to be true outside previews (for insetexternal)
- niceFile = true;
-}
-
-
-bool Buffer::isLatex() const
-{
- return params.getLyXTextClass().outputType() == LATEX;
-}
-
-
-bool Buffer::isLinuxDoc() const
-{
- return params.getLyXTextClass().outputType() == LINUXDOC;
-}
-
-
-bool Buffer::isLiterate() const
-{
- return params.getLyXTextClass().outputType() == LITERATE;
-}
-
-
-bool Buffer::isDocBook() const
-{
- return params.getLyXTextClass().outputType() == DOCBOOK;
-}
-
-
-bool Buffer::isSGML() const
-{
- LyXTextClass const & tclass = params.getLyXTextClass();
-
- return tclass.outputType() == LINUXDOC ||
- tclass.outputType() == DOCBOOK;
-}
-
-
-void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
-{
- ofstream ofs(fname.c_str());
-
- if (!ofs) {
- string const file = MakeDisplayPath(fname, 50);
- string text = bformat(_("Could not save the specified document\n%1$s.\n"),
- file);
- Alert::error(_("Could not save document"), text);
- return;
- }
-
- niceFile = nice; // this will be used by included files.
-
- LaTeXFeatures features(params);
-
- validate(features);
-
- texrow.reset();
-
- LyXTextClass const & tclass = params.getLyXTextClass();
-
- string top_element = tclass.latexname();
-
- if (!body_only) {
- ofs << "<!doctype linuxdoc system";
-
- string preamble = params.preamble;
- const string name = nice ? ChangeExtension(filename_, ".sgml")
- : fname;
- preamble += features.getIncludedFiles(name);
- preamble += features.getLyXSGMLEntities();
-
- if (!preamble.empty()) {
- ofs << " [ " << preamble << " ]";
- }
- ofs << ">\n\n";
-
- if (params.options.empty())
- sgml::openTag(ofs, 0, false, top_element);
- else {
- string top = top_element;
- top += ' ';
- top += params.options;
- sgml::openTag(ofs, 0, false, top);
- }
- }
-
- ofs << "<!-- " << lyx_docversion
- << " created this file. For more info see http://www.lyx.org/"
- << " -->\n";
-
- Paragraph::depth_type depth = 0; // paragraph depth
- string item_name;
- vector<string> environment_stack(5);
-
- users->resetErrorList();
-
- ParagraphList::iterator pit = paragraphs.begin();
- ParagraphList::iterator pend = paragraphs.end();
- for (; pit != pend; ++pit) {
- LyXLayout_ptr const & style = pit->layout();
- // treat <toc> as a special case for compatibility with old code
- if (pit->isInset(0)) {
- Inset * inset = pit->getInset(0);
- Inset::Code lyx_code = inset->lyxCode();
- if (lyx_code == Inset::TOC_CODE) {
- string const temp = "toc";
- sgml::openTag(ofs, depth, false, temp);
- continue;
- }
- }
-
- // environment tag closing
- for (; depth > pit->params().depth(); --depth) {
- sgml::closeTag(ofs, depth, false, environment_stack[depth]);
- environment_stack[depth].erase();
- }
-
- // write opening SGML tags
- switch (style->latextype) {
- case LATEX_PARAGRAPH:
- if (depth == pit->params().depth()
- && !environment_stack[depth].empty()) {
- sgml::closeTag(ofs, depth, false, environment_stack[depth]);
- environment_stack[depth].erase();
- if (depth)
- --depth;
- else
- ofs << "</p>";
- }
- sgml::openTag(ofs, depth, false, style->latexname());
- break;
-
- case LATEX_COMMAND:
- if (depth != 0)
- sgmlError(pit, 0,
- _("Error: Wrong depth for LatexType Command.\n"));
-
- if (!environment_stack[depth].empty()) {
- sgml::closeTag(ofs, depth, false, environment_stack[depth]);
- ofs << "</p>";
- }
-
- environment_stack[depth].erase();
- sgml::openTag(ofs, depth, false, style->latexname());
- break;
-
- case LATEX_ENVIRONMENT:
- case LATEX_ITEM_ENVIRONMENT:
- case LATEX_BIB_ENVIRONMENT:
- {
- string const & latexname = style->latexname();
-
- if (depth == pit->params().depth()
- && environment_stack[depth] != latexname) {
- sgml::closeTag(ofs, depth, false,
- environment_stack[depth]);
- environment_stack[depth].erase();
- }
- if (depth < pit->params().depth()) {
- depth = pit->params().depth();
- environment_stack[depth].erase();
- }
- if (environment_stack[depth] != latexname) {
- if (depth == 0) {
- sgml::openTag(ofs, depth, false, "p");
- }
- sgml::openTag(ofs, depth, false, latexname);
-
- if (environment_stack.size() == depth + 1)
- environment_stack.push_back("!-- --");
- environment_stack[depth] = latexname;
- }
-
- if (style->latexparam() == "CDATA")
- ofs << "<![CDATA[";
-
- if (style->latextype == LATEX_ENVIRONMENT) break;
-
- if (style->labeltype == LABEL_MANUAL)
- item_name = "tag";
- else
- item_name = "item";
-
- sgml::openTag(ofs, depth + 1, false, item_name);
- }
- break;
-
- default:
- sgml::openTag(ofs, depth, false, style->latexname());
- break;
- }
-
- simpleLinuxDocOnePar(ofs, pit, depth);
-
- ofs << "\n";
- // write closing SGML tags
- switch (style->latextype) {
- case LATEX_COMMAND:
- break;
- case LATEX_ENVIRONMENT:
- case LATEX_ITEM_ENVIRONMENT:
- case LATEX_BIB_ENVIRONMENT:
- if (style->latexparam() == "CDATA")
- ofs << "]]>";
- break;
- default:
- sgml::closeTag(ofs, depth, false, style->latexname());
- break;
- }
- }
-
- // Close open tags
- for (int i = depth; i >= 0; --i)
- sgml::closeTag(ofs, depth, false, environment_stack[i]);