]> git.lyx.org Git - features.git/commitdiff
Use TeXOnePar for the inpreamble layouts
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 26 Dec 2017 12:11:00 +0000 (13:11 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 26 Dec 2017 12:11:00 +0000 (13:11 +0100)
This considers paragraph language and spacing (and simplifies the code)

src/Paragraph.cpp
src/output_latex.cpp
src/output_latex.h

index c37220effc402ec6155e20329968bdd25d957403..abb2768d756601b0f12283c0fa1399d319578bdb 100644 (file)
@@ -1440,40 +1440,17 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
        BufferParams const & bp = features.runparams().is_child
                ? buf.masterParams() : buf.params();
        if (layout_->inpreamble && inset_owner_) {
-               bool const is_command = layout_->latextype == LATEX_COMMAND;
-               Font f;
-               // Using a string stream here circumvents the encoding
+               // FIXME: Using a string stream here circumvents the encoding
                // switching machinery of odocstream. Therefore the
                // output is wrong if this paragraph contains content
                // that needs to switch encoding.
                otexstringstream os;
                os << layout_->preamble();
-               if (is_command) {
-                       os << '\\' << 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_->latexargs().empty()) {
-                               OutputParams rp = features.runparams();
-                               rp.local_font = &owner_->getFirstFontSettings(bp);
-                               latexArgInsets(*owner_, os, rp, layout_->latexargs());
-                       }
-                       os << from_ascii(layout_->latexparam());
-               }
                size_t const length = os.length();
-               // this will output "{" at the beginning, but not at the end
-               owner_->latex(bp, f, os, features.runparams(), 0, -1, true);
-               if (os.length() > length) {
-                       if (is_command) {
-                               os << '}';
-                               if (!layout_->postcommandargs().empty()) {
-                                       OutputParams rp = features.runparams();
-                                       rp.local_font = &owner_->getFirstFontSettings(bp);
-                                       latexArgInsets(*owner_, os, rp, layout_->postcommandargs(), "post:");
-                               }
-                       }
+               TeXOnePar(buf, buf.text(), buf.getParFromID(owner_->id()).pit(), os,
+                         features.runparams(), string(), 0, -1, true);
+               if (os.length() > length)
                        features.addPreambleSnippet(os.release(), true);
-               }
        }
 
        if (features.runparams().flavor == OutputParams::HTML
@@ -2426,7 +2403,7 @@ void Paragraph::latex(BufferParams const & bparams,
        if (empty()) {
                // For InTitle commands, we have already opened a group
                // in output_latex::TeXOnePar.
-               if (style.isCommand() && (!style.intitle || style.inpreamble)) {
+               if (style.isCommand() && !style.intitle) {
                        os << '{';
                        ++column;
                }
@@ -2466,7 +2443,7 @@ void Paragraph::latex(BufferParams const & bparams,
                        }
                        // For InTitle commands, we have already opened a group
                        // in output_latex::TeXOnePar.
-                       if (style.isCommand() && (!style.intitle || style.inpreamble)) {
+                       if (style.isCommand() && !style.intitle) {
                                os << '{';
                                ++column;
                        }
index 5cac0ad89f96c9d0a5e5381dc96506a7314f7035..f8bb1519546e3b0ab0d9cd892c09af4c43e1d02b 100644 (file)
@@ -683,7 +683,8 @@ void TeXOnePar(Buffer const & buf,
               otexstream & os,
               OutputParams const & runparams_in,
               string const & everypar,
-              int start_pos, int end_pos)
+              int start_pos, int end_pos,
+              bool const force)
 {
        BufferParams const & bparams = runparams_in.is_child
                ? buf.masterParams() : buf.params();
@@ -694,7 +695,7 @@ void TeXOnePar(Buffer const & buf,
        Layout const & style = text.inset().forcePlainLayout() ?
                bparams.documentClass().plainLayout() : par.layout();
 
-       if (style.inpreamble)
+       if (style.inpreamble && !force)
                return;
 
        LYXERR(Debug::LATEX, "TeXOnePar for paragraph " << pit << " ptr " << &par << " '"
@@ -728,7 +729,7 @@ void TeXOnePar(Buffer const & buf,
                                os << '\n';
                }
 
-               par.latex(bparams, outerfont, os, runparams, start_pos, end_pos);
+               par.latex(bparams, outerfont, os, runparams, start_pos, end_pos, force);
                return;
        }
 
@@ -739,7 +740,7 @@ void TeXOnePar(Buffer const & buf,
                Font const outerfont = text.outerFont(pit);
                parStartCommand(par, os, runparams, style);
 
-               par.latex(bparams, outerfont, os, runparams, start_pos, end_pos);
+               par.latex(bparams, outerfont, os, runparams, start_pos, end_pos, force);
 
                // I did not create a parEndCommand for this minuscule
                // task because in the other user of parStartCommand
@@ -1015,7 +1016,7 @@ void TeXOnePar(Buffer const & buf,
 
        // FIXME UNICODE
        os << from_utf8(everypar);
-       par.latex(bparams, outerfont, os, runparams, start_pos, end_pos);
+       par.latex(bparams, outerfont, os, runparams, start_pos, end_pos, force);
 
        Font const font = par.empty()
                 ? par.getLayoutFont(bparams, outerfont)
index 1dd96898511e3ea078d715a11db7460d87db3988..cf37173604b2b03bd4daa4447fd774f16532ba72 100644 (file)
@@ -91,7 +91,8 @@ void TeXOnePar(Buffer const & buf,
                   otexstream & os,
                   OutputParams const & runparams,
                   std::string const & everypar = std::string(),
-                  int start_pos = -1, int end_pos = -1);
+                  int start_pos = -1, int end_pos = -1,
+                  bool const force = false);
 
 } // namespace lyx