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.
This commit is contained in:
Guillaume MM 2017-05-05 23:48:20 +02:00
parent 517cd50e05
commit 5452c53e9b
2 changed files with 19 additions and 3 deletions

View 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

View 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;