mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Add support for glue length in parskip (#12867)
This commit is contained in:
parent
e1cb15ee5d
commit
d2db74f9ee
@ -7,6 +7,14 @@ changes happened in particular if possible. A good example would be
|
||||
|
||||
-----------------------
|
||||
|
||||
2024-06-01 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* Format incremented to 622: Allow glue length (skip) in parskip setting.
|
||||
|
||||
2024-05-13 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* Format incremented to 621: Escape some special chars (#, %, \) in URL
|
||||
with hyperref. Previous to this change, the user had to escape this
|
||||
themselves.
|
||||
|
||||
2023-09-29 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* Format incremented to 620: Add InsetBox "default" framecolor ("foreground"
|
||||
rather than "black" in GUI). This aligns better with dark mode.
|
||||
|
@ -26,10 +26,10 @@ from datetime import (datetime, date, time)
|
||||
|
||||
# Uncomment only what you need to import, please.
|
||||
|
||||
from parser_tools import (find_end_of_inset, find_end_of_layout, find_token, find_re)
|
||||
from parser_tools import (find_end_of_inset, find_end_of_layout, find_token, find_re, get_value)
|
||||
# count_pars_in_inset, del_complete_lines, del_token, find_end_of,
|
||||
# find_token_backwards, find_token_exact, get_bool_value,
|
||||
# get_containing_inset, get_containing_layout, get_option_value, get_value,
|
||||
# get_containing_inset, get_containing_layout, get_option_value,
|
||||
# get_quoted_value, is_in_inset,
|
||||
# del_value,
|
||||
# find_complete_lines,
|
||||
@ -37,9 +37,10 @@ from parser_tools import (find_end_of_inset, find_end_of_layout, find_token, fin
|
||||
# set_bool_value
|
||||
# find_tokens, check_token
|
||||
|
||||
#from lyx2lyx_tools import (put_cmd_in_ert, add_to_preamble, insert_to_preamble, lyx2latex,
|
||||
# revert_language, revert_flex_inset, str2bool)
|
||||
# revert_font_attrs, latex_length
|
||||
from lyx2lyx_tools import (add_to_preamble, latex_length)
|
||||
# put_cmd_in_ert, insert_to_preamble, lyx2latex,
|
||||
# revert_language, revert_flex_inset, str2bool,
|
||||
# revert_font_attrs,
|
||||
# get_ert, lyx2verbatim, length_in_bp, convert_info_insets
|
||||
# revert_flex_inset, hex2ratio
|
||||
|
||||
@ -167,17 +168,44 @@ def revert_url_escapes2(document):
|
||||
document.body[bs] = "\\backslash\\backslash"
|
||||
i = bs + 1
|
||||
|
||||
|
||||
def revert_glue_parskip(document):
|
||||
"""Revert parskip with glue length to user preamble."""
|
||||
|
||||
i = find_token(document.header, "\\paragraph_separation skip", 0)
|
||||
if i == -1:
|
||||
return
|
||||
|
||||
j = find_token(document.header, "\\defskip", 0)
|
||||
if j == -1:
|
||||
document.warning("Malformed LyX document! Missing \\defskip.")
|
||||
return
|
||||
|
||||
val = get_value(document.header, "\\defskip", j)
|
||||
|
||||
if val.find("+") == -1 and val.find("-", 1) == -1:
|
||||
# not a glue length
|
||||
return
|
||||
|
||||
add_to_preamble(document, ["\\usepackage[skip={" + latex_length(val)[1] + "}]{parskip}"])
|
||||
|
||||
document.header[i] = "\\paragraph_separation indent"
|
||||
document.header[j] = "\\paragraph_indentation default"
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
#
|
||||
|
||||
supported_versions = ["2.5.0", "2.5"]
|
||||
convert = [
|
||||
[621, [convert_url_escapes, convert_url_escapes2]]
|
||||
[621, [convert_url_escapes, convert_url_escapes2]],
|
||||
[622, []]
|
||||
]
|
||||
|
||||
|
||||
revert = [[620, [revert_url_escapes2, revert_url_escapes]]
|
||||
revert = [[621, [revert_glue_parskip]],
|
||||
[620, [revert_url_escapes2, revert_url_escapes]]
|
||||
]
|
||||
|
||||
|
||||
|
@ -2189,8 +2189,13 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
|
||||
} else {
|
||||
// load parskip package with required options
|
||||
string psopts;
|
||||
if (!psopt.empty())
|
||||
psopts = "skip=" + psopt;
|
||||
if (!psopt.empty()) {
|
||||
if (contains(psopt, ' '))
|
||||
// glue length has spaces: embrace
|
||||
psopts = "skip={" + psopt + "}";
|
||||
else
|
||||
psopts = "skip=" + psopt;
|
||||
}
|
||||
string const xpsopts = getPackageOptions("parskip");
|
||||
if (!xpsopts.empty()) {
|
||||
if (!psopts.empty())
|
||||
|
@ -892,8 +892,10 @@ GuiDocument::GuiDocument(GuiView & lv)
|
||||
textLayoutModule->lspacingLE));
|
||||
textLayoutModule->indentLE->setValidator(new LengthValidator(
|
||||
textLayoutModule->indentLE, false));
|
||||
textLayoutModule->skipLE->setValidator(new LengthValidator(
|
||||
textLayoutModule->skipLE, false));
|
||||
// parskip accepts glue length
|
||||
LengthValidator * skipLEValidator = new LengthValidator(textLayoutModule->skipLE, false);
|
||||
skipLEValidator->setBottom(GlueLength());
|
||||
textLayoutModule->skipLE->setValidator(skipLEValidator);
|
||||
|
||||
textLayoutModule->indentCO->addItem(qt_("Default"), toqstr("default"));
|
||||
textLayoutModule->indentCO->addItem(qt_("Custom"), toqstr("custom"));
|
||||
|
@ -1745,8 +1745,13 @@ void Preamble::handle_package(Parser &p, string const & name,
|
||||
h_defskip = "bigskip";
|
||||
else if (opts == "skip=\\baselineskip")
|
||||
h_defskip = "fullline";
|
||||
else
|
||||
h_defskip = "opts";
|
||||
else {
|
||||
// get value, unbraced
|
||||
string length = rtrim(ltrim(token(opts, '=', 1), "{"), "}");
|
||||
// transform glue length if we have one
|
||||
is_glue_length(length);
|
||||
h_defskip = length;
|
||||
}
|
||||
h_paragraph_separation = "skip";
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ extern std::string rgbcolor2code(std::string const & name);
|
||||
|
||||
/// in text.cpp
|
||||
std::string translate_len(std::string const &);
|
||||
bool is_glue_length(std::string & length);
|
||||
|
||||
void parse_text(Parser & p, std::ostream & os, unsigned flags, bool outer,
|
||||
Context & context, std::string const & rdelim = "",
|
||||
|
@ -608,6 +608,32 @@ string translate_len(string const & length)
|
||||
return length;
|
||||
}
|
||||
|
||||
bool is_glue_length(string & length)
|
||||
{
|
||||
// check for glue lengths
|
||||
bool is_gluelength = false;
|
||||
string gluelength = length;
|
||||
string::size_type i = length.find(" minus");
|
||||
if (i == string::npos) {
|
||||
i = length.find(" plus");
|
||||
if (i != string::npos)
|
||||
is_gluelength = true;
|
||||
} else
|
||||
is_gluelength = true;
|
||||
// if yes transform "9xx minus 8yy plus 7zz"
|
||||
// to "9xx-8yy+7zz"
|
||||
if (is_gluelength) {
|
||||
i = gluelength.find(" minus");
|
||||
if (i != string::npos)
|
||||
gluelength.replace(i, 7, "-");
|
||||
i = gluelength.find(" plus");
|
||||
if (i != string::npos)
|
||||
gluelength.replace(i, 6, "+");
|
||||
length = gluelength;
|
||||
}
|
||||
return is_gluelength;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
@ -6039,25 +6065,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
}
|
||||
|
||||
// check for glue lengths
|
||||
bool is_gluelength = false;
|
||||
string gluelength = length;
|
||||
string::size_type i = length.find(" minus");
|
||||
if (i == string::npos) {
|
||||
i = length.find(" plus");
|
||||
if (i != string::npos)
|
||||
is_gluelength = true;
|
||||
} else
|
||||
is_gluelength = true;
|
||||
// if yes transform "9xx minus 8yy plus 7zz"
|
||||
// to "9xx-8yy+7zz"
|
||||
if (is_gluelength) {
|
||||
i = gluelength.find(" minus");
|
||||
if (i != string::npos)
|
||||
gluelength.replace(i, 7, "-");
|
||||
i = gluelength.find(" plus");
|
||||
if (i != string::npos)
|
||||
gluelength.replace(i, 6, "+");
|
||||
}
|
||||
bool is_gluelength = is_glue_length(gluelength);
|
||||
|
||||
if (t.cs()[0] == 'h' && (known_unit || known_hspace || is_gluelength)) {
|
||||
// Literal horizontal length or known variable
|
||||
|
@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
|
||||
|
||||
// Do not remove the comment below, so we get merge conflict in
|
||||
// independent branches. Instead add your own.
|
||||
#define LYX_FORMAT_LYX 621 // spitz: handle #% in frame urls
|
||||
#define LYX_FORMAT_TEX2LYX 621
|
||||
#define LYX_FORMAT_LYX 622 // spitz: support glue length in parskip
|
||||
#define LYX_FORMAT_TEX2LYX 622
|
||||
|
||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||
#ifndef _MSC_VER
|
||||
|
Loading…
Reference in New Issue
Block a user