From 60e34a2acd828681be9043ac710174aee6aba203 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 7 Mar 2022 12:13:48 -0500 Subject: latex, pagebreaks, make headers - for book, article and manually set pagebreaks, not fully utilized but flexibility introduced --- org/default_regex.org | 10 +++++ org/meta_conf_make_meta.org | 37 +++++++++++----- org/out_latex.org | 66 ++++++++++++++++++++++++++-- src/doc_reform/io_out/latex.d | 66 ++++++++++++++++++++++++++-- src/doc_reform/io_out/rgx.d | 2 + src/doc_reform/meta/conf_make_meta_json.d | 11 +++-- src/doc_reform/meta/conf_make_meta_structs.d | 9 +++- src/doc_reform/meta/conf_make_meta_yaml.d | 17 ++++--- 8 files changed, 190 insertions(+), 28 deletions(-) diff --git a/org/default_regex.org b/org/default_regex.org index 636d767..86f6d2d 100644 --- a/org/default_regex.org +++ b/org/default_regex.org @@ -442,6 +442,7 @@ https://dlang.org/phobos/std_regex.html module doc_reform.io_out.rgx; static template spineRgxOut() { static struct RgxO { + <> <> <> <> @@ -458,6 +459,15 @@ static template spineRgxOut() { } #+END_SRC +** make +*** various + +#+NAME: makes +#+BEGIN_SRC d +static make_breakpage = ctRegex!(`new=(?P.+?)(?:;|$)`); +static make_breakcolumn = ctRegex!(`break=(?P.+?)(?:;|$)`,); +#+END_SRC + ** special characters *** xhtml special characters diff --git a/org/meta_conf_make_meta.org b/org/meta_conf_make_meta.org index 38fe49a..983cc75 100644 --- a/org/meta_conf_make_meta.org +++ b/org/meta_conf_make_meta.org @@ -295,8 +295,9 @@ static auto mkup = InlineMarkup(); return line_; } struct ConfCompositeMakeStr { - string bold; + string doc_type = "book"; // book, article string breaks; + string bold; string cover_image; string css; string emphasis; @@ -321,6 +322,9 @@ struct confCompositeMakeBuild { } return _out; } + string doc_type(string _mk) { + return _mk; + } string breaks(string _mk) { return _mk; } @@ -385,10 +389,11 @@ struct confCompositeMakeBuild { #+NAME: meta_defaults_template_structs_composite_make_init #+BEGIN_SRC d struct ConfCompositeMakeInit { - string[] bold; + string doc_type; string breaks; string cover_image; string css; + string[] bold; string[] emphasis; string[] footer; string[] headings; @@ -1171,11 +1176,11 @@ if ("make" in _yaml if (_yaml["make"].type.mapping && _yaml["make"].tag.match(rgx.yaml_tag_is_map) ) { - if ("bold" in _yaml["make"] - && _yaml["make"]["bold"].type.string - && _yaml["make"]["bold"].tag.match(rgx.yaml_tag_is_str) + if ("doc_type" in _yaml["make"] + && _yaml["make"]["doc_type"].type.string + && _yaml["make"]["doc_type"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.make_str.bold = _yaml["make"]["bold"].get!string; + _struct_composite.make_str.doc_type = _yaml["make"]["doc_type"].get!string; } if ("breaks" in _yaml["make"] && _yaml["make"]["breaks"].type.string @@ -1183,6 +1188,12 @@ if ("make" in _yaml ) { _struct_composite.make_str.breaks = _yaml["make"]["breaks"].get!string; } + if ("bold" in _yaml["make"] + && _yaml["make"]["bold"].type.string + && _yaml["make"]["bold"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.bold = _yaml["make"]["bold"].get!string; + } if ("cover_image" in _yaml["make"] && _yaml["make"]["cover_image"].type.string && _yaml["make"]["cover_image"].tag.match(rgx.yaml_tag_is_str) @@ -1298,8 +1309,9 @@ if ("make" in _yaml _struct_composite.make_str.texpdf_font = _yaml["make"]["texpdf_font"].get!string; } } - _struct_composite.make.bold = _mk.bold(_struct_composite.make_str.bold); + _struct_composite.make.doc_type = _mk.doc_type(_struct_composite.make_str.doc_type); _struct_composite.make.breaks = _mk.breaks(_struct_composite.make_str.breaks); + _struct_composite.make.bold = _mk.bold(_struct_composite.make_str.bold); _struct_composite.make.cover_image = _mk.cover_image(_struct_composite.make_str.cover_image); _struct_composite.make.css = _mk.css(_struct_composite.make_str.css); _struct_composite.make.emphasis = _mk.emphasis(_struct_composite.make_str.emphasis); @@ -1774,16 +1786,21 @@ static template contentJSONtoSpineStruct() { #+BEGIN_SRC d /+ make ------------------------------------------------------------------- +/ if ("make" in _json.object) { - if ("bold" in _json.object["make"] - && (_json.object["make"]["bold"].type().to!string == "string") + if ("doc_type" in _json.object["make"] + && (_json.object["make"]["doc_type"].type().to!string == "string") ) { - _struct_composite.make_str.bold = _json.object["make"]["bold"].str; + _struct_composite.make_str.doc_type = _json.object["make"]["doc_type"].str; } if ("breaks" in _json.object["make"] && (_json.object["make"]["breaks"].type().to!string == "string") ) { _struct_composite.make_str.breaks = _json.object["make"]["breaks"].str; } + if ("bold" in _json.object["make"] + && (_json.object["make"]["bold"].type().to!string == "string") + ) { + _struct_composite.make_str.bold = _json.object["make"]["bold"].str; + } if ("cover_image" in _json.object["make"] && (_json.object["make"]["cover_image"].type().to!string == "string") ) { diff --git a/org/out_latex.org b/org/out_latex.org index 97fe425..0b37389 100644 --- a/org/out_latex.org +++ b/org/out_latex.org @@ -773,8 +773,60 @@ _txt = _txt string _txt, O obj, M doc_matters, + string paper_size_orientation, string _part = "" ) { + string manual_breaks( + string test_for_break_level, + string _pg_break + ) { + if ((!(doc_matters.conf_make_meta.make.breaks.empty) + && (matchFirst(doc_matters.conf_make_meta.make.breaks, test_for_break_level))) + ) { // manually override defaults + if ((matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakpage)) + && (matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakcolumn)) + ) { + if (auto m = matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakpage)) { + if (matchFirst(m.captures["breakpage"], test_for_break_level)) { + _pg_break = "\\clearpage\n"; + } else if (auto n = matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakcolumn)) { + if (matchFirst(n.captures["breakcolumn"], test_for_break_level)) { + if ((paper_size_orientation == "a4.landscape") + || (paper_size_orientation == "b4.landscape") + || (paper_size_orientation == "a5.landscape") + || (paper_size_orientation == "letter.landscape") + || (paper_size_orientation == "legal.landscape") + ) { + _pg_break = "\\\\ \\columnbreak\n"; // "\\\\ \\newpage\n"; + } else { // portrait + _pg_break = "\\clearpage\n"; + } + } + } + } + } else if (auto m = matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakpage)) { + if (matchFirst(m.captures["breakpage"], test_for_break_level)) { + _pg_break = "\\clearpage\n"; + } + } else if (auto m = matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakcolumn)) { + if (matchFirst(m.captures["breakcolumn"], test_for_break_level)) { + if ((paper_size_orientation == "a4.landscape") + || (paper_size_orientation == "b4.landscape") + || (paper_size_orientation == "a5.landscape") + || (paper_size_orientation == "letter.landscape") + || (paper_size_orientation == "legal.landscape") + ) { + _pg_break = "\\\\ \\columnbreak\n"; // "\\\\ \\newpage\n"; + } else { // portrait + _pg_break = "\\clearpage\n"; + } + } + } + } else if (!(doc_matters.conf_make_meta.make.breaks.empty)) { + _pg_break = ""; + } + return _pg_break; + } if (obj.metainfo.is_a == "heading") { string _tex_para; string _pg_break; @@ -798,7 +850,13 @@ _txt = _txt case 4: // 1 == section _columns = (_part != "bookindex") ? "" : "\n\\br\n\\begin{multicols}{2}"; - _pg_break = "\\clearpage\n"; + if (doc_matters.conf_make_meta.make.doc_type == "article") { // defaults for article + _pg_break = ""; + } else if (doc_matters.conf_make_meta.make.doc_type == "book") { // defaults for book + _pg_break = "\\clearpage\n"; + } else { + _pg_break = "\\clearpage\n"; + } _sect = "section"; _post = ""; _title_add = format(q"┃ @@ -1848,7 +1906,7 @@ case "frontmatter": assert(part == "head" || "toc"); case "para": switch (obj.metainfo.is_a) { case "heading": - _txt = _txt.heading(obj, doc_matters); + _txt = _txt.heading(obj, doc_matters, paper_size_orientation); goto default; case "toc": break; @@ -1875,7 +1933,7 @@ case "body": assert(part == "body" || "head"); // surprise case "para": switch (obj.metainfo.is_a) { case "heading": - _txt = _txt.heading(obj, doc_matters); + _txt = _txt.heading(obj, doc_matters, paper_size_orientation); goto default; case "para": _txt = _txt.para(obj) @@ -1945,7 +2003,7 @@ case "backmatter": if (part == "bookindex") { _multicolumns = true; } - _txt = _txt.heading(obj, doc_matters, part); + _txt = _txt.heading(obj, doc_matters, paper_size_orientation, part); goto default; case "endnote": assert(part == "endnotes"); /* uncomment code to reinstate endnotes in endnote section */ diff --git a/src/doc_reform/io_out/latex.d b/src/doc_reform/io_out/latex.d index a939fd8..ef878fd 100644 --- a/src/doc_reform/io_out/latex.d +++ b/src/doc_reform/io_out/latex.d @@ -505,8 +505,60 @@ template outputLaTeX() { string _txt, O obj, M doc_matters, + string paper_size_orientation, string _part = "" ) { + string manual_breaks( + string test_for_break_level, + string _pg_break + ) { + if ((!(doc_matters.conf_make_meta.make.breaks.empty) + && (matchFirst(doc_matters.conf_make_meta.make.breaks, test_for_break_level))) + ) { // manually override defaults + if ((matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakpage)) + && (matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakcolumn)) + ) { + if (auto m = matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakpage)) { + if (matchFirst(m.captures["breakpage"], test_for_break_level)) { + _pg_break = "\\clearpage\n"; + } else if (auto n = matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakcolumn)) { + if (matchFirst(n.captures["breakcolumn"], test_for_break_level)) { + if ((paper_size_orientation == "a4.landscape") + || (paper_size_orientation == "b4.landscape") + || (paper_size_orientation == "a5.landscape") + || (paper_size_orientation == "letter.landscape") + || (paper_size_orientation == "legal.landscape") + ) { + _pg_break = "\\\\ \\columnbreak\n"; // "\\\\ \\newpage\n"; + } else { // portrait + _pg_break = "\\clearpage\n"; + } + } + } + } + } else if (auto m = matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakpage)) { + if (matchFirst(m.captures["breakpage"], test_for_break_level)) { + _pg_break = "\\clearpage\n"; + } + } else if (auto m = matchFirst(doc_matters.conf_make_meta.make.breaks, rgx.make_breakcolumn)) { + if (matchFirst(m.captures["breakcolumn"], test_for_break_level)) { + if ((paper_size_orientation == "a4.landscape") + || (paper_size_orientation == "b4.landscape") + || (paper_size_orientation == "a5.landscape") + || (paper_size_orientation == "letter.landscape") + || (paper_size_orientation == "legal.landscape") + ) { + _pg_break = "\\\\ \\columnbreak\n"; // "\\\\ \\newpage\n"; + } else { // portrait + _pg_break = "\\clearpage\n"; + } + } + } + } else if (!(doc_matters.conf_make_meta.make.breaks.empty)) { + _pg_break = ""; + } + return _pg_break; + } if (obj.metainfo.is_a == "heading") { string _tex_para; string _pg_break; @@ -530,7 +582,13 @@ template outputLaTeX() { case 4: // 1 == section _columns = (_part != "bookindex") ? "" : "\n\\br\n\\begin{multicols}{2}"; - _pg_break = "\\clearpage\n"; + if (doc_matters.conf_make_meta.make.doc_type == "article") { // defaults for article + _pg_break = ""; + } else if (doc_matters.conf_make_meta.make.doc_type == "book") { // defaults for book + _pg_break = "\\clearpage\n"; + } else { + _pg_break = "\\clearpage\n"; + } _sect = "section"; _post = ""; _title_add = format(q"┃ @@ -1281,7 +1339,7 @@ string table(O,M)( case "para": switch (obj.metainfo.is_a) { case "heading": - _txt = _txt.heading(obj, doc_matters); + _txt = _txt.heading(obj, doc_matters, paper_size_orientation); goto default; case "toc": break; @@ -1302,7 +1360,7 @@ string table(O,M)( case "para": switch (obj.metainfo.is_a) { case "heading": - _txt = _txt.heading(obj, doc_matters); + _txt = _txt.heading(obj, doc_matters, paper_size_orientation); goto default; case "para": _txt = _txt.para(obj) @@ -1366,7 +1424,7 @@ string table(O,M)( if (part == "bookindex") { _multicolumns = true; } - _txt = _txt.heading(obj, doc_matters, part); + _txt = _txt.heading(obj, doc_matters, paper_size_orientation, part); goto default; case "endnote": assert(part == "endnotes"); /* uncomment code to reinstate endnotes in endnote section */ diff --git a/src/doc_reform/io_out/rgx.d b/src/doc_reform/io_out/rgx.d index 3aaf420..37ad39c 100644 --- a/src/doc_reform/io_out/rgx.d +++ b/src/doc_reform/io_out/rgx.d @@ -54,6 +54,8 @@ module doc_reform.io_out.rgx; static template spineRgxOut() { static struct RgxO { + static make_breakpage = ctRegex!(`new=(?P.+?)(?:;|$)`); + static make_breakcolumn = ctRegex!(`break=(?P.+?)(?:;|$)`,); static newline = ctRegex!("\n", "mg"); static space = ctRegex!(`[ ]`, "mg"); static spaces_keep = ctRegex!(`(?P^[ ]+|[ ]{2,})`, "mg"); // code, verse, block diff --git a/src/doc_reform/meta/conf_make_meta_json.d b/src/doc_reform/meta/conf_make_meta_json.d index 076487d..af2cc3e 100644 --- a/src/doc_reform/meta/conf_make_meta_json.d +++ b/src/doc_reform/meta/conf_make_meta_json.d @@ -90,16 +90,21 @@ static template contentJSONtoSpineStruct() { confCompositeMakeBuild _mk; /+ make ------------------------------------------------------------------- +/ if ("make" in _json.object) { - if ("bold" in _json.object["make"] - && (_json.object["make"]["bold"].type().to!string == "string") + if ("doc_type" in _json.object["make"] + && (_json.object["make"]["doc_type"].type().to!string == "string") ) { - _struct_composite.make_str.bold = _json.object["make"]["bold"].str; + _struct_composite.make_str.doc_type = _json.object["make"]["doc_type"].str; } if ("breaks" in _json.object["make"] && (_json.object["make"]["breaks"].type().to!string == "string") ) { _struct_composite.make_str.breaks = _json.object["make"]["breaks"].str; } + if ("bold" in _json.object["make"] + && (_json.object["make"]["bold"].type().to!string == "string") + ) { + _struct_composite.make_str.bold = _json.object["make"]["bold"].str; + } if ("cover_image" in _json.object["make"] && (_json.object["make"]["cover_image"].type().to!string == "string") ) { diff --git a/src/doc_reform/meta/conf_make_meta_structs.d b/src/doc_reform/meta/conf_make_meta_structs.d index 664c1b1..966e8d0 100644 --- a/src/doc_reform/meta/conf_make_meta_structs.d +++ b/src/doc_reform/meta/conf_make_meta_structs.d @@ -89,8 +89,9 @@ static auto mkup = InlineMarkup(); return line_; } struct ConfCompositeMakeStr { - string bold; + string doc_type = "book"; // book, article string breaks; + string bold; string cover_image; string css; string emphasis; @@ -115,6 +116,9 @@ struct confCompositeMakeBuild { } return _out; } + string doc_type(string _mk) { + return _mk; + } string breaks(string _mk) { return _mk; } @@ -172,10 +176,11 @@ struct confCompositeMakeBuild { } } struct ConfCompositeMakeInit { - string[] bold; + string doc_type; string breaks; string cover_image; string css; + string[] bold; string[] emphasis; string[] footer; string[] headings; diff --git a/src/doc_reform/meta/conf_make_meta_yaml.d b/src/doc_reform/meta/conf_make_meta_yaml.d index 5af22ad..cb4a661 100644 --- a/src/doc_reform/meta/conf_make_meta_yaml.d +++ b/src/doc_reform/meta/conf_make_meta_yaml.d @@ -652,11 +652,11 @@ template contentYAMLtoSpineStruct() { if (_yaml["make"].type.mapping && _yaml["make"].tag.match(rgx.yaml_tag_is_map) ) { - if ("bold" in _yaml["make"] - && _yaml["make"]["bold"].type.string - && _yaml["make"]["bold"].tag.match(rgx.yaml_tag_is_str) + if ("doc_type" in _yaml["make"] + && _yaml["make"]["doc_type"].type.string + && _yaml["make"]["doc_type"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.make_str.bold = _yaml["make"]["bold"].get!string; + _struct_composite.make_str.doc_type = _yaml["make"]["doc_type"].get!string; } if ("breaks" in _yaml["make"] && _yaml["make"]["breaks"].type.string @@ -664,6 +664,12 @@ template contentYAMLtoSpineStruct() { ) { _struct_composite.make_str.breaks = _yaml["make"]["breaks"].get!string; } + if ("bold" in _yaml["make"] + && _yaml["make"]["bold"].type.string + && _yaml["make"]["bold"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.bold = _yaml["make"]["bold"].get!string; + } if ("cover_image" in _yaml["make"] && _yaml["make"]["cover_image"].type.string && _yaml["make"]["cover_image"].tag.match(rgx.yaml_tag_is_str) @@ -779,8 +785,9 @@ template contentYAMLtoSpineStruct() { _struct_composite.make_str.texpdf_font = _yaml["make"]["texpdf_font"].get!string; } } - _struct_composite.make.bold = _mk.bold(_struct_composite.make_str.bold); + _struct_composite.make.doc_type = _mk.doc_type(_struct_composite.make_str.doc_type); _struct_composite.make.breaks = _mk.breaks(_struct_composite.make_str.breaks); + _struct_composite.make.bold = _mk.bold(_struct_composite.make_str.bold); _struct_composite.make.cover_image = _mk.cover_image(_struct_composite.make_str.cover_image); _struct_composite.make.css = _mk.css(_struct_composite.make_str.css); _struct_composite.make.emphasis = _mk.emphasis(_struct_composite.make_str.emphasis); -- cgit v1.2.3