From a61899ffe74c5eae21dda9d23a2a4d08d516a4d6 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sun, 28 Nov 2010 22:08:11 +0000 Subject: [PATCH] Allow InPreamble to be used with Paragraph-type environments. There is no reason not to permit this, and using it with PassThru 1 allows for a very simple Preamble layout-type that acts as ERT for the premable. Of course, we do have the preamble in Document>Settings, but that allows the embedding of preamble code in branches. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36562 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/doc/Customization.lyx | 23 +++++++++++++++++++++-- src/Layout.cpp | 4 ++-- src/Paragraph.cpp | 24 ++++++++++++++---------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index 2f76dadb26..1c192d9c3f 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -1,5 +1,5 @@ #LyX 2.0.0svn created this file. For more info see http://www.lyx.org/ -\lyxformat 404 +\lyxformat 410 \begin_document \begin_header \textclass scrbook @@ -76,7 +76,7 @@ End \font_sans default \font_typewriter default \font_default_family default -\use_xetex false +\use_non_tex_fonts false \font_sc false \font_osf false \font_sf_scale 100 @@ -138,6 +138,7 @@ End \html_math_output 0 \html_be_strict true \author 1 "Jean-Marc Lasgouttes" +\author 223010757 "Richard Heck" rgheck@brown.edu \end_header \begin_body @@ -10181,6 +10182,24 @@ Command \end_inset + +\change_inserted 223010757 1290981996 + or +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted 223010757 1290981998 +Paragraph +\change_unchanged + +\end_layout + +\end_inset + + +\change_unchanged . \end_layout diff --git a/src/Layout.cpp b/src/Layout.cpp index 5ba77ce1c6..cdfc1746b9 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -577,8 +577,8 @@ bool Layout::read(Lexer & lex, TextClass const & tclass) } lex.popTable(); // make sure we only have inpreamble = true for commands - if (inpreamble && latextype != LATEX_COMMAND) { - LYXERR0("InPreamble not permitted except with Command-type layouts."); + if (inpreamble && latextype != LATEX_COMMAND && latextype != LATEX_PARAGRAPH) { + LYXERR0("InPreamble not permitted except with command and paragraph layouts."); LYXERR0("Layout name: " << name()); inpreamble = false; } diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 3eb13ec0d1..4d31441d4f 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -1328,6 +1328,7 @@ bool Paragraph::Private::latexSpecialPhrase(odocstream & os, pos_type & i, void Paragraph::Private::validate(LaTeXFeatures & features) const { if (layout_->inpreamble && inset_owner_) { + bool const is_command = layout_->latextype == LATEX_COMMAND; Buffer const & buf = inset_owner_->buffer(); BufferParams const & bp = buf.params(); Font f; @@ -1337,20 +1338,23 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const // output is wrong if this paragraph contains content // that needs to switch encoding. odocstringstream ods; - ods << '\\' << from_ascii(layout_->latexname()); - // we have to provide all the optional arguments here, even though - // the last one is the only one we care about. - // Separate handling of optional argument inset. - if (layout_->optargs != 0 || layout_->reqargs != 0) - latexArgInsets(*owner_, ods, features.runparams(), - layout_->reqargs, layout_->optargs); - else - ods << from_ascii(layout_->latexparam()); + if (is_command) { + ods << '\\' << from_ascii(layout_->latexname()); + // we have to provide all the optional arguments here, even though + // the last one is the only one we care about. + // Separate handling of optional argument inset. + if (layout_->optargs != 0 || layout_->reqargs != 0) + latexArgInsets(*owner_, ods, features.runparams(), + layout_->reqargs, layout_->optargs); + else + ods << from_ascii(layout_->latexparam()); + } docstring::size_type const length = ods.str().length(); // this will output "{" at the beginning, but not at the end owner_->latex(bp, f, ods, tr, features.runparams(), 0, -1, true); if (ods.str().length() > length) { - ods << '}'; + if (is_command) + ods << '}'; string const snippet = to_utf8(ods.str()); features.addPreambleSnippet(snippet); }