aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/out_latex.org
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2020-02-06 08:55:48 -0500
committerRalph Amissah <ralph@amissah.com>2020-02-26 09:59:18 -0500
commitfc25d90c46f454448a41438c62fdd7dad5105946 (patch)
tree38e6bc56211a2392d8a87b81fd031441a79faa65 /org/out_latex.org
parentimports related, mostly cosmetic (diff)
latex outputs (various paper sizes & orientation)
- a4, a5, b4, letter, legal - portrait, landscape
Diffstat (limited to 'org/out_latex.org')
-rw-r--r--org/out_latex.org349
1 files changed, 211 insertions, 138 deletions
diff --git a/org/out_latex.org b/org/out_latex.org
index f679ecd..501fba7 100644
--- a/org/out_latex.org
+++ b/org/out_latex.org
@@ -32,7 +32,6 @@ template outputLaTeX() {
<<output_latex_shared>>
<<output_latex_shared_0>>
<<output_latex_head>>
- <<output_latex_head_1_format_string>>
<<output_latex_head_1_tex>>
<<output_latex_head_1_format_string_variables>>
<<output_latex_head_0_format_string>>
@@ -52,8 +51,9 @@ template outputLaTeX() {
#+NAME: output_latex
#+BEGIN_SRC d
void writeOutputLaTeX(T,M)(
- const T latex_content,
- M doc_matters,
+ const T latex_content,
+ M doc_matters,
+ string paper_size_orientation,
) {
auto pth_latex = spinePathsLaTeX(doc_matters);
try {
@@ -69,9 +69,9 @@ void writeOutputLaTeX(T,M)(
(pth_latex.latex_path_stuff).mkdirRecurse;
}
if (!(doc_matters.opt.action.quiet)) {
- writeln(" ", pth_latex.latex_file_with_path);
+ writeln(" ", pth_latex.latex_file_with_path(paper_size_orientation));
}
- auto f = File(pth_latex.latex_file_with_path, "w");
+ auto f = File(pth_latex.latex_file_with_path(paper_size_orientation), "w");
f.writeln(latex_content.head);
f.writeln(latex_content.content);
f.writeln(latex_content.tail);
@@ -102,10 +102,23 @@ void outputLaTeX(D,M)(
string tail;
}
auto latex = LaTeX();
- latex.head = latex_head(doc_matters);
- latex.content = latex_body(doc_abstraction, doc_matters);
- latex.tail = latex_tail(doc_matters);
- latex.writeOutputLaTeX(doc_matters);
+ foreach (paper_size_orientation; [
+ "a4.portrait",
+ "a4.landscape",
+ "letter.portrait",
+ "letter.landscape",
+ "a5.portrait",
+ "a5.landscape",
+ "b4.portrait",
+ "b4.landscape",
+ // "legal.portrait",
+ // "legal.landscape",
+ ]) {
+ latex.head = latex_head(doc_matters, paper_size_orientation);
+ latex.content = latex_body(doc_abstraction, doc_matters, paper_size_orientation);
+ latex.tail = latex_tail(doc_matters, paper_size_orientation);
+ latex.writeOutputLaTeX(doc_matters, paper_size_orientation);
+ }
}
#+END_SRC
@@ -134,17 +147,27 @@ import doc_reform.io_out;
struct A4 {
auto portrait() {
struct V {
- uint w = 160;
- uint h = 228;
- uint img_px = 450;
+ const uint w = 160;
+ const uint h = 228;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "12pt";
+ string name = "a4paper";
+ uint img_px = 450;
+ bool is_portrait = true;
}
return V();
}
auto landscape() {
struct H {
- uint w = 238;
- uint h = 160;
- uint img_px = 300;
+ const uint w = 238;
+ const uint h = 160;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "11pt";
+ string name = "a4paper";
+ uint img_px = 300;
+ bool is_portrait = false;
}
return H();
}
@@ -155,17 +178,27 @@ import doc_reform.io_out;
struct A5 {
auto portrait() {
struct V {
- uint w = 112;
- uint h = 162;
- uint img_px = 280;
+ const uint w = 112;
+ const uint h = 162;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "0pt";
+ string name = "a5paper";
+ uint img_px = 280;
+ bool is_portrait = true;
}
return V();
}
auto landscape() {
struct H {
- uint w = 152;
- uint h = 100;
- uint img_px = 190;
+ const uint w = 152;
+ const uint h = 100;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "0pt";
+ string name = "a5paper";
+ uint img_px = 190;
+ bool is_portrait = false;
}
return H();
}
@@ -176,17 +209,27 @@ import doc_reform.io_out;
struct B4 {
auto portrait() {
struct V {
- uint w = 140;
- uint h = 204;
- uint img_px = 356;
+ const uint w = 140;
+ const uint h = 204;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "0pt";
+ string name = "b4paper";
+ uint img_px = 356;
+ bool is_portrait = true;
}
return V();
}
auto landscape() {
struct H {
- uint w = 200;
- uint h = 130;
- uint img_px = 260;
+ const uint w = 200;
+ const uint h = 130;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "0pt";
+ string name = "b4paper";
+ uint img_px = 260;
+ bool is_portrait = false;
}
return H();
}
@@ -197,17 +240,27 @@ import doc_reform.io_out;
struct Letter {
auto portrait() {
struct V {
- uint w = 166;
- uint h = 212;
- uint img_px = 468;
+ const uint w = 166;
+ const uint h = 212;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "0pt";
+ string name = "letterpaper";
+ uint img_px = 468;
+ bool is_portrait = true;
}
return V();
}
auto landscape() {
struct H {
- uint w = 226;
- uint h = 166;
- uint img_px = 290;
+ const uint w = 226;
+ const uint h = 166;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "0pt";
+ string name = "letterpaper";
+ uint img_px = 290;
+ bool is_portrait = false;
}
return H();
}
@@ -218,17 +271,27 @@ import doc_reform.io_out;
struct Legal {
auto portrait() {
struct V {
- uint w = 168;
- uint h = 286;
- uint img_px = 474;
+ const uint w = 168;
+ const uint h = 286;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "0pt";
+ string name = "legalpaper";
+ uint img_px = 474;
+ bool is_portrait = true;
}
return V();
}
auto landscape() {
struct H {
- uint w = 296;
- uint h = 166;
- uint img_px = 420;
+ const uint w = 296;
+ const uint h = 166;
+ string width = format(q"┃%dmm┃", w);
+ string height = format(q"┃%dmm┃", h);
+ string font_size = "0pt";
+ string name = "legalpaper";
+ uint img_px = 420;
+ bool is_portrait = false;
}
return H();
}
@@ -897,20 +960,25 @@ string table(O,M)(
string _txt,
O obj,
M doc_matters,
+ string paper_size_orientation,
) {
if (obj.metainfo.is_a == "table") {
auto _t = _txt.tablarize(obj);
string _table = _t[0];
string _t_n = _t[1];
- string papertype = "a4";
uint pw = 0;
- switch (papertype) {
- case "a4": pw = (paper.a4.portrait.w - 20); break;
- case "a5": pw = (paper.a5.portrait.w - 20); break;
- case "b4": pw = (paper.b4.portrait.w - 20); break;
- case "letter": pw = (paper.letter.portrait.w - 20); break;
- case "legal": pw = (paper.legal.portrait.w - 20); break;
- default: pw = 0; break;
+ switch (paper_size_orientation) {
+ case "a4.portrait": pw = (paper.a4.portrait.w - 20); break;
+ case "a4.landscape": pw = (paper.a4.landscape.w - 20); break;
+ case "a5.portrait": pw = (paper.a5.portrait.w - 20); break;
+ case "a5.landscape": pw = (paper.a5.landscape.w - 20); break;
+ case "b4.portrait": pw = (paper.b4.portrait.w - 20); break;
+ case "b4.landscape": pw = (paper.b4.landscape.w - 20); break;
+ case "letter.portrait": pw = (paper.letter.portrait.w - 20); break;
+ case "letter.landscape": pw = (paper.letter.landscape.w - 20); break;
+ case "legal.portrait": pw = (paper.legal.portrait.w - 20); break;
+ case "legal.landscape": pw = (paper.legal.landscape.w - 20); break;
+ default: pw = 0; break;
}
// auto textwidth = (pw - 24);
string _colw = "";
@@ -949,7 +1017,8 @@ string table(O,M)(
#+NAME: output_latex_head
#+BEGIN_SRC d
string latex_head(M)(
- M doc_matters,
+ M doc_matters,
+ string paper_size_orientation,
) {
#+END_SRC
@@ -959,13 +1028,19 @@ string latex_head(M)(
#+NAME: output_latex_head
#+BEGIN_SRC d
- struct paperType {
+ struct paperTypeLatex {
string a4_portrait;
string a4_landscape;
+ string a5_portrait;
+ string a5_landscape;
+ string b4_portrait;
+ string b4_landscape;
string us_letter_portrait;
string us_letter_landscape;
+ string us_legal_portrait;
+ string us_legal_landscape;
}
- auto paper = paperType();
+ auto paper_type_latex = paperTypeLatex();
#+END_SRC
****** footer
@@ -1002,82 +1077,6 @@ string latex_head(M)(
}
#+END_SRC
-****** a4, portrait
-
-#+NAME: output_latex_head_1_format_string
-#+BEGIN_SRC d
- paper.a4_portrait = format(q"┃
-#+END_SRC
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC latex
-\documentclass[12pt,a4paper,titlepage]{scrartcl}
-\setlength{\textheight}{228mm} \setlength{\textwidth}{160mm}
-#+END_SRC
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC d
-┃",
- );
-#+END_SRC
-
-****** a4, landscape
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC d
- paper.a4_landscape = format(q"┃
-#+END_SRC
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC latex
-\documentclass[11pt,a4paper,landscape,titlepage,twocolumn]{scrartcl}
-\setlength{\textheight}{160mm} \setlength{\textwidth}{238mm}
-#+END_SRC
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC d
-┃",
- );
-#+END_SRC
-
-****** us letter, portrait
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC d
- paper.us_letter_portrait = format(q"┃
-#+END_SRC
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC latex
-\documentclass[12pt,letterpaper,titlepage]{scrartcl}
-\setlength{\textheight}{212mm} \setlength{\textwidth}{166mm}
-#+END_SRC
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC d
-┃",
- );
-#+END_SRC
-
-****** us letter, landscape
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC d
- paper.us_letter_landscape = format(q"┃
-#+END_SRC
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC latex
-\documentclass[11pt,letterpaper,landscape,titlepage,twocolumn]{scrartcl}
-\setlength{\textheight}{166mm} \setlength{\textwidth}{226mm}
-#+END_SRC
-
-#+NAME: output_latex_head_1_tex
-#+BEGIN_SRC d
-┃",
- );
-#+END_SRC
-
***** paper margins
****** struct
@@ -1224,6 +1223,77 @@ string latex_head(M)(
#+END_SRC
**** latex head starts
+***** dimensions & orientation
+****** set
+
+#+NAME: output_latex_head_0_format_string
+#+BEGIN_SRC d
+ string set_paper(P)(P paper_set,) {
+ string paper_type_description;
+ if (paper_set.is_portrait) {
+ paper_type_description = format(q"┃
+\documentclass[%s,%s,titlepage]{scrartcl}
+\setlength{\textheight}{%s} \setlength{\textwidth}{%s}
+┃",
+ paper_set.font_size,
+ paper_set.name,
+ paper_set.height,
+ paper_set.width,
+ );
+ } else {
+ paper_type_description = format(q"┃
+\documentclass[%s,%s,landscape,titlepage,twocolumn]{scrartcl}
+\setlength{\textheight}{%s} \setlength{\textwidth}{%s}
+┃",
+ paper_set.font_size,
+ paper_set.name,
+ paper_set.height,
+ paper_set.width,
+ );
+ }
+ return paper_type_description;
+ }
+#+END_SRC
+
+***** (a4, a5, b4, letter, legal) * (portrait & landscape)
+
+#+NAME: output_latex_head_0_format_string
+#+BEGIN_SRC d
+ string paper_size_orientation_latex;
+ switch (paper_size_orientation) {
+ case "a4.portrait": paper_size_orientation_latex = set_paper(paper.a4.portrait); break;
+ case "a4.landscape": paper_size_orientation_latex = set_paper(paper.a4.landscape); break;
+ case "a5.portrait": paper_size_orientation_latex = set_paper(paper.a5.portrait); break;
+ case "a5.landscape": paper_size_orientation_latex = set_paper(paper.a5.landscape); break;
+ case "b4.portrait": paper_size_orientation_latex = set_paper(paper.b4.portrait); break;
+ case "b4.landscape": paper_size_orientation_latex = set_paper(paper.b4.landscape); break;
+ case "letter.portrait": paper_size_orientation_latex = set_paper(paper.letter.portrait); break;
+ case "letter.landscape": paper_size_orientation_latex = set_paper(paper.letter.landscape); break;
+ case "legal.portrait": paper_size_orientation_latex = set_paper(paper.legal.portrait); break;
+ case "legal.landscape": paper_size_orientation_latex = set_paper(paper.legal.landscape); break;
+ default: paper_size_orientation_latex = paper_type_latex.a4_portrait;
+ }
+#+END_SRC
+
+***** set color links
+
+#+NAME: output_latex_head_0_format_string
+#+BEGIN_SRC d
+ string links_mono_or_color_set = links.mono.strip;
+ if (
+ (doc_matters.opt.action.latex_color_links)
+ || (paper_size_orientation ==
+ "a4.landscape" ||
+ "a5.landscape" ||
+ "b4.landscape" ||
+ "letter.landscape" ||
+ "legal.landscape")
+ ){
+ links_mono_or_color_set = links.color.strip;
+ }
+#+END_SRC
+
+***** format latex head, open
#+NAME: output_latex_head_0_format_string
#+BEGIN_SRC d
@@ -1239,14 +1309,15 @@ string latex_head(M)(
%%%% LaTeX output last Generated on: %s
%%%% %s %s
+\usepackage{geometry}
#+END_SRC
***** paper type (a4, letter, ...; ( portrait | landscape ))
-- paper.a4_portrait
-- paper.a4_landscape
-- paper.us_letter_portrait
-- paper.us_letter_landscape
+- paper_type_latex.a4_portrait
+- paper_type_latex.a4_landscape
+- paper_type_latex.us_letter_portrait
+- paper_type_latex.us_letter_landscape
#+NAME: output_latex_head_0_tex
#+BEGIN_SRC latex
@@ -1534,12 +1605,12 @@ string latex_head(M)(
doc_matters.opt.action.debug_do ? "" : doc_matters.generator_program.stime.strip,
doc_matters.generator_program.project_name.strip,
doc_matters.generator_program.url_home.strip,
- paper.a4_portrait.strip,
+ paper_size_orientation_latex.strip,
margins.portrait.strip,
multicol.portrait.strip,
lang.codes[doc_matters.src.language]["xlp"],
"english",
- links.mono.strip, // links.color.strip,
+ links_mono_or_color_set,
doc_matters.conf_make_meta.meta.title_full.strip,
doc_matters.conf_make_meta.meta.creator_author.strip,
doc_matters.conf_make_meta.meta.classify_subject.strip,
@@ -1562,8 +1633,9 @@ string latex_head(M)(
#+NAME: output_latex_body
#+BEGIN_SRC d
string latex_body(D,M)(
- const D doc_abstraction,
- M doc_matters,
+ const D doc_abstraction,
+ M doc_matters,
+ string paper_size_orientation,
) {
string _latex_body = "";
bool _multicolumns = false;
@@ -1656,7 +1728,7 @@ string latex_body(D,M)(
_txt = _txt.codeblock(obj, doc_matters);
goto default;
case "table":
- _txt = _txt.table(obj, doc_matters);
+ _txt = _txt.table(obj, doc_matters, paper_size_orientation);
goto default; // TODO
default:
_latex_body ~= _txt ~ "\n\n";
@@ -1768,7 +1840,8 @@ string latex_body(D,M)(
#+NAME: output_latex_tail
#+BEGIN_SRC d
string latex_tail(M)(
- M doc_matters,
+ M doc_matters,
+ string paper_size_orientation,
) {
#+END_SRC
@@ -1828,7 +1901,7 @@ if flags.length==0 \
#{cmd} --paper-size=a5 --out=~/test
WOK
end
-paper_size = (flags.inspect.match(/"--paper-size=(a4|a5|b5|letter|legal)"/)) ? $1 : "a4"
+// paper_size_orientation = (flags.inspect.match(/"--paper-size=(a4|a5|b5|letter|legal)"/)) ? $1 : "a4"
out_path = Dir.pwd
if (flags.inspect.match(/"--out=\S+"/))
out_path = flags.inspect.match(/"--out=(\S+)"/)[1]
@@ -1862,7 +1935,7 @@ if texfiles_with_path.length > 0
FileUtils::mkdir_p(_out_path)
end
end
- texpdf_cmd = %{xetex -interaction=batchmode -fmt=xelatex -papersize=#{paper_size} #{texfile_with_path}\n}
+ texpdf_cmd = %{xetex -interaction=batchmode -fmt=xelatex #{texfile_with_path}\n}
puts texpdf_cmd
2.times { |i| system(texpdf_cmd) }
if (FileTest.file?(%{#{pwd}/#{file_basename}.pdf})) && (FileTest.directory?(_out_path))