]> git.lyx.org Git - features.git/commitdiff
algorithm2e.module: Add Algorithm style to typeset algorithms
authorGuillaume MM <gm@lyx.org>
Fri, 5 May 2017 21:48:20 +0000 (23:48 +0200)
committerGuillaume MM <gm@lyx.org>
Tue, 9 May 2017 22:03:04 +0000 (00:03 +0200)
Do not output \begin and \end if there is not environment name. We only need the
nesting feature.

lib/layouts/algorithm2e.module
src/output_latex.cpp

index 94298175da4bffbdd5199bf0bcb147a444602acc..2a795ced8ae09cac561799d1064ce5c990732eca 100644 (file)
@@ -1,7 +1,8 @@
 #\DeclareLyXModule[algorithm2e.sty]{Algorithm2e}
 #DescriptionBegin
 # Use the algorithm2e package for algorithm floats rather
-# than LyX's home-brewed algorithm floats.
+# than LyX's home-brewed algorithm floats. Use the Algorithm
+# style to enter and indent the algorithm.
 #DescriptionEnd
 #
 #Author: Jürgen Spitzmüller
@@ -26,3 +27,14 @@ Float
        RefPrefix             alg
 End
 
+Style Algorithm
+  Category              List
+  Margin                Static
+  LatexType             Environment
+  NextNoIndent          1
+  ParbreakIsNewline     1
+  ToggleIndent          Never
+  KeepEmpty             1
+  LeftMargin            MM
+  Align                 Left
+End
index 7db9e7c52b58f7e0debb00d1ef702f5ecd9241fe..c8a6bc4ee9f343822fb5a5cf0ddf6d1e0948756b 100644 (file)
@@ -258,8 +258,10 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf,
                data.leftindent_open = true;
        }
 
-       if (style.isEnvironment()) {
+       if (style.isEnvironment())
                state->nest_level_ += 1;
+
+       if (style.isEnvironment() && !style.latexname().empty()) {
                os << "\\begin{" << from_ascii(style.latexname()) << '}';
                if (!style.latexargs().empty()) {
                        OutputParams rp = runparams;
@@ -324,7 +326,9 @@ static void finishEnvironment(otexstream & os, OutputParams const & runparams,
                        }
                }
                state->nest_level_ -= 1;
-               os << "\\end{" << from_ascii(data.style->latexname()) << "}\n";
+               string const & name = data.style->latexname();
+               if (!name.empty())
+                       os << "\\end{" << from_ascii(name) << "}\n";
                state->prev_env_language_ = data.par_language;
                if (runparams.encoding != data.prev_encoding) {
                        runparams.encoding = data.prev_encoding;