Add textclass options for paper size selection and default paper size

Fixes: #4506

Implementing this to the classes requires file format changes, as the
classes' page layout will likely differ from geometry's.
This commit is contained in:
Juergen Spitzmueller 2019-08-06 17:34:16 +02:00
parent 65c1ae8133
commit c6f262a5b7
7 changed files with 301 additions and 135 deletions

View File

@ -1,5 +1,5 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 578
\lyxformat 584
\begin_document
\begin_header
\save_transient_properties true
@ -53,7 +53,9 @@ logicalmkup
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
@ -10500,6 +10502,47 @@ natbib
\end_inset
.)
\change_inserted -712698321 1565102364
\end_layout
\begin_layout Description
\change_inserted -712698321 1565102470
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1565102365
PageSize
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1565105222
\emph on
custom
\emph default
, letterpaper, legalpaper, executivepaper, a0paper, a1paper, a2paper, a3paper,
a4paper, a5paper, a6paper, b0paper, b1paper, b2paper, b3paper, b4paper,
b5paper, b6paper, c0paper, c1paper, c2paper, c3paper, c4paper, c5paper,
c6paper, b0j, b1j, b2j, b3j, b4j, b5j, b6j
\end_layout
\end_inset
] The default page size.
This is used by some converters.
\change_unchanged
\end_layout
\begin_layout Description
@ -11492,6 +11535,11 @@ status collapsed
\end_inset
.
\change_inserted -712698321 1565102054
Any number is possible.
\change_unchanged
\end_layout
\begin_layout Description
@ -11518,6 +11566,94 @@ g.: PUBLIC
\end_inset
.
\change_inserted -712698321 1565101761
\end_layout
\begin_layout Description
\change_inserted -712698321 1565105413
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1565101918
PageSize
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1565105399
string="letterpaper|\SpecialChar allowbreak
legalpaper|\SpecialChar allowbreak
executivepaper|\SpecialChar allowbreak
a0paper|\SpecialChar allowbreak
a1paper|\SpecialChar allowbreak
a2paper|\SpecialChar allowbreak
a3paper|\SpecialChar allowbreak
a4
paper|\SpecialChar allowbreak
a5paper|\SpecialChar allowbreak
a6paper|\SpecialChar allowbreak
b0paper|\SpecialChar allowbreak
b1paper|\SpecialChar allowbreak
b2paper|\SpecialChar allowbreak
b3paper|\SpecialChar allowbreak
b4paper|\SpecialChar allowbreak
b5paper|\SpecialChar allowbreak
b6paper|\SpecialChar allowbreak
c0
paper|\SpecialChar allowbreak
c1paper|\SpecialChar allowbreak
c2paper|\SpecialChar allowbreak
c3paper|\SpecialChar allowbreak
c4paper|\SpecialChar allowbreak
c5paper|\SpecialChar allowbreak
c6paper|\SpecialChar allowbreak
b0j|\SpecialChar allowbreak
b1j|\SpecialChar allowbreak
b2j|\SpecialChar allowbreak
b3j|\SpecialChar allowbreak
b4j|\SpecialChar allowbreak
b5j|\SpecialChar allowbreak
b6
j"
\end_layout
\end_inset
] The list of available page sizes, separated by
\begin_inset Quotes eld
\end_inset
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1565101779
|
\end_layout
\end_inset
\begin_inset Quotes erd
\end_inset
.
Currently, only the listed sizes are supported.
Other sizes might be entered as custom class option.
\change_unchanged
\end_layout
\begin_layout Description

View File

@ -1,5 +1,5 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 578
\lyxformat 584
\begin_document
\begin_header
\save_transient_properties true
@ -61,7 +61,9 @@ logicalmkup
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
@ -8733,6 +8735,37 @@ natbib
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
PageSize
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\emph on
custom
\emph default
, letterpaper, legalpaper, executivepaper, a0paper, a1paper, a2paper, a3paper,
a4paper, a5paper, a6paper, b0paper, b1paper, b2paper, b3paper, b4paper,
b5paper, b6paper, c0paper, c1paper, c2paper, c3paper, c4paper, c5paper,
c6paper, b0j, b1j, b2j, b3j, b4j, b5j, b6j
\end_layout
\end_inset
] Die Standard-Seitengröße.
Dies wird von einigen Konvertern verwendet.
\end_layout
\begin_layout Description
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
PageStyle
\end_layout
@ -9637,6 +9670,7 @@ status collapsed
\end_inset
getrennt.
Neben den genannten sind auch andere Größen möglich.
\end_layout
\begin_layout Description
@ -9705,6 +9739,83 @@ Befehl als optionales Argument übergeben.
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
PageSize
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
string="letterpaper|\SpecialChar allowbreak
legalpaper|\SpecialChar allowbreak
executivepaper|\SpecialChar allowbreak
a0paper|\SpecialChar allowbreak
a1paper|\SpecialChar allowbreak
a2paper|\SpecialChar allowbreak
a3paper|\SpecialChar allowbreak
a4
paper|\SpecialChar allowbreak
a5paper|\SpecialChar allowbreak
a6paper|\SpecialChar allowbreak
b0paper|\SpecialChar allowbreak
b1paper|\SpecialChar allowbreak
b2paper|\SpecialChar allowbreak
b3paper|\SpecialChar allowbreak
b4paper|\SpecialChar allowbreak
b5paper|\SpecialChar allowbreak
b6paper|\SpecialChar allowbreak
c0
paper|\SpecialChar allowbreak
c1paper|\SpecialChar allowbreak
c2paper|\SpecialChar allowbreak
c3paper|\SpecialChar allowbreak
c4paper|\SpecialChar allowbreak
c5paper|\SpecialChar allowbreak
c6paper|\SpecialChar allowbreak
b0j|\SpecialChar allowbreak
b1j|\SpecialChar allowbreak
b2j|\SpecialChar allowbreak
b3j|\SpecialChar allowbreak
b4j|\SpecialChar allowbreak
b5j|\SpecialChar allowbreak
b6
j"
\end_layout
\end_inset
] Eine Liste verfügbarer Seitengrößen; die Einträge werden mit
\begin_inset Quotes gld
\end_inset
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
|
\end_layout
\end_inset
\begin_inset Quotes grd
\end_inset
getrennt.
Nur die aufgeführten Größen werden zurzeit unterstützt.
Weitere Größen können ggf.
über die benutzerdefinierten Klassenoptionen eingegeben werden.
\end_layout
\begin_layout Description
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
PageStyle
\end_layout

View File

@ -11,7 +11,7 @@
# This script will update a .layout file to current format
# The latest layout format is also defined in src/TextClass.cpp
currentFormat = 76
currentFormat = 77
# Incremented to format 4, 6 April 2007, lasgouttes
@ -255,6 +255,10 @@ currentFormat = 76
# Incremented to format 76, 8 July 2019 by spitz
# New textclass tag BibInToc
# Incremented to format 77, 6 August 2019 by spitz
# New textclass tag PageSize (= default page size)
# and textclass option PageSize (= list of available page sizes)
# Do not forget to document format change in Customization
# Manual (section "Declaring a new text class").
@ -504,7 +508,7 @@ def convert(lines, end_format):
i += 1
continue
if format >= 65 and format <= 75:
if format >= 65 and format <= 76:
# nothing to do.
i += 1
continue

View File

@ -80,8 +80,8 @@ static char const * const string_quotes_style[] = {
static char const * const string_papersize[] = {
"default", "custom", "letterpaper", "legalpaper", "executivepaper",
"a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
"a6paper", "b0paper", "b1paper", "b2paper","b3paper", "b4paper",
"a0paper", "a1paper", "a2paper", "a3paper", "a4paper", "a5paper",
"a6paper", "b0paper", "b1paper", "b2paper", "b3paper", "b4paper",
"b5paper", "b6paper", "c0paper", "c1paper", "c2paper", "c3paper",
"c4paper", "c5paper", "c6paper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j",
"b6j", ""
@ -1620,66 +1620,15 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
clsoptions << fontsize << "pt,";
}
// all paper sizes except of A4, A5, B5 and the US sizes need the
// paper sizes not supported by the class itself need the
// geometry package
bool nonstandard_papersize = papersize != PAPER_DEFAULT
&& papersize != PAPER_USLETTER
&& papersize != PAPER_USLEGAL
&& papersize != PAPER_USEXECUTIVE
&& papersize != PAPER_A4
&& papersize != PAPER_A5
&& papersize != PAPER_B5;
vector<string> classpsizes = getVectorFromString(tclass.opt_pagesize(), "|");
bool class_supported_papersize = papersize == PAPER_DEFAULT
|| find(classpsizes.begin(), classpsizes.end(), string_papersize[papersize]) != classpsizes.end();
if (!use_geometry || features.isProvided("geometry-light")) {
switch (papersize) {
case PAPER_A4:
clsoptions << "a4paper,";
break;
case PAPER_USLETTER:
clsoptions << "letterpaper,";
break;
case PAPER_A5:
clsoptions << "a5paper,";
break;
case PAPER_B5:
clsoptions << "b5paper,";
break;
case PAPER_USEXECUTIVE:
clsoptions << "executivepaper,";
break;
case PAPER_USLEGAL:
clsoptions << "legalpaper,";
break;
case PAPER_DEFAULT:
case PAPER_A0:
case PAPER_A1:
case PAPER_A2:
case PAPER_A3:
case PAPER_A6:
case PAPER_B0:
case PAPER_B1:
case PAPER_B2:
case PAPER_B3:
case PAPER_B4:
case PAPER_B6:
case PAPER_C0:
case PAPER_C1:
case PAPER_C2:
case PAPER_C3:
case PAPER_C4:
case PAPER_C5:
case PAPER_C6:
case PAPER_JISB0:
case PAPER_JISB1:
case PAPER_JISB2:
case PAPER_JISB3:
case PAPER_JISB4:
case PAPER_JISB5:
case PAPER_JISB6:
case PAPER_CUSTOM:
break;
}
}
if ((!use_geometry || features.isProvided("geometry-light"))
&& class_supported_papersize)
clsoptions << string_papersize[papersize] << ",";
// if needed
if (sides != tclass.sides()) {
@ -1854,7 +1803,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
os << "}\n";
}
if (use_geometry || nonstandard_papersize) {
if (use_geometry || !class_supported_papersize) {
odocstringstream ods;
if (!getGraphicsDriver("geometry").empty())
ods << getGraphicsDriver("geometry");
@ -1870,97 +1819,37 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
<< from_ascii(paperheight);
break;
case PAPER_USLETTER:
ods << ",letterpaper";
break;
case PAPER_USLEGAL:
ods << ",legalpaper";
break;
case PAPER_USEXECUTIVE:
ods << ",executivepaper";
break;
case PAPER_A0:
ods << ",a0paper";
break;
case PAPER_A1:
ods << ",a1paper";
break;
case PAPER_A2:
ods << ",a2paper";
break;
case PAPER_A3:
ods << ",a3paper";
break;
case PAPER_A4:
ods << ",a4paper";
break;
case PAPER_A5:
ods << ",a5paper";
break;
case PAPER_A6:
ods << ",a6paper";
break;
case PAPER_B0:
ods << ",b0paper";
break;
case PAPER_B1:
ods << ",b1paper";
break;
case PAPER_B2:
ods << ",b2paper";
break;
case PAPER_B3:
ods << ",b3paper";
break;
case PAPER_B4:
ods << ",b4paper";
break;
case PAPER_B5:
ods << ",b5paper";
break;
case PAPER_B6:
ods << ",b6paper";
break;
case PAPER_C0:
ods << ",c0paper";
break;
case PAPER_C1:
ods << ",c1paper";
break;
case PAPER_C2:
ods << ",c2paper";
break;
case PAPER_C3:
ods << ",c3paper";
break;
case PAPER_C4:
ods << ",c4paper";
break;
case PAPER_C5:
ods << ",c5paper";
break;
case PAPER_C6:
ods << ",c6paper";
break;
case PAPER_JISB0:
ods << ",b0j";
break;
case PAPER_JISB1:
ods << ",b1j";
break;
case PAPER_JISB2:
ods << ",b2j";
break;
case PAPER_JISB3:
ods << ",b3j";
break;
case PAPER_JISB4:
ods << ",b4j";
break;
case PAPER_JISB5:
ods << ",b5j";
break;
case PAPER_JISB6:
ods << ",b6j";
ods << "," << from_ascii(string_papersize[papersize]);
break;
case PAPER_DEFAULT:
break;
@ -3038,12 +2927,15 @@ void BufferParams::readIncludeonly(Lexer & lex)
}
string BufferParams::paperSizeName(PapersizePurpose purpose) const
string BufferParams::paperSizeName(PapersizePurpose purpose, string const psize) const
{
switch (papersize) {
PAPER_SIZE ppsize = psize.empty() ? papersize : papersizetranslator().find(psize);
switch (ppsize) {
case PAPER_DEFAULT:
// could be anything, so don't guess
return string();
if (documentClass().pagesize() == "custom")
// could be anything, so don't guess
return string();
return paperSizeName(purpose, documentClass().pagesize());
case PAPER_CUSTOM: {
if (purpose == XDVI && !paperwidth.empty() &&
!paperheight.empty()) {

View File

@ -466,7 +466,8 @@ public:
XDVI
};
///
std::string paperSizeName(PapersizePurpose purpose) const;
std::string paperSizeName(PapersizePurpose purpose,
std::string const psize = std::string()) const;
/// set up if and how babel is called
std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
/// return supported drivers for specific packages

View File

@ -62,7 +62,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script,
// to update the format of all of our layout files.
//
int const LAYOUT_FORMAT = 76; // spitz: BibInToc
int const LAYOUT_FORMAT = 77; // spitz: pagesize
// Layout format for the current lyx file format. Controls which format is
@ -150,7 +150,8 @@ docstring const TextClass::plain_layout_ = from_ascii(N_("Plain Layout"));
TextClass::TextClass()
: loaded_(false), tex_class_avail_(false),
opt_enginetype_("authoryear|numerical"), opt_fontsize_("10|11|12"),
opt_pagestyle_("empty|plain|headings|fancy"), pagestyle_("default"),
opt_pagesize_("default|a4paper|a5paper|b5paper|letterpaper|legalpaper|executivepaper"),
opt_pagestyle_("empty|plain|headings|fancy"), pagesize_("default"), pagestyle_("default"),
tablestyle_("default"), columns_(1), sides_(OneSide), secnumdepth_(3),
tocdepth_(3), outputType_(LATEX), outputFormat_("latex"),
has_output_format_(false), defaultfont_(sane_font),
@ -191,6 +192,7 @@ enum TextClassTags {
TC_COLUMNS,
TC_SIDES,
TC_PAGESTYLE,
TC_PAGESIZE,
TC_DEFAULTFONT,
TC_SECNUMDEPTH,
TC_TOCDEPTH,
@ -272,6 +274,7 @@ LexerKeyword textClassTags[] = {
{ "outputformat", TC_OUTPUTFORMAT },
{ "outputtype", TC_OUTPUTTYPE },
{ "packageoptions", TC_PKGOPTS },
{ "pagesize", TC_PAGESIZE },
{ "pagestyle", TC_PAGESTYLE },
{ "preamble", TC_PREAMBLE },
{ "provides", TC_PROVIDES },
@ -606,6 +609,11 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
}
break;
case TC_PAGESIZE:
lexrc.next();
pagesize_ = rtrim(lexrc.getString());
break;
case TC_PAGESTYLE:
lexrc.next();
pagestyle_ = rtrim(lexrc.getString());
@ -996,6 +1004,7 @@ void TextClass::readClassOptions(Lexer & lexrc)
{
enum {
CO_FONTSIZE = 1,
CO_PAGESIZE,
CO_PAGESTYLE,
CO_OTHER,
CO_HEADER,
@ -1007,6 +1016,7 @@ void TextClass::readClassOptions(Lexer & lexrc)
{"fontsize", CO_FONTSIZE },
{"header", CO_HEADER },
{"other", CO_OTHER },
{"pagesize", CO_PAGESIZE },
{"pagestyle", CO_PAGESTYLE }
};
@ -1026,6 +1036,10 @@ void TextClass::readClassOptions(Lexer & lexrc)
lexrc.next();
opt_fontsize_ = rtrim(lexrc.getString());
break;
case CO_PAGESIZE:
lexrc.next();
opt_pagesize_ = rtrim(lexrc.getString());
break;
case CO_PAGESTYLE:
lexrc.next();
opt_pagestyle_ = rtrim(lexrc.getString());

View File

@ -271,9 +271,13 @@ protected:
///
std::string opt_fontsize_;
///
std::string opt_pagesize_;
///
std::string opt_pagestyle_;
/// Specific class options
std::string options_;
/// Default page size
std::string pagesize_;
///
std::string pagestyle_;
///
@ -449,12 +453,16 @@ public:
///
std::string const & opt_fontsize() const { return opt_fontsize_; }
///
std::string const & opt_pagesize() const { return opt_pagesize_; }
///
std::string const & opt_pagestyle() const { return opt_pagestyle_; }
///
std::string const & options() const { return options_; }
///
std::string const & class_header() const { return class_header_; }
///
std::string const & pagesize() const { return pagesize_; }
///
std::string const & pagestyle() const { return pagestyle_; }
///
std::string const & tablestyle() const { return tablestyle_; }