Allow literate documents other than noweb to work out of the box. Currently

only sweave is supported (for building documentation, not programs).

Layout files allow a new OutputFormat tag 

Modules can be conditionned on a feature of the type from->to, indicating that
it should be possible to convert from format 'from' to format 'to'.

Layout format incremented to 15.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29874 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2009-05-28 08:59:25 +00:00
parent 863b102f87
commit 864773d7d9
9 changed files with 428 additions and 108 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
#\DeclareLyXModule[noweb.sty]{Noweb literate programming} #\DeclareLyXModule[literate->latex,noweb.sty]{Noweb literate programming}
#DescriptionBegin #DescriptionBegin
#Allows to use Noweb as a literate programming tool. #Allows to use Noweb as a literate programming tool.
#DescriptionEnd #DescriptionEnd

View File

@ -1,4 +1,4 @@
#\DeclareLyXModule[Sweave.sty]{Sweave - S/R literate programming} #\DeclareLyXModule[sweave->latex]{Sweave - S/R literate programming}
#DescriptionBegin #DescriptionBegin
#Allows to use the statistical language S/R as a literate programming tool - Sweave. #Allows to use the statistical language S/R as a literate programming tool - Sweave.
#DescriptionEnd #DescriptionEnd
@ -11,7 +11,7 @@
Format 11 Format 11
OutputType literate OutputType literate
#OutputFormat sweave OutputFormat sweave
Style Chunk Style Chunk
Category Sweave Category Sweave

View File

@ -48,10 +48,14 @@ import os, re, string, sys
# Incremented to format 14, 14 February 2009 by gb # Incremented to format 14, 14 February 2009 by gb
# Rename I18NPreamble to BabelPreamble and add LangPreamble # Rename I18NPreamble to BabelPreamble and add LangPreamble
# Incremented to format 15, 28 May 2009 by lasgouttes
# Add new tag OutputFormat; modules can be conditionned on feature
# "from->to".
# Do not forget to document format change in Customization # Do not forget to document format change in Customization
# Manual (section "Declaring a new text class"). # Manual (section "Declaring a new text class").
currentFormat = 14 currentFormat = 15
def usage(prog_name): def usage(prog_name):
@ -227,6 +231,11 @@ def convert(lines):
i += 1 i += 1
continue continue
# This just involved new features, not any changes to old ones
if format == 14:
i += 1
continue
# Rename I18NPreamble to BabelPreamble # Rename I18NPreamble to BabelPreamble
if format == 13: if format == 13:
match = re_I18nPreamble.match(lines[i]) match = re_I18nPreamble.match(lines[i])

View File

@ -459,10 +459,12 @@ string Buffer::logName(LogType * type) const
FileName const fname(addName(temppath(), FileName const fname(addName(temppath(),
onlyFilename(changeExtension(filename, onlyFilename(changeExtension(filename,
".log")))); ".log"))));
// FIXME: how do we know this is the name of the build log?
FileName const bname( FileName const bname(
addName(path, onlyFilename( addName(path, onlyFilename(
changeExtension(filename, changeExtension(filename,
formats.extension("literate") + ".out")))); formats.extension(bufferFormat()) + ".out"))));
// If no Latex log or Build log is newer, show Build log // If no Latex log or Build log is newer, show Build log
@ -2662,15 +2664,14 @@ void Buffer::autoSave() const
string Buffer::bufferFormat() const string Buffer::bufferFormat() const
{ {
if (isDocBook()) string format = params().documentClass().outputFormat();
return "docbook"; if (format == "latex") {
if (isLiterate()) if (params().useXetex)
return "literate"; return "xetex";
if (params().useXetex) if (params().encoding().package() == Encoding::japanese)
return "xetex"; return "platex";
if (params().encoding().package() == Encoding::japanese) }
return "platex"; return format;
return "latex";
} }

View File

@ -19,6 +19,7 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "ColorSet.h" #include "ColorSet.h"
#include "Converter.h"
#include "Encoding.h" #include "Encoding.h"
#include "Floating.h" #include "Floating.h"
#include "FloatList.h" #include "FloatList.h"
@ -370,6 +371,14 @@ bool LaTeXFeatures::mustProvide(string const & name) const
bool LaTeXFeatures::isAvailable(string const & name) bool LaTeXFeatures::isAvailable(string const & name)
{ {
string::size_type const i = name.find("->");
if (i != string::npos) {
string const from = name.substr(0,i);
string const to = name.substr(i+2);
LYXERR0("from=[" << from << "] to=[" << to << "]");
return theConverters().isReachable(from, to);
}
if (packages_.empty()) if (packages_.empty())
getAvailable(); getAvailable();
string n = name; string n = name;

View File

@ -62,7 +62,7 @@ private:
}; };
// Keep the changes documented in the Customization manual. // Keep the changes documented in the Customization manual.
int const FORMAT = 14; int const FORMAT = 15;
bool layout2layout(FileName const & filename, FileName const & tempfile) bool layout2layout(FileName const & filename, FileName const & tempfile)
@ -127,6 +127,7 @@ InsetLayout DocumentClass::plain_insetlayout_;
TextClass::TextClass() TextClass::TextClass()
{ {
outputType_ = LATEX; outputType_ = LATEX;
outputFormat_ = "latex";
columns_ = 1; columns_ = 1;
sides_ = OneSide; sides_ = OneSide;
secnumdepth_ = 3; secnumdepth_ = 3;
@ -160,6 +161,7 @@ bool TextClass::readStyle(Lexer & lexrc, Layout & lay) const
enum TextClassTags { enum TextClassTags {
TC_OUTPUTTYPE = 1, TC_OUTPUTTYPE = 1,
TC_OUTPUTFORMAT,
TC_INPUT, TC_INPUT,
TC_STYLE, TC_STYLE,
TC_DEFAULTSTYLE, TC_DEFAULTSTYLE,
@ -208,6 +210,7 @@ namespace {
{ "leftmargin", TC_LEFTMARGIN }, { "leftmargin", TC_LEFTMARGIN },
{ "nofloat", TC_NOFLOAT }, { "nofloat", TC_NOFLOAT },
{ "nostyle", TC_NOSTYLE }, { "nostyle", TC_NOSTYLE },
{ "outputformat", TC_OUTPUTFORMAT },
{ "outputtype", TC_OUTPUTTYPE }, { "outputtype", TC_OUTPUTTYPE },
{ "pagestyle", TC_PAGESTYLE }, { "pagestyle", TC_PAGESTYLE },
{ "preamble", TC_PREAMBLE }, { "preamble", TC_PREAMBLE },
@ -352,8 +355,24 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
format = lexrc.getInteger(); format = lexrc.getInteger();
break; break;
case TC_OUTPUTTYPE: // output type definition case TC_OUTPUTFORMAT:
if (lexrc.next())
outputFormat_ = lexrc.getString();
break;
case TC_OUTPUTTYPE:
readOutputType(lexrc); readOutputType(lexrc);
switch(outputType_) {
case LATEX:
outputFormat_ = "latex";
break;
case DOCBOOK:
outputFormat_ = "docbook";
break;
case LITERATE:
outputFormat_ = "literate";
break;
}
break; break;
case TC_INPUT: // Include file case TC_INPUT: // Include file

View File

@ -191,6 +191,8 @@ public:
std::string const & latexname() const { return latexname_; } std::string const & latexname() const { return latexname_; }
/// Can be LaTeX, DocBook, etc. /// Can be LaTeX, DocBook, etc.
OutputType outputType() const { return outputType_; } OutputType outputType() const { return outputType_; }
/// Can be latex, docbook ... (the name of a format)
std::string outputFormat() const { return outputFormat_; }
protected: protected:
/// Protect construction /// Protect construction
TextClass(); TextClass();
@ -272,6 +274,8 @@ protected:
int tocdepth_; int tocdepth_;
/// Can be LaTeX, DocBook, etc. /// Can be LaTeX, DocBook, etc.
OutputType outputType_; OutputType outputType_;
/// Can be latex, docbook ... (the name of a format)
std::string outputFormat_;
/** Base font. The paragraph and layout fonts are resolved against /** Base font. The paragraph and layout fonts are resolved against
this font. This has to be fully instantiated. Attributes this font. This has to be fully instantiated. Attributes
FONT_INHERIT, FONT_IGNORE, and FONT_TOGGLE are FONT_INHERIT, FONT_IGNORE, and FONT_TOGGLE are
@ -406,8 +410,6 @@ public:
int max_toclevel() const { return max_toclevel_; } int max_toclevel() const { return max_toclevel_; }
/// returns true if the class has a ToC structure /// returns true if the class has a ToC structure
bool hasTocLevels() const; bool hasTocLevels() const;
/// Can be LaTeX, DocBook, etc.
OutputType outputType() const { return outputType_; }
protected: protected:
/// Constructs a DocumentClass based upon a LayoutFile. /// Constructs a DocumentClass based upon a LayoutFile.
DocumentClass(LayoutFile const & tc); DocumentClass(LayoutFile const & tc);

View File

@ -150,6 +150,7 @@ bool GuiLog::initialiseParams(string const & data)
if (logtype == "latex") if (logtype == "latex")
type_ = LatexLog; type_ = LatexLog;
// FIXME: not sure "literate" still works.
else if (logtype == "literate") else if (logtype == "literate")
type_ = LiterateLog; type_ = LiterateLog;
else if (logtype == "lyx2lyx") else if (logtype == "lyx2lyx")