Jean-Marc Lasgouttes wrote: >>>>>> "Helge" == Helge Hafting >>>>>> <[EMAIL PROTECTED]> writes: > > Helge> I think this is a low-risk item that could go into 1.4.x, for > Helge> it adds functionality without messing with other things. > > The patch looks good (but we must be careful about the possible > interaction; the export code has weird assumptions). It would be a > good candidate for 1.4.2.
Here comes an updated one. It renames the GUI names of the latex and pdflatex formats as Helge suggested. It also adds the needed changes to OutputParams::exportdata that I forgot in the last patch. I implemented the suggestion of Jean-Marc to use a full OutputParams variable in LaTeXFeatures instead of several flags. > Instead of testing for names when doing export to guess the flavour, > wouldn't it be better to use a 'pdflatex' format flag instead of the > current 'latex' and work from that? Currently, the format names are > hardcoded in a way I do not like very much. I agree. The problem is that formats don't have flags yet, only converters. Splitting the "latex" flag of the converters into "latex" and "pdflatex" would not be a good idea, because a) we reaally want a format flag and b) we would need to touch a lot of code. I do plan format flags (such as "noexport" and "noview") for later. Since this requires changes to lyxrc reading I would like to do without them for now and put the attached patch into trunk. OK? Georg Log: * src/LaTeXFeatures.[Ch]: replace nice_ by runparams_ * src/insets/insetexternal.C (InsetExternal::validate): Use the correct template for the desired output format * src/insets/insetgraphics.C (InsetGraphics::prepareFile): Record the needed files for "latex" or "pdflatex" format, dependant on the desired output format * src/insets/insetinclude.C (InsetInclude::latex): ditto * src/BufferView_pimpl.C (BufferView::Pimpl::getStatus): adapt to LaTeXFeatures changes * src/paragraph_pimpl.C (Paragraph::Pimpl::simpleTeXSpecialC): ditto * src/buffer.C (Buffer::makeLaTeXFile): ditto (Buffer::makeLinuxDocFile): ditto (Buffer::makeDocBookFile): ditto * src/paragraph.C (Paragraph::simpleTeXOnePar): ditto * src/exporter.C (Backends): Add "pdflatex" backend format (Exporter::Export): set runparams.flavor correctly for "pdflatex" format * lib/external_templates (RasterImage): Use "pdflatex" format in PDFLaTeX template (XFig): ditto (ChessDiagram): Add PDFLaTeX template (Date): ditto * lib/configure.py: Add "pdflatex" format
Index: src/LaTeXFeatures.C =================================================================== --- src/LaTeXFeatures.C (Revision 13511) +++ src/LaTeXFeatures.C (Arbeitskopie) @@ -49,8 +49,9 @@ namespace biblio = lyx::biblio; LaTeXFeatures::PackagesList LaTeXFeatures::packages_; -LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p, bool n) - : buffer_(&b), params_(p), nice_(n) +LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p, + OutputParams const & r) + : buffer_(&b), params_(p), runparams_(r) {} Index: src/insets/insetexternal.C =================================================================== --- src/insets/insetexternal.C (Revision 13511) +++ src/insets/insetexternal.C (Arbeitskopie) @@ -753,9 +753,20 @@ void InsetExternal::validate(LaTeXFeatur return; external::Template const & et = *et_ptr; - // FIXME: This is wrong if we export to PDFLaTeX + string format; + switch (features.flavor()) { + case OutputParams::LATEX: + format = "LaTeX"; + break; + case OutputParams::PDFLATEX: + format = "PDFLaTeX"; + break; + case OutputParams::XML: + format = "DocBook"; + break; + } external::Template::Formats::const_iterator cit = - et.formats.find("LaTeX"); + et.formats.find(format); if (cit == et.formats.end()) return; Index: src/insets/insetgraphics.C =================================================================== --- src/insets/insetgraphics.C (Revision 13511) +++ src/insets/insetgraphics.C (Arbeitskopie) @@ -607,6 +607,8 @@ string const InsetGraphics::prepareFile( params().filename.outputFilename(m_buffer->filePath()) : OnlyFilename(temp_file)); string const source_file = runparams.nice ? orig_file : temp_file; + string const tex_format = (runparams.flavor == OutputParams::LATEX) ? + "latex" : "pdflatex"; if (zipped) { if (params().noUnzip) { @@ -619,7 +621,7 @@ string const InsetGraphics::prepareFile( string const bb_orig_file = ChangeExtension(orig_file, "bb"); if (runparams.nice) { - runparams.exportdata->addExternalFile("latex", + runparams.exportdata->addExternalFile(tex_format, bb_orig_file, ChangeExtension(output_file, "bb")); } else { @@ -630,10 +632,10 @@ string const InsetGraphics::prepareFile( copyFileIfNeeded(bb_orig_file, bb_file); if (status == FAILURE) return orig_file; - runparams.exportdata->addExternalFile("latex", + runparams.exportdata->addExternalFile(tex_format, bb_file); } - runparams.exportdata->addExternalFile("latex", + runparams.exportdata->addExternalFile(tex_format, source_file, output_file); runparams.exportdata->addExternalFile("dvi", source_file, output_file); @@ -678,7 +680,7 @@ string const InsetGraphics::prepareFile( if (from == to) { // The extension of temp_file might be != ext! - runparams.exportdata->addExternalFile("latex", source_file, + runparams.exportdata->addExternalFile(tex_format, source_file, output_file); runparams.exportdata->addExternalFile("dvi", source_file, output_file); @@ -695,7 +697,7 @@ string const InsetGraphics::prepareFile( << bformat(_("No conversion of %1$s is needed after all"), rel_file) << std::endl; - runparams.exportdata->addExternalFile("latex", to_file, + runparams.exportdata->addExternalFile(tex_format, to_file, output_to_file); runparams.exportdata->addExternalFile("dvi", to_file, output_to_file); @@ -709,7 +711,7 @@ string const InsetGraphics::prepareFile( << "\t from " << from << " to " << to << '\n'; if (converters.convert(&buf, temp_file, temp_file, from, to, true)) { - runparams.exportdata->addExternalFile("latex", + runparams.exportdata->addExternalFile(tex_format, to_file, output_to_file); runparams.exportdata->addExternalFile("dvi", to_file, output_to_file); Index: src/insets/insetinclude.C =================================================================== --- src/insets/insetinclude.C (Revision 13511) +++ src/insets/insetinclude.C (Arbeitskopie) @@ -407,11 +407,13 @@ int InsetInclude::latex(Buffer const & b } } + string const tex_format = (runparams.flavor == OutputParams::LATEX) ? + "latex" : "pdflatex"; if (isVerbatim(params_)) { incfile = latex_path(incfile); os << '\\' << params_.getCmdName() << '{' << incfile << '}'; } else if (type(params_) == INPUT) { - runparams.exportdata->addExternalFile("latex", writefile, + runparams.exportdata->addExternalFile(tex_format, writefile, exportfile); // \input wants file with extension (default is .tex) @@ -426,7 +428,7 @@ int InsetInclude::latex(Buffer const & b << '}'; } } else { - runparams.exportdata->addExternalFile("latex", writefile, + runparams.exportdata->addExternalFile(tex_format, writefile, exportfile); // \include don't want extension and demands that the Index: src/BufferView_pimpl.C =================================================================== --- src/BufferView_pimpl.C (Revision 13511) +++ src/BufferView_pimpl.C (Arbeitskopie) @@ -1072,7 +1072,8 @@ FuncStatus BufferView::Pimpl::getStatus( break; case LFUN_OUTPUT_CHANGES: { - LaTeXFeatures features(*buffer_, buffer_->params(), false); + OutputParams runparams; + LaTeXFeatures features(*buffer_, buffer_->params(), runparams); flag.enabled(buffer_ && buffer_->params().tracking_changes && features.isAvailable("dvipost")); flag.setOnOff(buffer_->params().output_changes); Index: src/paragraph_pimpl.C =================================================================== --- src/paragraph_pimpl.C (Revision 13511) +++ src/paragraph_pimpl.C (Arbeitskopie) @@ -531,7 +531,7 @@ void Paragraph::Pimpl::simpleTeXSpecialC // output change tracking marks only if desired, // if dvipost is installed, // and with dvi/ps (other formats don't work) - LaTeXFeatures features(buf, bparams, runparams.nice); + LaTeXFeatures features(buf, bparams, runparams); bool const output = bparams.output_changes && runparams.flavor == OutputParams::LATEX && features.isAvailable("dvipost"); Index: src/exporter.C =================================================================== --- src/exporter.C (Revision 13511) +++ src/exporter.C (Arbeitskopie) @@ -58,8 +58,12 @@ namespace { vector<string> const Backends(Buffer const & buffer) { vector<string> v; - if (buffer.params().getLyXTextClass().isTeXClassAvailable()) + if (buffer.params().getLyXTextClass().isTeXClassAvailable()) { v.push_back(BufferFormat(buffer)); + // FIXME: Don't hardcode format names here, but use a flag + if (v.back() == "latex") + v.push_back("pdflatex"); + } v.push_back("text"); v.push_back("lyx"); return v; @@ -169,8 +173,12 @@ bool Exporter::Export(Buffer * buffer, s formats.prettyName(format))); return false; } - } else + } else { backend_format = format; + // FIXME: Don't hardcode format names here, but use a flag + if (backend_format == "pdflatex") + runparams.flavor = OutputParams::PDFLATEX; + } string filename = buffer->getLatexName(false); filename = AddName(buffer->temppath(), filename); Index: src/LaTeXFeatures.h =================================================================== --- src/LaTeXFeatures.h (Revision 13511) +++ src/LaTeXFeatures.h (Arbeitskopie) @@ -14,6 +14,8 @@ #define LATEXFEATURES_H +#include "outputparams.h" + #include <set> #include <list> #include <map> @@ -39,7 +41,8 @@ class Language; class LaTeXFeatures { public: /// - LaTeXFeatures(Buffer const &, BufferParams const &, bool); + LaTeXFeatures(Buffer const &, BufferParams const &, + OutputParams const &); /// The packages needed by the document std::string const getPackages() const; /// The macros definitions needed by the document @@ -88,8 +91,14 @@ public: BufferParams const & bufferParams() const; /// the return value is dependent upon both LyXRC and LaTeXFeatures. bool useBabel() const; - /// - bool nice() const { return nice_; }; + /** If we are writing a nice LaTeX file or not. + * Only needed by InsetInclude::validate(). + */ + bool nice() const { return runparams_.nice; } + /** The latex that we export depends occasionally on what is to + * compile the file. + */ + OutputParams::FLAVOR flavor() const { return runparams_.flavor; } private: std::list<std::string> usedLayouts_; @@ -124,10 +133,10 @@ private: Buffer const * buffer_; /// BufferParams const & params_; - /** If we are writing a nice LaTeX file or not. - * Only needed by InsetInclude::validate(). + /** Some insets need to know details about the to-be-produced file + * in validate(). */ - bool nice_; + OutputParams const & runparams_; }; #endif Index: src/buffer.C =================================================================== --- src/buffer.C (Revision 13511) +++ src/buffer.C (Arbeitskopie) @@ -833,7 +833,7 @@ void Buffer::makeLaTeXFile(ostream & os, // validate the buffer. lyxerr[Debug::LATEX] << " Validating buffer..." << endl; - LaTeXFeatures features(*this, params(), runparams.nice); + LaTeXFeatures features(*this, params(), runparams); validate(features); lyxerr[Debug::LATEX] << " Buffer validation done." << endl; @@ -986,7 +986,7 @@ void Buffer::makeLinuxDocFile(string con if (!openFileWrite(ofs, fname)) return; - LaTeXFeatures features(*this, params(), runparams.nice); + LaTeXFeatures features(*this, params(), runparams); validate(features); texrow().reset(); @@ -1044,7 +1044,7 @@ void Buffer::makeDocBookFile(string cons if (!openFileWrite(ofs, fname)) return; - LaTeXFeatures features(*this, params(), runparams.nice); + LaTeXFeatures features(*this, params(), runparams); validate(features); texrow().reset(); Index: src/paragraph.C =================================================================== --- src/paragraph.C (Revision 13511) +++ src/paragraph.C (Arbeitskopie) @@ -885,7 +885,7 @@ bool Paragraph::simpleTeXOnePar(Buffer c LyXFont basefont; - LaTeXFeatures features(buf, bparams, runparams.nice); + LaTeXFeatures features(buf, bparams, runparams); // output change tracking marks only if desired, // if dvipost is installed, Index: lib/external_templates =================================================================== --- lib/external_templates (Revision 13511) +++ lib/external_templates (Arbeitskopie) @@ -82,7 +82,7 @@ Template RasterImage UpdateFormat png UpdateResult "$$AbsPath$$Basename.png" Requirement "graphicx" - ReferencedFile latex "$$AbsPath$$Basename.png" + ReferencedFile pdflatex "$$AbsPath$$Basename.png" FormatEnd Format Ascii Product "$$Contents(\"$$AbsPath$$Basename.asc\")" @@ -134,8 +134,8 @@ Template XFig Requirement "graphicx" # Preamble WarnNotFound # Preamble InputOrWarn - ReferencedFile latex "$$AbsOrRelPathMaster$$Basename.pdftex_t" - ReferencedFile latex "$$AbsPath$$Basename.pdf" + ReferencedFile pdflatex "$$AbsOrRelPathMaster$$Basename.pdftex_t" + ReferencedFile pdflatex "$$AbsPath$$Basename.pdf" FormatEnd Format Ascii Product "$$Contents(\"$$AbsPath$$Basename.asc\")" @@ -184,6 +184,11 @@ Template ChessDiagram Requirement "chess" ReferencedFile latex "$$AbsPath$$Basename$$Extension" FormatEnd + Format PDFLaTeX + Product "\\loadgame{$$AbsOrRelPathMaster$$Basename}\\showboard" + Requirement "chess" + ReferencedFile pdflatex "$$AbsPath$$Basename$$Extension" + FormatEnd Format Ascii Product "$$Contents(\"$$AbsPath$$Basename.asc\")" UpdateFormat asciichess @@ -212,6 +217,11 @@ Template Date UpdateFormat dateout UpdateResult "$$Tempname" FormatEnd + Format PDFLaTeX + Product "$$Contents(\"$$Tempname\")" + UpdateFormat dateout + UpdateResult "$$Tempname" + FormatEnd Format Ascii Product "$$Contents(\"$$Tempname\")" UpdateFormat dateout Index: lib/configure.py =================================================================== --- lib/configure.py (Revision 13511) +++ lib/configure.py (Arbeitskopie) @@ -224,7 +224,7 @@ if LATEX != 'none': removeFiles(['chklatex.ltx', 'chklatex.log']) checkProg('the pdflatex program', ['pdflatex $$i'], - rc_entry = [ r'\converter latex pdf2 "%%" "latex"' ]) + rc_entry = [ r'\converter pdflatex pdf2 "%%" "latex"' ]) checkProg('a Tgif viewer and editor', ['tgif'], rc_entry = [ r'\Format tgif obj Tgif "" "%%" "%%"']) @@ -262,8 +262,9 @@ checkProg('a text editor', ['xemacs', 'g \Format docbook sgml DocBook B "" "%%" \Format docbook-xml xml "Docbook (XML)" "" "" "%%" \Format literate nw NoWeb N "" "%%" -\Format latex tex LaTeX L "" "%%" +\Format latex tex "TeX (latex)" L "" "%%" \Format linuxdoc sgml LinuxDoc x "" "%%" +\Format pdflatex tex "TeX (pdflatex)" "" "" "%%" \Format text txt "Plain text" a "" "%%" \Format textparagraph txt "Plain text (paragraphs)" "" "" "%%"''' ])