mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Move spacing code around (and fix a bug)
* LaTeXFeatures.cpp (getPackages): remove some specific spacing code; move listings support to simplefeatures array. * src/Spacing.cpp (writeEnvirBegin, writeEnvirEnd): code factorization (writePreamble): new method containing former code from LaTeXFeatures; use \setSpacing instead of \setSingleSpacing. * src/BufferParams.cpp (validate, writeLaTeX): handle spacing here. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22644 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
385ae43b39
commit
0df54152bc
@ -863,6 +863,10 @@ void BufferParams::validate(LaTeXFeatures & features) const
|
|||||||
if (use_esint == package_on)
|
if (use_esint == package_on)
|
||||||
features.require("esint");
|
features.require("esint");
|
||||||
|
|
||||||
|
// Document-level line spacing
|
||||||
|
if (spacing().getSpace() != Spacing::Single && !spacing().isDefault())
|
||||||
|
features.require("setspace");
|
||||||
|
|
||||||
// the bullet shapes are buffer level not paragraph level
|
// the bullet shapes are buffer level not paragraph level
|
||||||
// so they are tested here
|
// so they are tested here
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
@ -1206,6 +1210,9 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
|
|||||||
// The optional packages;
|
// The optional packages;
|
||||||
docstring lyxpreamble(from_ascii(features.getPackages()));
|
docstring lyxpreamble(from_ascii(features.getPackages()));
|
||||||
|
|
||||||
|
// Line spacing
|
||||||
|
lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace")));
|
||||||
|
|
||||||
// We try to load babel late, in case it interferes
|
// We try to load babel late, in case it interferes
|
||||||
// with other packages. But some packages also need babel to be loaded
|
// with other packages. But some packages also need babel to be loaded
|
||||||
// before, e.g. jurabib has to be called after babel.
|
// before, e.g. jurabib has to be called after babel.
|
||||||
|
@ -544,7 +544,8 @@ char const * simplefeatures[] = {
|
|||||||
"enumitem",
|
"enumitem",
|
||||||
"endnotes",
|
"endnotes",
|
||||||
"ifthen",
|
"ifthen",
|
||||||
"amsthm"
|
"amsthm",
|
||||||
|
"listings"
|
||||||
};
|
};
|
||||||
|
|
||||||
int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
|
int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
|
||||||
@ -652,30 +653,8 @@ string const LaTeXFeatures::getPackages() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setspace.sty
|
// setspace.sty
|
||||||
if ((isRequired("setspace")
|
if (mustProvide("setspace") && !tclass.provides("SetSpace"))
|
||||||
|| ((params_.spacing().getSpace() != Spacing::Single
|
|
||||||
&& !params_.spacing().isDefault())))
|
|
||||||
&& !tclass.provides("SetSpace")) {
|
|
||||||
packages << "\\usepackage{setspace}\n";
|
packages << "\\usepackage{setspace}\n";
|
||||||
}
|
|
||||||
bool const upcase = tclass.provides("SetSpace");
|
|
||||||
switch (params_.spacing().getSpace()) {
|
|
||||||
case Spacing::Default:
|
|
||||||
case Spacing::Single:
|
|
||||||
// we dont use setspace.sty so dont print anything
|
|
||||||
//packages += "\\singlespacing\n";
|
|
||||||
break;
|
|
||||||
case Spacing::Onehalf:
|
|
||||||
packages << (upcase ? "\\OnehalfSpacing\n" : "\\onehalfspacing\n");
|
|
||||||
break;
|
|
||||||
case Spacing::Double:
|
|
||||||
packages << (upcase ? "\\DoubleSpacing\n" : "\\doublespacing\n");
|
|
||||||
break;
|
|
||||||
case Spacing::Other:
|
|
||||||
packages << (upcase ? "\\setSingleSpace{" : "\\setstretch{")
|
|
||||||
<< params_.spacing().getValue() << "}\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// amssymb.sty
|
// amssymb.sty
|
||||||
if (mustProvide("amssymb")
|
if (mustProvide("amssymb")
|
||||||
@ -724,9 +703,6 @@ string const LaTeXFeatures::getPackages() const
|
|||||||
"\\makenomenclature\n";
|
"\\makenomenclature\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mustProvide("listings"))
|
|
||||||
packages << "\\usepackage{listings}\n";
|
|
||||||
|
|
||||||
return packages.str();
|
return packages.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
#include "support/convert.h"
|
#include "support/convert.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <ostream>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -89,50 +88,59 @@ void Spacing::writeFile(ostream & os, bool para) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
string envName(Spacing::Space space, bool useSetSpace)
|
||||||
|
{
|
||||||
|
static char const * const env_names[]
|
||||||
|
= { "SingleSpace", "OnehalfSpace", "DoubleSpace", "Spacing", ""};
|
||||||
|
string const name = env_names[space];
|
||||||
|
|
||||||
|
return useSetSpace ? name : support::ascii_lowercase(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
string const Spacing::writeEnvirBegin(bool useSetSpace) const
|
string const Spacing::writeEnvirBegin(bool useSetSpace) const
|
||||||
{
|
{
|
||||||
switch (space) {
|
string const name = envName(space, useSetSpace);
|
||||||
case Default: break; // do nothing
|
if (space == Other)
|
||||||
case Single:
|
return "\\begin{" + name + "}{" + getValueAsString() + '}';
|
||||||
return (useSetSpace ? "\\begin{SingleSpace}"
|
else
|
||||||
: "\\begin{singlespace}");
|
return name.empty() ? string() : "\\begin{" + name + '}';
|
||||||
case Onehalf:
|
|
||||||
return (useSetSpace ? "\\begin{OnehalfSpace}"
|
|
||||||
: "\\begin{onehalfspace}");
|
|
||||||
case Double:
|
|
||||||
return (useSetSpace ? "\\begin{DoubleSpace}"
|
|
||||||
: "\\begin{doublespace}");
|
|
||||||
case Other:
|
|
||||||
{
|
|
||||||
ostringstream ost;
|
|
||||||
ost << (useSetSpace ? "\\begin{Spacing}{"
|
|
||||||
: "\\begin{spacing}{" )
|
|
||||||
<< getValueAsString() << '}';
|
|
||||||
return ost.str();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string const Spacing::writeEnvirEnd(bool useSetSpace) const
|
string const Spacing::writeEnvirEnd(bool useSetSpace) const
|
||||||
{
|
{
|
||||||
switch (space) {
|
string const name = envName(space, useSetSpace);
|
||||||
case Default: break; // do nothing
|
return name.empty() ? string() : "\\end{" + name + '}';
|
||||||
case Single:
|
|
||||||
return (useSetSpace ? "\\end{SingleSpace}"
|
|
||||||
: "\\end{singlespace}");
|
|
||||||
case Onehalf:
|
|
||||||
return (useSetSpace ? "\\end{OnehalfSpace}"
|
|
||||||
: "\\end{onehalfspace}");
|
|
||||||
case Double:
|
|
||||||
return (useSetSpace ? "\\end{DoubleSpace}"
|
|
||||||
: "\\end{doublespace}");
|
|
||||||
case Other:
|
|
||||||
return (useSetSpace ? "\\end{Spacing}" : "\\end{spacing}") ;
|
|
||||||
}
|
|
||||||
return string();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string const Spacing::writePreamble(bool useSetSpace) const
|
||||||
|
{
|
||||||
|
string preamble;
|
||||||
|
switch (space) {
|
||||||
|
case Default:
|
||||||
|
case Single:
|
||||||
|
// we dont use setspace.sty so dont print anything
|
||||||
|
//return "\\singlespacing\n";
|
||||||
|
break;
|
||||||
|
case Onehalf:
|
||||||
|
preamble = useSetSpace ? "\\OnehalfSpacing\n"
|
||||||
|
: "\\onehalfspacing\n";
|
||||||
|
break;
|
||||||
|
case Double:
|
||||||
|
preamble = useSetSpace ? "\\DoubleSpacing\n"
|
||||||
|
: "\\doublespacing\n";
|
||||||
|
break;
|
||||||
|
case Other:
|
||||||
|
preamble = (useSetSpace ? "\\setSpacing{" : "\\setstretch{")
|
||||||
|
+ getValueAsString() + "}\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return preamble;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
#include "support/strfwd.h"
|
#include "support/strfwd.h"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -64,6 +64,9 @@ public:
|
|||||||
/// useSetSpace is true when using the variant supported by
|
/// useSetSpace is true when using the variant supported by
|
||||||
/// the memoir class.
|
/// the memoir class.
|
||||||
std::string const writeEnvirEnd(bool useSetSpace) const;
|
std::string const writeEnvirEnd(bool useSetSpace) const;
|
||||||
|
/// useSetSpace is true when using the variant supported by
|
||||||
|
/// the memoir class.
|
||||||
|
std::string const writePreamble(bool useSetSpace) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user