From 5452c53e9b336565fe2a1c7fa59d38edc43e0c9f Mon Sep 17 00:00:00 2001 From: Guillaume MM Date: Fri, 5 May 2017 23:48:20 +0200 Subject: [PATCH] algorithm2e.module: Add Algorithm style to typeset algorithms Do not output \begin and \end if there is not environment name. We only need the nesting feature. --- lib/layouts/algorithm2e.module | 14 +++++++++++++- src/output_latex.cpp | 8 ++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/layouts/algorithm2e.module b/lib/layouts/algorithm2e.module index 94298175da..2a795ced8a 100644 --- a/lib/layouts/algorithm2e.module +++ b/lib/layouts/algorithm2e.module @@ -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 diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 7db9e7c52b..c8a6bc4ee9 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -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; -- 2.39.2